Autonomous 3D navigation with obstacle avoidance for a PX4 multirotor on ROS 2.
Give it a goal and the drone flies there on its own: it maps the world in 3D as it flies, tracks the people and vehicles that move, plans around both, replans in flight when something new blocks the way, and recovers when no plan can be found. It runs on ROS 2 Lyrical with PX4 main (native Zenoh or uXRCE-DDS) and is tested end to end in PX4 SITL with Gazebo.
Left Gazebo, right RViz: the 3D map built in flight (voxels coloured by height), the global
A* route (blue), the local path (green, Informed-RRT* then) and the track flown (orange).
- 3D mapping from a 3D lidar and a front depth camera into a Bonxai occupancy map, shared zero-copy between the servers.
- Moving-object tracking: people, carts and flying objects are found in the lidar scans and the depth camera's cloud, tracked with their velocity, left out of the map, and planned around where they are going.
- Two-level planning: a global A* route over the whole volume and a local AIT* path along it (OMPL), a few metres at a time; long detours are flown over.
- Smooth flight: paths are flown as jerk-limited trajectories with feed-forward, and new paths are spliced on without stopping.
- Replanning in flight when newly mapped obstacles or moving objects block the path, plus dodging what comes at the vehicle.
- Recoveries driven by a BehaviorTree.CPP tree: wait for moving objects to pass, climb to see over what blocks the way, or back up.
- Landing and return home: the drone lands at the goal (PX4's Land mode) and takes off for the next one; on a low battery it flies home around obstacles and lands there.
- A real PX4 flight mode: "UAV Nav" shows up in QGroundControl and on the RC switch next to PX4's own modes; PX4's failsafes and the pilot always take precedence. OFFBOARD works too.
- Nav2-style architecture: lifecycle servers in one container, pluginlib planners and
path followers, Nav2's
navigate_to_posegoal interface, health on/diagnostics.
flowchart LR
subgraph PX4["PX4 autopilot (SITL or real)"]
ODO["odometry, status,<br/>failsafe flags"]
IN["trajectory setpoints,<br/>commands, mode"]
end
subgraph C["nav_container (one process, zero-copy)"]
PE["perception"]
MS["map_server"]
PS["planner_server<br/>A* + AIT*"]
CS["controller_server"]
BS["behavior_server"]
NV["navigator"]
end
LIDAR["3D lidar"] --> PE
DEPTH["front depth camera"] --> PE
PE -- "static points" --> MS
PE -- "moving objects" --> PS
PE -- "moving objects" --> CS
ODO --> DP["drone_pose<br/>map → base_link"]
DP -- tf --> MS
MS -- "3D map" --> PS
MS -- "3D map" --> CS
GOAL["goal<br/>(RViz, navigate_to_pose)"] --> NV
NV -- compute_path --> PS
NV -- follow_path --> CS
NV -- "climb, back_up, wait" --> BS
BS -- follow_path --> CS
ODO --> CS
CS --> IN
Each server is its own package, with a README that explains what it does, its parameters and how it was measured:
| Package | Role |
|---|---|
uav_map_server |
Mapping: lidar and depth camera → Bonxai 3D occupancy map, incremental snapshots, zero-copy transport, save / load |
uav_perception |
Perception: moving objects found in the scans, tracked, and removed from what gets mapped |
uav_planner_server |
Path planning: compute_path, a global route and a local path through plugins |
uav_planners |
the planner plugins: A* (global) and AIT* / ABIT* (local, OMPL) |
uav_controller_server |
Control: follow_path, the "UAV Nav" PX4 mode, failsafes, blocked-path checks, dodging |
uav_controllers |
the path follower plugin: jerk-limited reference with feed-forward |
uav_navigator |
Navigation: navigate_to_pose, a behavior tree over planning, following and recoveries |
uav_behavior_server |
Recoveries: climb, back up, wait |
uav_nav_core |
shared library: map snapshots, collision checking, plugin interfaces |
uav_nav_msgs |
messages, actions and services |
uav_nav_bringup |
launch, parameters, RViz view, PX4 SITL model and worlds; how the servers communicate |
The map → base_link tf comes from
drone_pose (separate repo).
docs/bonxai_eval compares Bonxai with OctoMap on recorded scans.
Needs ROS 2 Lyrical, PX4 main, Gazebo Jetty, rmw_zenoh_cpp, OMPL and the packages listed
in the bringup README.
cd ~/ros2_ws/src && git clone https://github.com/facontidavide/Bonxai.git
cd ~/ros2_ws/src && git clone --recursive https://github.com/Auterion/px4-ros2-interface-lib
cd ~/ros2_ws && colcon build --packages-up-to uav_nav_bringup drone_poseIn simulation, each in its own terminal (source ~/ros2_ws/install/setup.bash,
export RMW_IMPLEMENTATION=rmw_zenoh_cpp):
ros2 run rmw_zenoh_cpp rmw_zenohdPX4_GZ_WORLD=obstacle_course uav_nav_bringup/sim/run_px4_sitl.shros2 launch uav_nav_bringup bringup.launch.py use_sim_time:=true auto_arm:=true gz_bridge:=true rviz:=trueThe drone arms and takes off by itself; then send a goal with RViz's 2D Goal Pose, or:
ros2 action send_goal /navigate_to_pose nav2_msgs/action/NavigateToPose "{pose: {header: {frame_id: map}, pose: {position: {x: 0.0, y: -8.0, z: 2.0}}}}" --feedbackOther worlds (recovery_course, mixed_field), the real-drone setup and every launch
argument are in the bringup README.
- Unknown space is free for the planner: only what the sensors have mapped is planned around. The controller keeps the drone able to stop in seen space, so it crawls (about 0.6 m/s, 1 m/s on steep climbs) where a path leads into space nothing has seen yet.
- Fresh obstacles close in front: when something appears right in front of the drone (a sliding door closing), the space under it now counts as unseen until the sensors see through it. The SITL door runs never reproduced the old duck-under, with or without it, so the fix is checked by unit tests only.
- Below the lidar: to the sides and behind (the depth camera covers the front), a person closer than about 2 m is below the lidar's ±15° view and is followed by prediction only.
- Flying objects: a moving object keeps its own height only once the lidar has seen the space under it empty on 3 scans in a row; until then its box reaches the ground.
- Measured in simulation: every number in these READMEs comes from PX4 SITL; the depth camera has not been tried on real hardware yet.
Each package's README lists its own known issues.






