Skip to content

nus-safmc/gazebo-slam-prototype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gazebo SLAM Prototype

Run simulation of SAFMC drone with ring of 8 ToF sensors using PX4 Software in the Loop (SITL)

Quick Start

Prerequisites

  • Pixi package manager
  • Git

Setup

  1. Clone the repository:

    git clone --recursive https://github.com/nus-safmc/gazebo-slam-prototype.git
    cd gazebo-slam-prototype

    Make sure to include the --recursive flag to clone all submodules

  2. Install dependencies and build:

    # This automatically sets up ROS 2 Jazzy and all dependencies
    pixi run -e jazzy build
  3. Activate the environment:

    pixi shell -e jazzy
    # ROS 2 environment is ready with CycloneDDS configured automatically

Usage

Once in the pixi shell, you can:

Launch the PX4 SITL environment:

pixi run -e jazzy px4_sitl

Viewing ROS topics The list of ROS topics created by the SITL simulation can be viewed using

ros2 topic list

Data 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.

Possible issue on non-Linux systems

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.

System Initialization Sequence

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
Loading

Package Structure

Development

This project uses RoboStack - a conda-based ROS distribution that integrates seamlessly with pixi for reproducible ROS 2 development environments.

Environment Management

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 clean

Building

The 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

Why RoboStack + Pixi?

  • 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)

Troubleshooting

Common Issues

  1. ROS commands not found: Make sure you're in the pixi shell

    pixi shell -e jazzy
  2. Build fails: Clean and rebuild

    pixi run -e jazzy rebuild
  3. Gazebo issues: Ensure graphics drivers support OpenGL

    # On macOS, you might need:
    export LIBGL_ALWAYS_SOFTWARE=1
  4. TF_OLD_DATA / "Detected jump back in time": You have multiple /clock publishers (usually from a stale gz sim / parameter_bridge process).

    pixi run -e jazzy cleanup_sim
    pixi run -e jazzy -- ros2 topic info /clock   # should show Publisher count: 1

Getting Help

  • Check the RoboStack documentation
  • Review the package-specific README in tof_slam_sim/
  • Open an issue for bugs or feature requests

License

Apache 2.0

About

Testing 2d SLAM with 8 x VL53L7CX TOF sensors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages