Simulated PX4 Iris drone for autonomous path planning and obstacle avoidance using MAVROS and ROS2. Integrated real-time weed detection via YOLO-based segmentation from drone-captured images to enable targeted field surveys.
This project demonstrates a simulated PX4 Iris drone navigating through a designated area using MAVROS and ROS2, with real-time obstacle avoidance and camera-based weed detection using YOLOv8.
The goal of this project is to:
- Simulate the PX4 Iris drone in a Gazebo environment.
- Implement autonomous path planning for obstacle-free navigation.
- Capture images at waypoints using the drone’s camera plugin.
- Apply YOLO-based computer vision to detect and segment weeds in the captured images for an autonomous field survey.
- Generate heat maps to visualize weed density in the surveyed area.
-
The drone follows a set of waypoints generated dynamically to explore the environment while avoiding obstacles.
-
Real-time data from sensors are used to plan an optimal obstacle-free path.
You can see the trajectory of the drone and the waypoints with the range below:
The PX4 Iris drone is simulated in Gazebo with real-time control using MAVROS and ROS2 for communication between the drone and the host system.
- The simulation environment contains various obstacles (e.g., trees) that the drone avoids while exploring the area.
- Optimized path planning algorithms ensure smooth navigation, even in complex environments.
A camera plugin is attached to the drone to capture images at each waypoint. These images are processed for further analysis and detection tasks.
- Camera Features: Real-time image capture, high-definition snapshots, suitable for agricultural analysis.
The captured images from each waypoint are fed into a YOLOv8 model that has been trained to detect and segment weeds.
- YOLO Model: The pre-trained YOLOv8 model identifies weeds with high accuracy and provides segmentation masks for further field analysis.
- This enables the drone to autonomously detect weed clusters in a given area, which can be crucial for agricultural automation.
- The weed detection data collected during the drone's flight is used to create a heat map visualizing weed density across the surveyed area.
- The heat map helps in identifying the most infested regions, aiding in targeted weed management strategies.
After detecting the weeds, the images are processed in real-time to extract weed segmentation data, allowing the drone to focus on areas that require attention during field surveys.
- The segmentation results are then integrated with the drone's navigation system, allowing the drone to target specific areas.
To set up the project on your local machine, follow these steps:
- Clone the Repository:
git clone https://github.com/Masudali23/PX4-Iris-Drone-Project.git cd PX4-Iris-Drone-Project - Install Dependencies: Install ROS2, MAVROS, and PX4 (follow official documentation for setup). Also, install additional libraries for YOLO:
pip install opencv-python torch torchvision
- Install YOLOv8: Clone the YOLOv8 repository and install its requirements:
git clone https://github.com/ultralytics/yolov8.git cd yolov8 pip install -r requirements.txt
- Build the Project: (for Ros 2)
colcon build
- Run the Simulation:
Launch the Gazebo simulation with a custom world:
PX4_SITL_WORLD=/path_to_your_world/name_of_your_world.sdf make px4_sitl gazebo
- Launch MAVROS:
Start MAVROS with the appropriate FCU URL:
ros2 launch mavros px4.launch fcu_url:="udp://:14540@localhost:14557" - Set OFFBOARD Mode:
Call the service to set the drone mode to OFFBOARD:
ros2 service call /mavros/set_mode mavros_msgs/srv/SetMode "{base_mode: 0, custom_mode: 'OFFBOARD'}" - Publish Drone Position:
Publish the drone's position at a frequency of 10 Hz for testing purposes:
ros2 topic pub -r 10 /mavros/setpoint_position/local geometry_msgs/msg/PoseStamped "{header: {stamp: {sec: 0, nanosec: 0}, frame_id: 'map'}, pose: {position: {x: 10.0, y: 10.0, z: 5.0}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}}" - Publish Drone Position from csv file: Execute the Python script for controlling the drone in your specific use case:
python3 path_of_your_script/drone_flight.py
- Arm the Drone: To arm the drone for flight, use the following command:
ros2 service call /mavros/cmd/arming mavros_msgs/srv/CommandBool "{value: true}"
- Ensure your ROS2 and MAVROS setups are correctly configured before running the project.
- Modify paths according to your local environment.
- The drone successfully navigated the area, avoiding obstacles and detecting weed clusters with a 90% accuracy using the YOLO model.
- The integration of real-time image processing allowed for autonomous field surveying, making the system suitable for agricultural automation tasks.
- The generated heat maps provided valuable insights into weed distribution across the surveyed area.
- Improve the accuracy of weed detection by training on a larger dataset.
- Extend the system for multi-drone coordination to cover larger areas.
- Implement additional crop health analysis features.





