(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Running a simulation using the command line

Description: Shows how to setup and run a basic simulation with only the real_time_simulator package.

Tutorial Level: BEGINNER

This framework is developed with modularity as its core. This means every module should be able to run and be tested independently. Let's see how to start right away a basic simulation without any programming!

Launching your first simulation

A simple script is provided in /bash_scripts to launch a complete simulation. This serves as a good test to see if everything is correctly installed.

roscd real_time_simulator/
mkdir log
./bash_scripts/test_simu.sh

A graphical interface should appear:

simulator_GUI.png

Click on the Publish button at the bottom of the windows to start the simulation. If everything goes well, the rocket should be launched and reach an apogee of around 1100 meters after 15 seconds. You can stop the simulation whenever you want by hitting CTRL+C on the terminal that started the simulation.

Exploring the simulation script

Basic configuration

Let's see what is inside this script bash_scripts/test_simu.sh.

First the workspace is built and the terminal configured:

set -e
cd ~/catkin_ws
catkin_make
source ~/catkin_ws/devel/setup.sh

Then the rocket engine is commanded a thrust of 2000 N, aligned with the rocket body (both angles at 0 rad), and the simulator is started:

(sleep 5;rostopic pub /gimbal_command_0 rocket_utils/GimbalControl "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
outer_angle: 0.0
inner_angle: 0.0
thrust: 2000.0" -r 10)&
roslaunch real_time_simulator rocket_sim.launch
  • The first command is rostopic, a classic ROS command-line tool that can manipulate ros messages. Here we publish (pub) on the topic /gimbal_command_0 with a message of type rocket_utils/GimbalControl. The desired thrust and engine orientation is specified, and the -r 10 option specify to send this message at 10Hz.

  • The second command is roslaunch, another important ROS command-line tool that allow to configure ROS and launch multiple nodes.

Try changing the desired thrust and engine orientation to see how it affect the trajectory.

We can look inside the file rocket_sim.launch, which defines how the simulator should be configured.

First the launch trigger mode is set to Command, which means that the simulation will start as soon as we hit the Publish button.

<param name="launch_trigger_type" type="string" value="Command" />

The other available mode is Thrust which starts the simulation only when the thrust is higher than the weight of the rocket.

Then the different user parameters are loaded from their .yaml files and placed inside groups for convenience:

<group ns="rocket">
    <rosparam file="$(find real_time_simulator)/config/rocket_parameters.yaml" />
</group>

<group ns="actuator">
    <rosparam file="$(find real_time_simulator)/config/actuator_parameters.yaml" />
</group>

<group ns="environment">
    <rosparam file="$(find real_time_simulator)/config/environment_parameters.yaml" />
</group>

<group ns="perturbation">
    <rosparam file="$(find real_time_simulator)/config/perturbations_parameters.yaml" />
</group>

<group ns="visualization">
  <rosparam file="$(find real_time_simulator)/config/visualization_parameters.yaml" />
</group>

We will see later how to change these files to configure the simulation parameters.

Then the different nodes of the simulator are loaded. The nodes aerodynamic, disturbance, integrator and wind_generator are computing the physics of the simulation. The nodes GUI_interface and rqt_gui take care of the graphical interface, and rosbag logs all simulation data for following analysis.

<node name="aerodynamic" pkg="real_time_simulator" type="aerodynamic.py" cwd = "node" />
<node name="disturbance" pkg="real_time_simulator" type="disturbance.py" cwd = "node"/>

<node name="integrator" pkg="real_time_simulator" type="integrator" cwd = "node" output ="screen"/>
<node name="wind_generator" pkg="real_time_simulator" type="wind_generator" cwd = "node" output ="screen"/>
  
<node name="GUI_interface" pkg="real_time_simulator" type="GUI_interface" />
  
<node name="rqt_gui" pkg="rqt_gui" type="rqt_gui" args="--perspective-file $(find real_time_simulator)/GUI/rocket_GUI.perspective"/> 
<node pkg="rosbag" type="record" name="recorder" args="record -a -O $(find real_time_simulator)/log/log.bag"/>

Note: Please check this page for a complete guide on how to write a launch file

Custom configuration

You can change the settings of the simulations using the .yaml files in the /config folder. The most important parameters are found in environment_parameters.yaml and rocket_parameters.yaml.

To configure a simulation, simply change the parameters in a text editor, then start the simulation using the script test_simu.sh.

Environment parameters

Open the file environment_parameters.yaml with a text editor. Here you can find all the external parameters that affects the rocket's flight. These include initial position and final target of the rocket, atmospheric conditions such as air temperature and wind, and launch rail parameters.

Try playing the parameters wind_speed and wind_direction to see how they affect the stability of the rocket during its flight.

Rocket parameters

Open the file rocket_parameters.yaml. Here you can find internal parameters to the rocket, such as its dimensions, mass and rocket engine parameters.

Try playing the parameters dry_mass, propellant_mass and Isp to see how they affect the apogee of the flight.

Actuator parameters

In the file actuator_parameters.yaml, you can define a list of each type of actuator that will control the rocket. We currently support the classic rocket engine mounted on a gimbal, control moment gyroscope, and drone gimbal. You can have as many actuators as you want, with different position and parameters.

Perturbations parameters

In the file perturbations_parameters.yaml, you can modify the external forces and torques that are applied randomly to the rocket during its flight. The sensors imperfections are also configured here.

Visualization parameters

Here are placed some parameters that only affect the 3D view of the rocket. Changing them have no effects on the simulated flight.

Next Step

Now that you know how to tun a simulation manually, let's see in the next tutorial how to connect your GNC project to control the simulator !

Wiki: real_time_simulator/Tutorials/Using the command line (last edited 2022-08-09 15:52:43 by Albéric de Lajarte)