This repository
contains a python examples for offboard control on ROS2 with PX4
The px4_offboard
package contains the following nodes
offboard_control.py
: Example of offboard position control using position setpointsvisualizer.py
: Used for visualizing vehicle states in Rvizvelocity_control.py
: Example of offboard velocity control based from ROS2_PX4_Offboard_Examplecontrol.py
: Keyboard User input to be sent to velocity control
The source code is released under a BSD 3-Clause license.
- Author: Jaeyoung Lim
- Affiliation: Autonomous Systems Lab, ETH Zurich
- Maintainer: Kyuhyong You
Add the repository to the ros2 workspace
git clone https://github.com/kyuhyong1/px4-offboard
You will make use of 3 different terminals to run the offboard demo.
On the first terminal, run a SITL instance from the PX4 Autopilot firmware.
make px4_sitl gazebo
On the second terminal terminal, run the micro-ros-agent which will perform the mapping between Micro XRCE-DDS and RTPS. So that ROS2 Nodes are able to communicate with the PX4 micrortps_client.
micro-ros-agent udp4 --port 8888
First you will need to start micro-ros-agent either from the Host PC or Companion computer(CC) depending on how PX4 is connected to.
If CC is connected to PX4 via serial port(/dev/ttyHS1) with baud rate of 2000000,
$ ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyHS1 -b 2000000
To run the offboard teleop control example, open a terminal and run the the node.
ros2 launch px4_offboard offboard_teleop_control.launch.py
This will launch teleop_keyboard.py which takes keyboard input from user to send Twist command to offboard_commander node.
Available commands as below
-
W: Velocity +Z (Move up)
-
X: Velocity -Z (Move down)
-
A: Velocity +Y (Move Left)
-
D: Velocity -Y (Move Right)
-
Arrow Up: Velocity +X (FWD)
-
Arrow Down: Velocity -X (REV)
-
Arrow Left: Rotate +Z (Yaw Left)
-
Arrow Right: Rotate -Z (Yaw Right)
-
S: Reset velocity to zero
-
O: Set to OFFBOARD mode
-
SPACE: Set ARM
-
T: Set to TAKEOFF mode
-
L: Set to LAND mode
-
BACKSPACE: Set DISARM
In order to run the offboard position control example, open a third terminal and run the the node. This runs two ros nodes, which publishes offboard position control setpoints and the visualizer.
ros2 launch px4_offboard offboard_position_control.launch.py
In order to just run the visualizer,
ros2 launch px4_offboard visualize.launch.py