juanmanzanero / fastest-lap

Fastest-lap is a vehicle dynamics simulator. It can be used to understand vehicle dynamics, to learn about driving techniques, to design car prototypes, or just for fun!
MIT License
575 stars 43 forks source link

Can't loop simulations #20

Closed pierre-trott closed 2 years ago

pierre-trott commented 2 years ago

Hi,

I'm trying to run the simulation multiple times and changing the vehicle model parameters between each iteration.

The first iteration works but stops after with an generic Windows Error. Could it be that it doesn't like that I am loading a vehicle that is already loaded? Is there a way to unload_vehicle before load_vehicle again on the same xml? If not, do I have to rename the car model xml to something different every iteration.

Thanks

juanmanzanero commented 2 years ago

Hello Pierre,

This is correct. Once a variable (scalar, vector, car, circuit) has been loaded with a name, you cannot override it. New documentation is available. Two things are possibly happening:

The delete_vehicle function is there in the library, but I have forgot to put a python binding for it. I will deliver it in the next release. I give you three options.

First option, in the mean time you can add to fastest_lap.py

def delete_vehicle(vehicle_name):
        vehicle_name = c.c_char_p((vehicle_name).encode('utf-8'))
        c_lib.delete_vehicle(vehicle_name);
        return;

Second option, change the name of the car at every loop iteration (you will never run out of memory, I think...)

Third option, just create one car, and modify the parameters you are interested using

fastest_lap.set_scalar_parameter(vehicle_name,"vehicle/chassis/aerodynamics/cd", new_value)
pierre-trott commented 2 years ago

Perfect, thank you!