/ros2_px4_bbox_ctrl

Target bounding box based drone control in ROS2 and PX4

Primary LanguageC++

Drone control with PX4 and ROS2 based on bounding boxes from CNN inference

Dereived from https://github.com/nhma20/mmWave_ROS2_PX4_Gazebo

Prerequisites

Tested with:

  • Ubuntu 20.04.3 LTS
  • ROS2 Foxy
  • Gazebo 11.9.0
  • px4_ros_com 29th Nov
  • PX4 Autopilot v1.12.3

Launch all

https://docs.px4.io/master/en/ros/ros2_offboard_control.html https://github.com/PX4/px4_ros_com/blob/master/src/examples/offboard/offboard_control.cpp

  1. If offboard_control.cpp or other files have been edited, re-run install.sh script (add new files to script and CMakeLists.txt):
    cd ~/mmWave_ROS2_PX4_Gazebo/
    ( chmod +x ./install.sh )
    ./install.sh
    If same PX4 and px4_ros_com_ros2 roots:
    ./install.sh ~/PX4-Autopilot/ ~/px4_ros_com_ros2/
    
  2. Launch PX4 SITL:
     cd ~/PX4-Autopilot/ 
     make px4_sitl_rtps gazebo
    Without Gazebo GUI:
     HEADLESS=1 make px4_sitl_rtps gazebo_iris__hca_full_pylon_setup
    Without drone following:
     PX4_NO_FOLLOW_MODE=1 make px4_sitl_rtps gazebo_iris__hca_full_pylon_setup
    After PX4 SITL fully launched, might need to manually start microRTPS client in same terminal:
     micrortps_client start -t UDP
    Will fail and return -1 if already running.
  3. Optional: Open QGroundControl
  4. In a new terminal, start the fake bounding box publisher:
    source ~/px4_ros_com_ros2/install/setup.bash
    ros2 run px4_ros_com lidar_to_mmwave 
  5. In another terminal, start the velocity vector calculator and publisher:
    source ~/px4_ros_com_ros2/install/setup.bash
    ros2 run px4_ros_com vel_ctrl_vec_pub
  6. In a new terminal start microRTPS agent and offboard control:
    source ~/px4_ros_com_ros2/install/setup.bash
    micrortps_agent start -t UDP & ros2 run px4_ros_com offboard_control 
  7. Simulated drone in Gazebo should arm and takeoff, hover, do some maneuvers based on bbox in the fake bbox publisher, then land.

MISC

  1. Trajectory setpoint message: https://github.com/PX4/px4_msgs/blob/ros2/msg/TrajectorySetpoint.msg

  2. Disabled param: pxh> param set NAV_RCL_ACT 0

    NAV_RCL_ACT: curr: 2 -> new: 0

  3. Add any new ROS2 files to ~/px4_ros_com_ros2/src/px4_ros_com/CMakeLists.txt

  4. libignition-common3 error (after software update?) - Copy existing file and rename to match missing file

  5. If gazebo does not open, try running gazebo --verbose to troubleshoot. killall gzserver should kill any gazebo instances. Else, retry in fresh terminal. Restart PC if all else fails.

  6. In CMakeLists.txt add new msgs.

  7. After running ./build_ros2_workspace restart all affected executables.

  8. iris.sdf (or other models) can be edited to include sensors, like 2D lidar.

  9. Display simulated camera feed either with rviz2 or

source ~/px4_ros_com_ros2/install/setup.bash
ros2 run image_tools showimage image:=/cable_camera/image_raw
  1. See local packages, and msgs, with: ros2 interface packages and e.g. ros2 interface package px4_msgs
  2. Drone spawn coordinates set in ~/PX4-Autopilot/Tools/sitl_run.sh ?
  3. *** No rule to make target '/opt/ros/foxy/lib/libfastrtps.so.2.0.2', needed by 'libpx4_msgs__rosidl_typesupport_fastrtps_cpp.so'. Stop. Fixed by renaming closest libfastrtps.so.x.y.z to libfastrtps.so.2.0.2.
  4. Dependency errors with PX4, like ninja: error: '/usr/lib/x86_64-linux-gnu/libsdformat9.so.9.6.1', needed by 'libmav_msgs.so', missing and no known rule to make it may be solved by a PX4 reinstall (remember worlds, models, cmake files etc. must be also be reinstalled into new PX4).
  5. If drone enters failsafe when starting offboard_control, param set COM_RCL_EXCEPT 4 in the PX4 console may solve this. Else, try manually publish few setpoints to fmu/manual_control_setpoint/in and then start offboard mode.
  6. Showing videos in readme: Just drag and drop your image/video from your local pc to github readme in editable mode.
  7. If gradle not working, might have to downgrade Java (JDK) to 11: https://askubuntu.com/questions/1133216/downgrading-java-11-to-java-8

TODO

  1. 🟡 Set up with "real" bounding box to tune PI controller
  2. 🟡 Get working with real flight controller
  3. 🟡 Build in more safety