Skip to content

Latest commit

 

History

53 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drone Simulation with ArduPilot, MAVProxy, and Gazebo Harmonic

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.

1. What This Repo Is About

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

2. How to Install QGroundControl

# Download AppImage (64-bit Linux)
wget https://d176tv9ibo4jno.cloudfront.net/latest/QGroundControl.AppImage

# Make it executable
chmod +x QGroundControl.AppImage

# Run it
./QGroundControl.AppImage

You can also download the latest version from the official site: https://docs.qgroundcontrol.com/master/en/getting_started/download_and_install.html

3. Installing the required Softwares

To install Ardupilot:

Downloading the Code / Using Git — Dev documentation

Setting up SITL for Ardupilot

Follow steps in the Documentation

For Ardupilot gazebo plugin:

https://github.com/ArduPilot/ardupilot_gazebo/blob/685e3e3d10c0ba33324df2b81474f9ed5c01289f/README.md

Installing MAVROS:

To install MAVROS :

Step 1: Get MAVROS and MAVLink Sources

# 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.repos

Step 2: Install Dependencies

rosdep update
rosdep install --from-paths src --ignore-src -y

Step 3: Install GeographicLib Datasets (Required by MAVROS)

./src/mavros/mavros/scripts/install_geographiclib_datasets.sh

Step 4: Build the Workspace

colcon build

Step 5: Source the Workspace

source install/setup.bash

Add this line to your .bashrc if you'd like it sourced automatically:

echo "source ~/ros2_ws/install/setup.bash" >> ~/.bashrc

4. How to Run QGroundControl with SITL using ArduPilot

  1. Run SITL with MAVProxy:
cd ardupilot/ArduCopter
sim_vehicle.py -v ArduCopter -f gazebo-iris --console --map
  1. Launch QGroundControl:
./QGroundControl.AppImage

note: this must be used from directory where it is downloaded usually /home/(name)/Downloads/

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

5. ArduPilot + Gazebo + MAVROS (ROS 2) Quick Start

This guide walks you through running ArduCopter (Iris) simulation in Gazebo, connecting with MAVROS (ROS 2), and sending basic commands.

  1. Run Gazebo
cd ardupilot_gazebo
gz sim -v4 -r iris_runway.sdf
  1. Start ArduPilot SITL

Navigate to your ArduPilot directory and run:

sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --map --console
  1. Check MAVROS State (in another terminal)
ros2 topic echo /mavros/state
  1. Connect MAVROS (in another terminal)
ros2 run mavros mavros_node --ros-args -p fcu_url:=udp://:14550@localhost:14550
  1. 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}"
  1. 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}}}"
  1. 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}}}"

Notes

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

6. Robot Vizualization using RViz

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.

Directory structure

drone_ws/
├── src/
│   └── drone/
|       ├── drone/
│       │   └── __init__.py
│       │   └── pose_to_tf_broadcaster.py
│       ├── launch/
│       │   └── robot_launch.py
│       ├── urdf/
│       │   └── my_robot.urdf
│       └── ...

Building the Workspace

Open a terminal and run the following commands:

cd ~/drone_ws
colcon build
source ~/drone_ws/install/setup.bash

Launch the Drone

Run the following command to launch the drone:

ros2 launch drone robot_launch.py

Visualize in RViz

  1. Open a new terminal and run:

    rviz2
  2. 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.

7. Drone Camera topic

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

then we can use rqt_image_viewer to view the topic

ros2 run rqt_image_view rqt_image_view

We can also view this in Rviz. To open Rviz follow the below command

rviz2

Inside 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/image

from the drop down menu and you will be able to see the image from the cam

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages