The Analyser is found in the race_stack/system_identification/id_analyser
folder.
For the analyser you need bagpy, as bagpy only works in python 3, but you might be running python2, create a virtual environment following this guide:
https://code.visualstudio.com/docs/python/environments
which boils down to doing the following in the id_analyser folder:
sudo apt-get install python3-venv
# move to the current folder
cd /home/icra_crew/catkin_ws/src/race_stack/system_identification/id_analyser/
# create a new virtual environment
python3 -m venv .venv
Then install the python extension for vscode and open the command palete using Ctrl+Shift+P
and search for
"Python: Select Interpreter". If the interpreter does not show up, just manually select it (.venv/bin/python)
Then install bagpy and anything else that might be required.
source /home/icra_crew/catkin_ws/src/race_stack/system_identification/id_analyser/.venv/bin/activate
pip install wheel importlib-resources tk bagpy
Parameters that need to be identified physically are:
- I_z: Moment of Inertia around yaw axis - Bifilar Pendulum experiment
- h_cg: Height of the center of gravity over the wheel axes
- l_f: distance of front axis from center of mass
- l_r: distance of rear axis from center of mass
- l_wb: wheelbase, should be l_r + l_f
- m: mass of the model
Typically these don't change significantly and need to be identified only once. If a new model is added, generate a model file using the script in the id_analyser add_model.
The parameters that are affected by this are found in
f1tenth_system/racecar/racecar/config/<NUCX>/vesc.yaml
. We need to set
steering_angle_to_servo_gain: # e.g. -0.8390
steering_angle_to_servo_offset: # e.g. 0.405
This mapping should already be identified correctly. This can be checked by doing the following:
-
Launch the base system with the correct racecar version
roslaunch racecar pbl_teleop.launch racecar_version:=NUC2
-
Drive straight 2.1 If the car drives to the right: decrease
steering_angle_to_servo_offset
2.2 If the car drive to the left: increasesteering_angle_to_servo_offset
2.3 There is always some small error due to servo deadzones. 2.4 This can also be done by tightening os loosening the steering links on the car -
Repeat Step 2 until satisfied
After finding the correct offset, and setting it in the vesc.yaml
file, navigate to the system_identification/id_analyser/models/<NUCX>
folder. In the two model files you find in there, set C_0d
to the steering_angle_to_servo_offset
you just identified.
In the system_identification/id_analyser/models/<NUCX>/<NUCX>_linear.txt
file you will find a parameter called l_wb
, this is the wheelbase of the car. Assuming ackermann steering, we can estimate how large a driven circle should be given a certain steering angle. The formula is:
Circle_Radius = Wheelbase / tan(Steering_Angle)
You can command a constant steering angle using the id controller
. Navigate to system_identification/ic_controller/parameters
and open experiments.yaml
. We will only use experiment number 5
, in which the car drives with a constant speed defined by the const_speed
parameter and changes the steering angle from start_angle
to end_angle
over the time angle_time
. From previous tests we know that the maximum steering angle is around +-0.4.
By setting the start and end angles to the same value the car will drive with a constant steering angle and speed for angle_time duration.
To test if the steering to servo position gain is correct do the following:
-
Set the const_speed to 1.5, set the start and end angles to 0.1 -> Car will drive a left hand circle
-
Calculate the circle radius the car should drive at with a steering angle of 0.1.
-
Measure out a circle with with radius and mark the start position of the car and where it should drive through
-
Start the base system like above
roslaunch racecar pbl_teleop.launch racecar_version:=NUC2
-
Start the id_controller with
roslaunch id_controller id_controller.launch experiment:=5
-
Hold the top right button on the remote to make the car follow the commands from the id controller.
-
Check if the radius of the driven circle matches the marked positions: 7.1 If the Radius was too big, increase the
steering_angle_to_servo_gain
(more negative, e.g. -0.8 -> -0.85) 7.2 If the Radius was too small, decrease thesteering_angle_to_servo_gain
(less negative, e.g. -0.8 -> -0.75) -
Repeat above steps until it drives the circle like you would want it to. Also try out with a negative steering angle: -0.1 -> Car will drive a righthand circle
-
If, after this procedure, you changed the parameters in the
vesc.yaml
file, change them in the corresponding models of the car. You will find the two files in the following position:
race_stack/system_identification/id_analyser/models/<NUCX>/<NUCX>_linear.txt
race_stack/system_identification/id_analyser/models/<NUCX>/<NUCX>_pacejka.txt
steering_angle_to_servo_gain
corresponds toC_d
andsteering_angle_to_servo_offset
corresponds toC_0d
.
To do this, we need to generate data first. For this:
- In a terminal navigate to
~/catkin-ws/src/race_stack/system_identification/id_anaylser
and if it doesn't exist yet, make the foldersdata/<NUCX>/steering_angle
. - Go into the
steering_angle
folder you just created and prepare the command to record a rosbag:rosbag record -a -x "scan"
- In another terminal, start the base system:
roslaunch racecar pbl_teleop.launch racecar_version:=<NUCX> se_version:=new
- Manually drive a circle driving at a constant speed and steering angle, record rosbag as soon as you reach a steady state and stop rosbag before you stop driving / change steering angle.
- Repeat step 4. a few times, driving circles with different radii, recording a new rosbag each time.
To analye the data, navigate to the ~/catkin_ws/src/race_stack/system_identification/id_analyser
folder and open analyse_steering.py
. Set model_name_
to the model that you want to edit. The models are located in the models
subdirectory.
Open a terminal in vscode and select the virtual environment set up above as python interpreter. Then run the following command to analyse the data:
python3 analyse_steering.py
The script will print the parameters that it estimated and will also update them in the model .txt
. All that is left to do it to copy the identified C_0d
to steering_angle_to_servo_offset
and C_d
to steering_angle_to_servo_gain
in the vesc.yaml
for the car.
This should be done for new floors or Tires!! Make sure that the steering angle to servo mapping is identified before.
To find the tire parameters, we need to make the car drive at different slip angles. To do this, use the id_controller to make the car drive at a constant speed and slowly ramp up the steering angle.
- Make a new folder
~/catkin_ws/src/race_stack/system_identification/id_analyser/data/<NUCX>/tire_dynamics
, record subsequent bags in that folder - Start the Base system:
roslaunch racecar pbl_teleop.launch racecar_version:=<NUCX> se_version:=new
- Set the experiment parameters in
~/catkin_ws/src/race_stack/system_identification/id_controller/parameters/experiments.yaml
:- angle_time: 20, const_speed: 3, start_angle: 0.1, end_angle: 0.4 <-- left hand turn, car will drive circle with 12m diameter and converge to the left of start position
- angle_time: 20, const_speed: 4, start_angle: 0.1, end_angle: 0.4
- angle_time: 10, const_speed: 5, start_angle: 0.1, end_angle: 0.4
- angle_time: 10, const_speed: 5, start_angle: -0.1, end_angle: -0.4 <-- right hand turn, car will drive circle with 12m diameter and converge to the right of start position
- angle_time: 20, const_speed: 4, start_angle: -0.1, end_angle: -0.4
- angle_time: 20, const_speed: 3, start_angle: -0.1, end_angle: -0.4
- Start the experiment with
roslaunch id_controller id_controller.launch experiment:=5
- Hold the button on the remote to make the car drive
- In another terminal open the data folder you just made and start recording a rosbag as soon as the car has reached a steady state:
rosbag record -a -x "scan"
- The terminal with the experiment will notice you when the experiment is about to be over: "Ending soon, stop the bag" <-- Do so
- Repeat 2 - 5 with all different settings in step 2.
- Open
~/catkin_ws/src/race_stack/system_identification/id_analyser/analyse_tires.py
and change the model name to the one that you are working on (e.g. NUC2_pacejka) - Run the script:
source .venv/bin/activate
python3 analyse_tires.py
- Change the name to the linear version of the model, to also save and fit the linear tire parameters
After identifying the parameters, the lookup table for the model can be generated automatically. For this open ~/catkin_ws/src/race_stack/system_identification/id_analyser/generate_lookup_table.py
and change the model name to the model that you would like to generate the lookup table for. Then run the script:
source .venv/bin/activate
python3 generate_lookup_table.py
The lookup table will be generated and saved as CSV in the id_analyser/models/<NUCX>
folder. From there you can copy it over to system_identification/steering_lookup/cfg
and name it according to your setting. It can then be used for the MAP controller.
Drive on the track and compare to other Lookup Tables
To roughly check the quality of the obtained measurement, you can test driving around an ellipse and see if the error is low enough.
- position the car in a place with at least 1m space to the right, 5m to the left, 5m in front and 5m to the back. There is a picture for reference, with car as the blue arrow.
- launch the SysId verificator:
roslaunch stack_master sysid_verify.launch mode:=safe LU_table:=<INSERT CORRECT LUT NAME>
- Drive around for a couple of laps
- check in the terminal used for running the test what is the average lap time and what is the average error. In the hangar, yields ca. 5.95 s for laptime and 0.135 for lateral error.
In ~/catkin_ws/src/race_stack/system_identification/id_analyser/model/NUCX/NUCX_pacejka/linear
, change the mu value to represent how much more slippery or grippy the tires are compared to the measured ones. To do this, measure the lateral friction of the car with the Newtonmeter and compare it to the premeasured values in this table
Then continue with generating the Lookup Table.
The parameters that are affected by this are found in
race_stack/base_system/f1tenth_system/racecar/racecar/config/<NUCX>/vesc.yaml
. We need to set
speed_to_erpm_gain: # e.g. 4316
speed_to_erpm_offset: #e.g. -5.0
This mapping should already be identified correctly. this can be checked by plotting commanded vs measured speed (by slam) in rqt.
We are actually going to fix the offset to -5.0, so in fact we only need to identify the speed_to_erpm_gain
.
To do this, we need to generate data first. For this:
- In a terminal navigate to
~/catkin-ws/src/race_stack/system_identification/id_anaylser
and if it doesn't exist yet, make the foldersdata/<NUCX>/motor
. - Go into the motor folder you just created and prepare the command to record a rosbag:
rosbag record -a -x "scan"
- In another terminal, start the base system:
roslaunch racecar pbl_teleop.launch racecar_version:=<NUCX> se_version:=new
- Drive straight at a constant velocity, after the car has accelerated to a constant velocity start recording the bag, stop the bag before you stop driving.
- Repeat step 4. a few times, driving at different speeds, recording a new rosbag each time.
To analye the data, navigate to the ~/catkin-ws/src/race_stack/system_identification/id_anaylser
folder and open analyse_motor_rpm.py
. Set model_name_
to the model that you want to edit. The models are located in the models
subdirectory.
Open a terminal in vscode and select the virtual environment set up above as python interpreter. Then run the following command to analyse the data:
python3 analyse_motor_rpm.py
The script will print the parameters that it estimated and will also update them in the model .txt
. All that is left to do it to copy the identified C_v
to speed_to_erpm_gain
in the vesc.yaml
for the car.
The parameters that are affected by this are found in
f1tenth_system/racecar/racecar/config/<NUCX>/vesc.yaml
. We need to set
steering_angle_to_servo_gain: # e.g. -0.8390
steering_angle_to_servo_offset: # e.g. 0.405
This mapping should already be identified correctly. This can be checked by doing the following:
-
Launch the base system with the correct racecar version
roslaunch racecar pbl_teleop.launch racecar_version:=NUC4
-
Drive straight 2.1 If the car drives to the right: decrease
steering_angle_to_servo_offset
2.2 If the car drive to the left: increasesteering_angle_to_servo_offset
2.3 There is always some small error due to servo deadzones. 2.4 This can also be done by tightening os loosening the steering links on the car -
Repeat Step 2 until satisfied
After finding the correct offset, and setting it in the vesc.yaml
file, navigate to the system_identification/id_analyser/models/<NUCX>
folder. In the two model files you find in there, set C_0d
to the steering_angle_to_servo_offset
you just identified.
In the system_identification/id_analyser/models/<NUCX>/<NUCX>_linear.txt
file you will find a parameter called l_wb
, this is the wheelbase of the car. Assuming ackermann steering, we can estimate how large a driven circle should be given a certain steering angle. The formula is:
Circle_Radius = Wheelbase / tan(Steering_Angle)
You can command a constant steering angle using the id controller
. Navigate to system_identification/ic_controller/parameters
and open experiments.yaml
. We will only use experiment number 5
, in which the car drives with a constant speed defined by the const_speed
parameter and changes the steering angle from start_angle
to end_angle
over the time angle_time
. From previous tests we know that the maximum steering angle is around +-0.4.
By setting the start and end angles to the same value the car will drive with a constant steering angle and speed for angle_time duration.
To test if the steering to servo position gain is correct do the following:
-
Set the const_speed to 1.5, set the start and end angles to 0.1 -> Car will drive a left hand circle
-
Calculate the circle radius the car should drive at with a steering angle of 0.1.
-
Measure out a circle with with radius and mark the start position of the car and where it should drive through
-
Start the base system like above
roslaunch racecar pbl_teleop.launch racecar_version:=NUC2
-
Start the id_controller with
roslaunch id_controller id_controller.launch experiment:=5
-
Hold the top right button on the remote to make the car follow the commands from the id controller.
-
Check if the radius of the driven circle matches the marked positions: 7.1 If the Radius was too big, increase the
steering_angle_to_servo_gain
(more negative, e.g. -0.8 -> -0.85) 7.2 If the Radius was too small, decrease thesteering_angle_to_servo_gain
(less negative, e.g. -0.8 -> -0.75) -
Repeat above steps until it drives the circle like you would want it to. Also try out with a negative steering angle: -0.1 -> Car will drive a righthand circle
-
If, after this procedure, you changed the parameters in the
vesc.yaml
file, change them in the corresponding models of the car. You will find the two files in the following position:
race_stack/system_identification/id_analyser/models/<NUCX>/<NUCX>_linear.txt
race_stack/system_identification/id_analyser/models/<NUCX>/<NUCX>_pacejka.txt
steering_angle_to_servo_gain
corresponds toC_d
andsteering_angle_to_servo_offset
corresponds toC_0d
.
To do this, we need to generate data first. For this:
- In a terminal navigate to
~/catkin-ws/src/race_stack/system_identification/id_anaylser
and if it doesn't exist yet, make the foldersdata/<NUCX>/steering_angle
. - Go into the
steering_angle
folder you just created and prepare the command to record a rosbag:rosbag record -a -x "scan"
- In another terminal, start the base system:
roslaunch racecar pbl_teleop.launch racecar_version:=<NUCX> se_version:=new
- Manually drive a circle driving at a constant speed and steering angle, record rosbag as soon as you reach a steady state and stop rosbag before you stop driving / change steering angle.
- Repeat step 4. a few times, driving circles with different radii, recording a new rosbag each time.
To analye the data, navigate to the ~/catkin_ws/src/race_stack/system_identification/id_analyser
folder and open analyse_steering.py
. Set model_name_
to the model that you want to edit. The models are located in the models
subdirectory.
Open a terminal in vscode and select the virtual environment set up above as python interpreter. Then run the following command to analyse the data:
python3 analyse_steering.py
The script will print the parameters that it estimated and will also update them in the model .txt
. All that is left to do it to copy the identified C_0d
to steering_angle_to_servo_offset
and C_d
to steering_angle_to_servo_gain
in the vesc.yaml
for the car.
This is only needed when controlling the cars acceleration directly and not through the VESC
- Make a new folder
~/catkin_ws/src/race_stack/system_identification/id_analyser/data/<NUCX>/accel
, record subsequent bags in that folder - Start the Base system:
roslaunch racecar pbl_teleop.launch racecar_version:=<NUCX> se_version:=new
and make sure that you have at least 20m of free space in front of the car. - Set the experiment parameters in
~/catkin_ws/src/race_stack/system_identification/id_controller/parameters/experiments.yaml
:- const_accel = 2, const_decel = 2
- const_accel = 4, const_decel = 4
- const_accel = 6, const_decel = 6
- In another terminal open the data folder you just made and prepare for recording a rosbag.
rosbag record -a -x "scan"
- Start the experiment with
roslaunch id_controller id_controller.launch experiment:=3
-
Immediately start the rosbag
-
Hold the button on the remote to make the car drive
-
The terminal with the experiment will notice you when the experiment is over: "Experiment over", so stop the rosbag
-
Repeat 2 - 7 with all different settings in step 2.
-
Open
~/catkin_ws/src/race_stack/system_identification/id_analyser/analyse_accel.py
and change the model name to the one that you are working on (e.g. NUC2_pacejka) -
Run the script:
source .venv/bin/activate
python3 analyse_tires.py
-
Do the same with
~/catkin_ws/src/race_stack/system_identification/id_analyser/analyse_decel.py
-
In
~/catkin_ws/src/race_stack/system_identification/id_analyser/models/NUCX/NUCX_pacejka.txt
look at the parameters C_acc, C_dec and C_R -
In
~/catkin_ws/src/race_stack/base_system/f1tenth_system/racecar/racecar/config/NUCX/vesc.yaml
, input the found parameters in the following way:acceleration_to_current_gain: C_acc
deceleration_to_current_gain: C_dec
velocity_to_current_gain: C_R
-
Verify the parameters by setting the parameters to
const_accel = 2, const_decel = 2
and launching roslaunch id_controller id_controller.launch experiment:=3
again. Measure out a 6m long straight and measure the time it takes to drive across from standing still. Calculate the acceleration by