How to use
In the folder examples/, we provide the file use_emb_es.py, which opens a ZMQ Sender and Receiver to communicate with the energy strategy algorithm. In the following, we wish to explain the code fragments in its main.
Important: 1. Create Reference velocity profile must be executed prior to the race start. 2. Initialization of the energy strategy must be run to initialize the energy strategy. 3. Reoptimization of the energy strategy is running online to recalculate the strategy.
1. Create Reference velocity profile
Creation of the reference velocity profile v_ref is done by
vpl.trigger_recalc(phase='v',
track='mnt')
By this, the reference velocity profile is generated and saved as a .csv-file.
2. Initialization of the energy strategy
Initialization of the energy strategy is done by
# x0 = s [m], v[m/s], t[s], soc_batt [], temp_batt, temp_mach, temp_inv, temp_cool_mi, temp_cool_b [°C]
vpl.trigger_recalc(s_meas=0.0,
meas_diff=np.array(0),
phase='i',
track='mnt',
laps=12,
x0=np.array([1, 0, 0, 0.5, 35, 35, 35, 35, 35]))
Here, s_meas indicates the global s-coordinate where a powertrain measurement of SOC and temperatures was made (start: s_meas = 0.0m). The number of race laps must be set in the argument laps for a specific track. The initial state conditions (see code comment above) are provided in x0. Have a look in Tracks to find available race tracks and their respective IDs.
3. Reoptimization of the energy strategy
Re-optimization of the energy strategy is done by
s_meas_ = 500 # meters
# meas_diff = s [m], v[m/s], t[s], soc_batt [], temp_batt, temp_mach, temp_inv, temp_cool_mi, temp_cool_b [°C]
vpl.trigger_recalc(s_meas=s_meas_,
meas_diff=np.array([0, 0, 0, -0.02, 0, 3.0, 0, 0, 0]))
Here, s_meas describes the global s-coordinate where the measurement value was generated. The measurement differences compared to the planned values of the last energy strategy recalculation at this position need to be set in meas_diff.
Open loop simulation (internal)
The energy strategy can be run in an open loop mode. This example explains how to run
a trajectory planner,
an LQR vehicle dynamics controller,
a vehicle dynamics simulation,
the energy strategy.
To do this, a trajectory planner, which uses the velocity_optimization module must be started. It transfers local trajectories to the LQR controller, and the vehicle dynamics simulation. The trajectory planner itself calls the initialization 2. Initialization of the energy strategy and the reoptimization 3. Reoptimization of the energy strategy of the energy strategy module. Do the following steps to setup the open loop simulation:
Clone the repository mod_control and checkout branch old_rr_ltpl:
git clone https://gitlab.lrz.de/iac/mod_control git checkout old_rr_ltplDownload the latest controller and vehicle dynamics simulation from branch old_rr_ltpl and extract the files into /mod_control/misc/py_binds/dist/ and install via
pip install tum_motion_control-0.1.0-cp38-cp38-linux_x86_64Install rticonnextdds-connector in a virtual environment with Python 3.8 via
pip install rticonnextdds-connectorRun the main script of the controller simulation via
python3 raceline_driving.py --vehicle_interface sil --vehicle_params il --network_config loc --slow_factor 1.0 --verbose FalseGo ahead, start the energy strategy and the trajectory planner.