Run simulation of SAFMC drone with ring of 8 ToF sensors using PX4 Software in the Loop (SITL)
- Pixi package manager
- Git
-
Clone the repository:
git clone --recursive https://github.com/nus-safmc/gazebo-slam-prototype.git cd gazebo-slam-prototypeMake sure to include the --recursive flag to clone all submodules
-
Install dependencies and build:
# This automatically sets up ROS 2 Jazzy and all dependencies pixi run -e jazzy build -
Activate the environment:
pixi shell -e jazzy # ROS 2 environment is ready with CycloneDDS configured automatically
Once in the pixi shell, you can:
Launch the PX4 SITL environment:
pixi run -e jazzy px4_sitlViewing ROS topics The list of ROS topics created by the SITL simulation can be viewed using
ros2 topic listData from individual ToF sensors are published to the /depth/tof_n topics. However, the launch file also automatically starts up the tof_to_scan.py node, which automatically processes the depth data and returns a LaserScan topic, /scan_merged that can be used by ROS SLAM toolbox.
Other data (e.g. odometry) from the PX4's Flight Management Unit (FMU) can also be subscribed to via their respective ROS topics.
The px4_sitl.launch.py launches processes in multiple gnome terminals. You may need to edit these lines to launch your respective terminal application if necessary.
sequenceDiagram
participant User
participant PIXI
participant RoboStack
participant Launch
participant Gazebo
participant ROS_Bridge
participant ROS_Nodes
User->>PIXI: pixi run -e jazzy sim
PIXI->>RoboStack: Activate ROS 2 Jazzy environment
RoboStack->>RoboStack: Configure CycloneDDS, RMW_IMPLEMENTATION
RoboStack->>Launch: Execute sim_with_bridge.launch.py
Launch->>Launch: Set GZ_SIM_RESOURCE_PATH
Launch->>Launch: Detect platform (macOS vs Linux)
Launch->>Gazebo: Start Gazebo server (+ GUI on macOS)
Gazebo->>Gazebo: Load playfield.sdf world
Gazebo->>Gazebo: Spawn quadcopter model with 8 sensors
Gazebo->>Gazebo: Initialize physics simulation
Launch->>ROS_Bridge: Start parameter_bridge nodes with TimerAction
Note over ROS_Bridge: 16 bridges (8 sensors × 2 topics)<br/>staggered at 0.2s intervals
ROS_Bridge->>ROS_Bridge: Bridge cmd_vel and odometry topics (immediate)
ROS_Bridge->>ROS_Bridge: Monitor for sensor topics (lazy activation)
Gazebo->>ROS_Bridge: Publish sensor topics once active
Note over Gazebo,ROS_Bridge: Gazebo publishes:<br/>/model/robot/model/tof_*/link/sensor/camera/*
ROS_Bridge->>ROS_Bridge: Activate lazy bridges for sensor topics
ROS_Bridge->>ROS_Bridge: Publish ROS sensor topics
Note over ROS_Bridge: ROS topics:<br/>/tof_*/image, /tof_*/camera_info
Launch->>ROS_Nodes: Start custom Python nodes
ROS_Nodes->>ROS_Nodes: Initialize tof8x8_to_scan (8 instances)
ROS_Nodes->>ROS_Nodes: Initialize scan_merger
ROS_Nodes->>ROS_Nodes: Initialize test_controller
ROS_Nodes->>ROS_Bridge: Subscribe to ROS sensor topics
ROS_Bridge->>ROS_Nodes: Forward Gazebo sensor data as ROS messages
ROS_Nodes->>ROS_Bridge: Publish LaserScan topics
ROS_Nodes->>ROS_Bridge: Publish merged scan topic
User->>ROS_Nodes: Send velocity commands (optional)
ROS_Nodes->>ROS_Bridge: Forward commands to Gazebo
This project uses RoboStack - a conda-based ROS distribution that integrates seamlessly with pixi for reproducible ROS 2 development environments.
The project uses pixi for environment management. Key commands:
# Enter the ROS environment
pixi shell -e jazzy
# Run commands in the environment
pixi run -e jazzy <command>
# Update dependencies
pixi update
# Clean build artifacts
pixi run -e jazzy cleanThe build system installs directly into the pixi environment (.pixi/envs/jazzy/), eliminating the need for traditional ROS workspace sourcing.
# Build the package
pixi run -e jazzy build
# The package is automatically available in the ROS environment- Reproducible: Lock files ensure consistent environments
- Cross-platform: Works on macOS, Linux, and Windows
- Isolated: No conflicts with system packages
- Simple: One-command setup and activation
- Fast: Incremental builds and caching
- DDS-Ready: Automatically configured with CycloneDDS (prevents FastDDS hanging)
-
ROS commands not found: Make sure you're in the pixi shell
pixi shell -e jazzy
-
Build fails: Clean and rebuild
pixi run -e jazzy rebuild
-
Gazebo issues: Ensure graphics drivers support OpenGL
# On macOS, you might need: export LIBGL_ALWAYS_SOFTWARE=1
-
TF_OLD_DATA/ "Detected jump back in time": You have multiple/clockpublishers (usually from a stalegz sim/parameter_bridgeprocess).pixi run -e jazzy cleanup_sim pixi run -e jazzy -- ros2 topic info /clock # should show Publisher count: 1
- Check the RoboStack documentation
- Review the package-specific README in
tof_slam_sim/ - Open an issue for bugs or feature requests
Apache 2.0