A comprehensive ROS 2 Gazebo-based simulation for BFMC (Bosch Future Mobility Challenge) autonomous vehicle competition. This project provides a containerized environment for developing and testing autonomous driving algorithms.
- Requirements
- Quick Start
- Detailed Setup
- Running the Simulation
- Common Commands
- Troubleshooting
- Project Structure
Before getting started, ensure you have:
- Docker (version 20.10+)
- Docker Compose (optional, for easier management)
- Git
- X11 server (for GUI support on Linux)
- Adequate disk space (~5GB for Docker image and dependencies)
- Linux system with Docker support
- GPU recommended for smooth simulation performance
- Minimum 4GB RAM (8GB+ recommended)
If you already have the Docker image built, here's the fastest way to get running:
# 1. Allow Docker to access your X11 display
xhost +local:docker
# 2. Start the existing container
docker start bfmc_sim
# 3. Enter the container
docker exec -it bfmc_sim bash
# 4. Inside the container, run the simulation
./sim.shgit clone https://github.com/BFMC-Cathi/Simulation
cd SimulationThe Dockerfile includes all dependencies for ROS 2 Humble, Gazebo, and the BFMC environment.
docker build -t team_cathi/bfmc_env .Expected output: Docker image team_cathi/bfmc_env created successfully (this may take 5-10 minutes)
First, allow Docker access to your X11 display for GUI rendering:
xhost +local:dockerThen, create and start the container:
docker run -it \
--name bfmc_sim \
--network=bridge \
--env DISPLAY=$DISPLAY \
--env QT_X11_NO_MITSHM=1 \
--device /dev/dri:/dev/dri \
--volume /tmp/.X11-unix:/tmp/.X11-unix \
--volume $(pwd):/home/ros_dev/BFMC_workspace \
team_cathi/bfmc_env bashExplanation of flags:
-it: Interactive terminal mode--name bfmc_sim: Names the container for easy reference--env DISPLAY=$DISPLAY: Enables GUI rendering--device /dev/dri:/dev/dri: Enables GPU acceleration--volume: Mounts your project folder into the container
Once inside the container, run:
# Execute the simulation script
./sim.shThis script will:
- Set up the ROS 2 environment variables
- Configure Gazebo resource paths
- Load the traffic light plugin
- Launch the BFMC Competition World
Expected behavior: Gazebo window opens with the simulated track and vehicle.
# Start an existing container
docker start bfmc_sim
# Enter a running container
docker exec -it bfmc_sim bash
# Stop the container
docker stop bfmc_sim
# Remove the container (if needed)
docker rm bfmc_sim
# View running containers
docker ps
# View all containers (including stopped ones)
docker ps -a# Navigate to workspace
cd /home/ros_dev/BFMC_workspace/files/ros
# Source the ROS environment (already done in .bashrc)
source /opt/ros/humble/setup.bash
source install/setup.bash
# Build the ROS packages (if you made changes)
cd /home/ros_dev/BFMC_workspace/files/ros
colcon build
# Run the simulation
./sim.sh
# List available ROS topics
ros2 topic list
# Echo a specific topic (for debugging)
ros2 topic echo /topic_name
# View the ROS node graph
ros2 node list# Clear Gazebo cache (useful if you see texture glitches)
rm -rf ~/.ignition/gazebo/
# Reset library paths before launching
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ros/humble/lib
export IGN_GAZEBO_RESOURCE_PATH=/home/ros_dev/BFMC_workspace/files/simulation/models_pkg
export IGN_GAZEBO_SYSTEM_PLUGIN_PATH=$IGN_GAZEBO_SYSTEM_PLUGIN_PATH:/home/ros_dev/BFMC_workspace/files/ros/install/traffic_light_plugin/lib/traffic_light_plugin
# Set the rendering engine
export IGN_GAZEBO_RENDER_ENGINE_GUI=ogreSimulation/
├── Dockerfile # Docker configuration
├── sim.sh # Main simulation launch script
├── README.md # This file
├── files/
│ ├── ros/ # ROS 2 workspace
│ │ ├── src/ # Source code
│ │ │ ├── car_brain/ # Vehicle control package
│ │ │ └── traffic_light_plugin/ # Traffic light simulation
│ │ ├── build/ # Build artifacts
│ │ └── install/ # Installed packages
│ └── simulation/ # Gazebo simulation assets
│ ├── world.sdf # World definition
│ └── models_pkg/ # 3D models for tracks and objects
Solution:
# Restart the X11 authorization
xhost +local:docker
# Then start/restart the container
docker stop bfmc_sim
docker start bfmc_sim
docker exec -it bfmc_sim bashSolution:
# Make the script executable
chmod +x sim.sh
# Then run it
./sim.shSolution:
# Clear the Gazebo cache
rm -rf ~/.ignition/gazebo/
# Verify resource paths are set
echo $IGN_GAZEBO_RESOURCE_PATHSolution:
# Check if GPU is accessible
glxinfo | grep "OpenGL"
# Alternatively, try software rendering
export IGN_GAZEBO_RENDER_ENGINE_GUI=ogre2Solution:
# Rebuild the packages
cd /home/ros_dev/BFMC_workspace/files/ros
colcon build --symlink-install
# Make sure environment is sourced
source install/setup.bashHappy simulating! 🚗