The instructions are assuming Ubuntu 22.04 and use ROS2 Humble and PX4 from the main branch (going to be v1.14).
Install ROS2 Humble according to offical instructions. I ended up install the full desktop, so that I could try the Talker-listener example.
Install the toolchain as explained in the PX4 docs, namely:
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
PX4-Autopilot/Tools/setup/ubuntu.sh --no-nuttx
Then I built and ran it:
make px4_sitl gazebo_iris
(Note that make px4_sitl gazebo
no longer works).
Leave PX4 running, and create a new terminal for the next step.
Install micro-ROS and run it.
Source the ROS2 environment:
source /opt/ros/humble/setup.bash
Create a workspace:
mkdir microros_ws
cd microros_ws
mkdir src
Clone repo:
git clone -b humble https://github.com/micro-ROS/micro_ros_setup.git src/micro_ros_setup
And build it:
colcon build
source install/local_setup.bash
ros2 run micro_ros_setup create_agent_ws.sh
ros2 run micro_ros_setup build_agent.sh
For the first time it complained that I needed to run:
sudo rosdep init
rosdep update
Now the micro-ROS agent can be run:
source install/local_setup.bash
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888
It should report that several subscribers and topics have been created.
Leave it running, and open a new terminal for the next step.
Again, source the ROS2 environment:
source /opt/ros/humble/setup.bash
Then, try to check if you can see the topics published by PX4:
ros2 topic list
The output should be something like this:
/fmu/in/obstacle_distance
/fmu/in/offboard_control_mode
/fmu/in/onboard_computer_status
/fmu/in/sensor_optical_flow
/fmu/in/telemetry_status
/fmu/in/trajectory_setpoint
/fmu/in/vehicle_attitude_setpoint
/fmu/in/vehicle_command
/fmu/in/vehicle_mocap_odometry
/fmu/in/vehicle_rates_setpoint
/fmu/in/vehicle_trajectory_bezier
/fmu/in/vehicle_trajectory_waypoint
/fmu/in/vehicle_visual_odometry
/fmu/out/failsafe_flags
/fmu/out/sensor_combined
/fmu/out/timesync_status
/fmu/out/vehicle_attitude
/fmu/out/vehicle_control_mode
/fmu/out/vehicle_global_position
/fmu/out/vehicle_gps_position
/fmu/out/vehicle_local_position
/fmu/out/vehicle_odometry
/fmu/out/vehicle_status
/parameter_events
/rosout
If so, you should be ready for the example:
Again, source the ROS2 environment:
source /opt/ros/humble/setup.bash
Create a second ROS workspace for the offboard example
mkdir example_ws
cd example_ws
mkdir src
git clone https://github.com/PX4/px4_msgs.git
git clone https://github.com/PX4/px4_ros_com.git src/px4_ros_com
git clone https://github.com/Jaeyoung-Lim/px4-offboard.git src/px4-offboard
Then build it:
colcon build
Check if you can see the PX4 messages being published now, e.g.
ros2 topic echo /fmu/out/vehicle_status
For me, it looks something like:
timestamp: 1673219083786731
armed_time: 0
takeoff_time: 0
arming_state: 1
...
---
Now, you can try to run the example:
ros2 launch px4_offboard offboard_position_control.launch.py
Nothing happens just yet, we need to do a few steps in QGroundControl.
Open QGroundControl which should connect automatically.
To allow arming, we need to tell PX4 that it's fine to do offboard control without RC connected.
Go to Vehicle Setup, Parameters, and set COM_RCL_EXCEPT to 4 which means Offboard is ignored.
Then go back and click on the mode and switch it to Offboard. Then, click on Ready to fly and click Arm.
It should now take off and start flying a circle, as commanded by the offboard Python script.
- ROS2 install: https://docs.ros.org/en/humble/Installation/Ubuntu-Install-Debians.html
- PX4 toolchain: https://docs.px4.io/main/en/dev_setup/dev_env_linux_ubuntu.html#gazebo-jmavsim-and-nuttx-pixhawk-targets
- Tutorial for micro-ROS and example: https://github.com/Jaeyoung-Lim/px4-offboard/pull/8/files
- Offboard example: https://github.com/Jaeyoung-Lim/px4-offboard
Thanks for this tutorial, we used it and manage to run the PX4 in offboard mode with ROS2, we even connect it to Foxglove Studio and viewed the topics from there:
Screencast.from.03-15-2023.03.50.08.PM.webm
Is there a way to enter
offboard
andarm
the drone directly from the code (withoutQGroundControl
)?Thanks again!