[chrono] Variable SCM Soil Parameters with HMMWV vehicle

163 views
Skip to first unread message

Marco Visca

unread,
Feb 24, 2021, 10:58:16 AM2/24/21
to ProjectChrono
Hello everyone,
I am attempting to set up a simulation with:
- hmmwv vehicle
- terrain with variable height from .bmp file
- deformable terrain with SCM model

I am using PyChrono installed with Anaconda.

Following different demos I succeeded in setting up the simulator for a terrain with fixed soil properties. I would like to extend it to variable soil properties depending on the terrain coordinates.
I modified the code following demo_VEH_DeformableSoil, which sets up a callback function to define variable soil parameters. However, during simulation when the code gets to:

my_hmmwv.Advance(step_size)

I encounter the following error:

return _vehicle.HMMWV_Advance(self, step)

RuntimeError: SWIG director method error. Error detected when calling 'SoilParametersCallback.Set'


Any idea what may cause this and how to fix it?

I noticed demo_VEH_DeformableSoil uses a generic ChSystem, while I am specifically interested in using hmmwv, but I couldn't find any demo which uses it with variable soil properties.

Many thanks in advance,

Marco.

Marco Visca

unread,
Feb 24, 2021, 11:16:51 AM2/24/21
to ProjectChrono
A little note:
I tried in C++, and everything works fine without any error. I am specifically interested in using the Python version though.
Thanks.
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

SIMONE BENATTI

unread,
Feb 25, 2021, 5:27:57 AM2/25/21
to ProjectChrono
Hi Marco,
SCM demos (wheel only) and HMMWV demo work fine, could you please share your code?
Also, which version of pychrono are you running? The last main is quite old now, the new one is being deployed right now.
Alternatively, you could also install develop version (conda install -c projectchrono/label/develop pychrono)
Thanks,
Simone

Marco Visca

unread,
Feb 25, 2021, 9:28:44 AM2/25/21
to ProjectChrono
Hi Simone,
Many thanks for the prompt reply.

The version I installed is the 6.0.0 with build py37_5, which I installed few days ago with: conda install -c projectchrono/label/develop pychrono

I did some further tests and I did actually succeed to make it work if the simulation runs in a simple function, while it fails if I define the terrain object as attribute of a class.

The reason I want the simulation to be defined as a class is that I would like that the simulation could be run by other python files for a while, until some conditions are met. Then, I do other operations. And then I start the simulation again from when it was interrupted (i.e. by starting from same Chrono time and same terrain/vehicle conditions).

The  pseudocode would look like something like this:

class Simulator:
def __init__(self):
self.my_hmmwv = ...
self.terrain = ...
self.app = ...
self.driver = ...

def run(self):
while (condition):
.
.
.
self.driver.Synchronize()
self.terrain.Synchronize()
self.my_hmmwv.Synchronize()
self.app.Synchronoize()

self.driver.Advance(step_size)
self.terrain.Advance(step_size)
self.my_hmmwv.Advance(step_size)
self.app.Advance(step_size)


# In other file
sim = Simulator()
sim.run()
# other operations
sim.run()


Now, while this was actually working when the soil properties where fixed, if the terrain properties are defined with the SoilParameters callback the error linked above occurs.

Moreover, the error does not occur if I define terrain as a local variable in 'run' and I call 'run' only once.

Any idea why swig seems to have problem if terrain is defined as a class attribute? Do you think there is a workaround that which will allow me to keep it as such?

Many Thanks for you support,
Marco.



SIMONE BENATTI

unread,
Feb 25, 2021, 9:48:40 AM2/25/21
to ProjectChrono
Hi Marco,
the SCM Python demo works with variable SCM parameter (SoilParametersCallback), so the problem is not in the wrapper itself. I think there is some subtle scope/trash collector action, it would be helpful if you could share a minimal functioning code showing the error..
Thanks,
Simone

Marco Visca

unread,
Feb 25, 2021, 12:30:51 PM2/25/21
to ProjectChrono
Dear Simone,
I share at this link a minimal working code:

https://drive.google.com/file/d/1Ubpk4rfUWHVbDs0KgS7LRZdRgguKXnTJ/view?usp=sharing

The variable "terrain_type" can be set either to: "uniform" or "variable"

In the first case the terrain is set with uniform properties and the code runs without errors.
In the second case the terrain is set with the SoilParametersCallback, and the error occurs.

I hope this can be useful.

Many Thanks,
Marco.

SIMONE BENATTI

unread,
Feb 25, 2021, 1:09:33 PM2/25/21
to ProjectChrono
Hi Marco,
as I suspected, that was a subtle scope error.
When you define soil parameters @line 125 as soon as you exit from the function and looke the ownership the garbage collector deletes the parameters, and when the underlying C++ code looks for them they are nowhere to be found. If you define paremetets as class attribute the problem is solved.


Here the working version, you'll have to change back the paths to data and terrains. Enjoy!

Thanks,
Simone

Marco Visca

unread,
Feb 25, 2021, 1:32:00 PM2/25/21
to ProjectChrono
Thanks a lot Simone, that worked!
All the bests,
Marco

ttt feng

unread,
Nov 2, 2022, 10:40:55 PM11/2/22
to ProjectChrono
hello,Simone and Marco
I have the same problem when using pychrono. But the working version shared by Simone can't be opend, please help me solve this problem.

All the bests,
Lemon

Reply all
Reply to author
Forward
0 new messages