Skip to content

Standalone Sim

Image of the RViz multirotor sim
Image of the standalone simulator (using ROS2 RViz).

This guide contains detailed information on the "standalone simulator", which is simply the ROSflight sim that uses ROS2 RViz to visualize the vehicle.

Launch parameters

This document describes a lot of the launch-time arguments that can be passed to the launch files to configure the simulation. To see a complete and current list of the launch-time arguments, run a launch command with

ros2 launch <package_name> <launch_file_name> --show-args

Note

To simulate a fixed-wing mav, just change all instances of multirotor in the steps below to fixedwing.

Standalone sim architecture

Standalone sim software modules
Modules used by the standalone simulator and how they interact. See the simulator architecture page for more information.

The standalone simulator uses every module in the above figure and optionally uses the standalone_time_manager to manage the simulation time. See the simulator architecture page for more information on each module.

Installation

The standalone simulator depends on ROS2 RViz. RViz and its dependencies are installed when the ros-<ros-distro>-desktop version of ROS2 is installed. Set up ROSflight with the software installation for sim guide guide, making sure to install the -desktop package of ROS2, not the -ros-base.

Other than RViz, the standalone simulator only depends on the code in rosflight_ros_pkgs. Check the installation for sim guide for more information.

Launching instructions

  • The standalone sim for ROSflight SIL is usually launched using this launch file:

    ros2 launch rosflight_sim multirotor_standalone.launch.py
    

  • The standalone sim should now be running! RViz should open with the STL of the multirotor.

    Image of the RViz multirotor sim
    Image of RViz with the multirotor STL at the origin.

  • You should have the following rqt_graph.

    multirotor_launch_rqt_graph
    RQT graph of the nodes involved in the standalone simulator. Click on the figure to enlarge.

    Tip

    Run rqt_graph with rqt_graph in a new terminal, assuming the -desktop version of ROS2 was installed.

The launch file manages launching several nodes all at once, as shown in the rqt_graph image. This includes the ROSflight sim nodes

  • /rosflight_io: Handles the communication between the companion computer and the simulated flight controller
  • /standalone_sensors: Simulates sensor measurements given the true state of the robot
  • /rc: Simulates the RC safety pilot connection to the firmware
  • /sil_board: Instantiation of the firmware
  • /standalone_dynamics: Dynamics node for keeping track of the true robot state
  • /multirotor_forces_and_moments: Computes aerodynamic forces and moments based on motor commands
  • /standalone_time_manager: Only appears if use_sim_time launch argument is set true, and publishes to the /clock topic.

As well as some nodes specific to the standalone_sim:

  • /rviz: Instance of the ROS2 RViz visualizer
  • /standalone_viz_transcriber: Manages publishing rosflight_sim information to RViz
  • 3 transform listener nodes: Manage coordinate frame transformations to RViz

For more information on each of these nodes, see the simulator architecture page.

Running nodes individually

If you don't want to use the launch file, you can instead run all of the nodes individually in separate terminals with the appropriate parameters. For example, to run just the /multirotor_forces_and_moments node, you would run

ros2 run rosflight_sim multirotor_forces_and_moments --ros-args --params-file ~/rosflight_ws/src/rosflight_ros_pkgs/rosflight_sim/params/multirotor_dynamics.yaml
Check the launch files for more information on what parameters and param files get loaded by the launch file.

Also note that the multirotor_standalone.launch.py file actually calls 2 other launch files--one specific to the standalone sim (standalone_sim.launch.py) and one that launches the nodes shared by both the fixedwing and multirotor simulators (common_nodes_standalone.launch.py). You can also launch those files separately if you want--just make sure to also run the forces and moments node in addition to those two sub-launch files.

Warning

If you do run all nodes separately, make sure all the needed nodes are running. You can verify this by checking that the rqt_graph is the same as the above image.

This is important since the nodes are chained together to complete a simulation loop.

Configuring the standalone sim

The launch files for the standalone simulator include some arguments that you can set to configure the visualization environment. To see the options when launching the simulator, run

ros2 launch rosflight_sim multirotor_standalone.launch.py --show-args

Argument name Description
rviz2_config_file Configuration file loaded into RViz at launch. Helps automatically set up subscriptions, cameras, etc.
sim_aircraft_file Path to the mesh file that will be used to visualize the vehicle.
use_sim_time When set true, sets the same parameter to true on all launched nodes.

To change one of these arguments, specify the argument and its value with the <argument>:=<value> syntax. For example,

ros2 launch rosflight_sim multirotor_standalone.launch.py rviz2_config_file:=$(pwd)/my_config_file.rviz
would launch RViz with the my_config_file.rviz configuration file.

After launching

Remember that the SIL tries its best to replicate hardware. That means you have to calibrate and set parameters in the same way you do in hardware. If you need a reminder, please follow the configuration and manual flight tutorial.

See the Parameter Configuration pages in this documentation for instructions on how to perform all preflight configuration before the aircraft will arm.

You can also run

ros2 launch rosflight_sim multirotor_init_firmware.launch.py
to load all required parameters and perform initial calibrations for a quick simulation setup.

Warning

Remember to verify that all parameters are set to the value that you would expect. Otherwise, the vehicle will behave erratically.

After loading parameters, you can fly autonomously by launching your GNC stack. See the ROScopter or ROSplane tutorials for a reminder on how to run ROScopter or ROSplane.