This repository contains the files and documentation for setting up a drone simulation environment using ArduPilot SITL, MAVProxy, Gazebo Harmonic, and QGroundControl. The simulation includes basic drone flight and waypoint navigation using QGroundControl.
This project demonstrates:
- Installing and running ArduPilot SITL (Software-In-The-Loop) for drone simulation
- Bridging with MAVProxy and Gazebo Harmonic for visual simulation
- Connecting to QGroundControl for mission planning and control
- Running basic waypoint navigation using QGroundControl + ArduPilot SITL
# Download AppImage (64-bit Linux)
wget https://d176tv9ibo4jno.cloudfront.net/latest/QGroundControl.AppImage
# Make it executable
chmod +x QGroundControl.AppImage
# Run it
./QGroundControl.AppImageYou can also download the latest version from the official site: https://docs.qgroundcontrol.com/master/en/getting_started/download_and_install.html
To install Ardupilot:
Downloading the Code / Using Git — Dev documentation
Setting up SITL for Ardupilot
Follow steps in the Documentation
For Ardupilot gazebo plugin:
Installing MAVROS:
To install MAVROS :
# Navigate to your workspace root
cd ~/ros2_ws
# Generate repos file for MAVLink
rosinstall_generator --format repos mavlink | tee /tmp/mavlink.repos
# Append MAVROS repo definitions
rosinstall_generator --format repos --upstream mavros | tee -a /tmp/mavros.repos
# Import source code into the workspace
vcs import src < /tmp/mavlink.repos
vcs import src < /tmp/mavros.reposrosdep update
rosdep install --from-paths src --ignore-src -y./src/mavros/mavros/scripts/install_geographiclib_datasets.shcolcon buildsource install/setup.bashAdd this line to your .bashrc if you'd like it sourced automatically:
echo "source ~/ros2_ws/install/setup.bash" >> ~/.bashrc- Run SITL with MAVProxy:
cd ardupilot/ArduCopter
sim_vehicle.py -v ArduCopter -f gazebo-iris --console --map
- Launch QGroundControl:
./QGroundControl.AppImagenote: this must be used from directory where it is downloaded usually /home/(name)/Downloads/
- QGroundControl will automatically connect via UDP on port 14550. You should see the simulated drone appear on the map. You can now use QGroundControl to send commands, upload waypoints, and monitor the drone state in real-time.
working demo https://www.youtube.com/watch?v=09Z5kr5EHag
This guide walks you through running ArduCopter (Iris) simulation in Gazebo, connecting with MAVROS (ROS 2), and sending basic commands.
- Run Gazebo
cd ardupilot_gazebo
gz sim -v4 -r iris_runway.sdf- Start ArduPilot SITL
Navigate to your ArduPilot directory and run:
sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --map --console- Check MAVROS State (in another terminal)
ros2 topic echo /mavros/state- Connect MAVROS (in another terminal)
ros2 run mavros mavros_node --ros-args -p fcu_url:=udp://:14550@localhost:14550- Set Mode, Arm, and Takeoff (in another terminal)
Set flight mode to GUIDED:
ros2 service call /mavros/set_mode mavros_msgs/srv/SetMode "{base_mode: 0, custom_mode: 'GUIDED'}"Arm the vehicle:
ros2 service call /mavros/cmd/arming mavros_msgs/srv/CommandBool "{value: true}"Take off to 5 meters altitude:
ros2 service call /mavros/cmd/takeoff mavros_msgs/srv/CommandTOL "{altitude: 5.0}"- Move Forward Continuously
To move forward at 1 m/s, publish at 10 Hz:
ros2 topic pub -r 10 /mavros/setpoint_velocity/cmd_vel geometry_msgs/msg/TwistStamped "{twist: {linear: {x: 1.0, y: 0.0, z: 0.0}}}"- Stop the Vehicle
To stop, publish zeros:
ros2 topic pub /mavros/setpoint_velocity/cmd_vel geometry_msgs/msg/TwistStamped "{twist: {linear: {x: 0.0, y: 0.0, z: 0.0}}}"- Use a new terminal for each major step as indicated.
- Ensure all dependencies (Gazebo, ArduPilot, MAVROS, ROS 2) are installed and sourced.
- Adjust file/model names as needed for your setup.
This part contains the final component of the ROS2 drone simulation project focused on robot visualization using RViz. The goal of this module is to reflect the drone's movements in Gazebo within RViz by broadcasting pose data and publishing the robot model for visualization.
drone_ws/
├── src/
│ └── drone/
| ├── drone/
│ │ └── __init__.py
│ │ └── pose_to_tf_broadcaster.py
│ ├── launch/
│ │ └── robot_launch.py
│ ├── urdf/
│ │ └── my_robot.urdf
│ └── ...Open a terminal and run the following commands:
cd ~/drone_ws
colcon build
source ~/drone_ws/install/setup.bashRun the following command to launch the drone:
ros2 launch drone robot_launch.py-
Open a new terminal and run:
rviz2
-
In the RViz window:
- Click Add.
- Select RobotModel.
- In the Description Topic, select /robot_description. You should see a red box appear in RViz, which mimics the drone in Gazebo.
To see image from camera, run the following command
ros2 run ros_gz_bridge parameter_bridge \
/world/iris_runway/model/iris_with_gimbal/model/gimbal/link/pitch_link/sensor/camera/image@sensor_msgs/msg/Image[gz.msgs.Imagethen we can use rqt_image_viewer to view the topic
ros2 run rqt_image_view rqt_image_viewWe can also view this in Rviz. To open Rviz follow the below command
rviz2Inside Rviz click on Add then Select image and then select the topic
/world/iris_runway/model/iris_with_gimbal/model/gimbal/link/pitch_link/sensor/camera/imagefrom the drop down menu and you will be able to see the image from the cam