diff --git a/assets/computer_vision/collision_prevention/obstacle_distance_def.svg b/assets/computer_vision/collision_prevention/obstacle_distance_def.svg new file mode 100644 index 000000000000..3538a31ce96b --- /dev/null +++ b/assets/computer_vision/collision_prevention/obstacle_distance_def.svg @@ -0,0 +1,1523 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/computer_vision/collision_prevention/scalefactor.png b/assets/computer_vision/collision_prevention/scalefactor.png new file mode 100644 index 000000000000..9667698afade Binary files /dev/null and b/assets/computer_vision/collision_prevention/scalefactor.png differ diff --git a/de/releases/main.md b/de/releases/main.md index cbdcea2bcc1f..cffdc77e83cb 100644 --- a/de/releases/main.md +++ b/de/releases/main.md @@ -70,6 +70,7 @@ Please continue reading for [upgrade instructions](#upgrade-guide). ### Multi-Rotor - Allow system-default [multicopter orbit mode](../flight_modes_mc/orbit.md) yaw behaviour to be configured, using the parameter [MC_ORBIT_YAW_MOD](../advanced_config/parameter_reference.md#MC_ORBIT_YAW_MOD) ([PX4-Autopilot#23358](https://github.com/PX4/PX4-Autopilot/pull/23358)) +- [Colision Prevention](../computer_vision/collision_prevention.md) rewrite for Manual Flight Modes. [PX4-Autopilot#23507](https://github.com/PX4/PX4-Autopilot/pull/23507) ### VTOL diff --git a/en/SUMMARY.md b/en/SUMMARY.md index 145d6b9f6a46..c005a4e23849 100644 --- a/en/SUMMARY.md +++ b/en/SUMMARY.md @@ -19,6 +19,7 @@ - [Mission Mode (MC)](flight_modes_mc/mission.md) - [Return Mode (MC)](flight_modes_mc/return.md) - [Offboard Mode (MC)](flight_modes_mc/offboard.md) + - [Collision Prevention](computer_vision/collision_prevention.md) - [Precision Landing](advanced_features/precland.md) - [Terrain Following/Holding](flying/terrain_following_holding.md) - [Throw Launch](flight_modes_mc/throw_launch.md) @@ -376,7 +377,6 @@ - [Holybro Pixhawk RPi CM4 Baseboard](companion_computer/holybro_pixhawk_rpi_cm4_baseboard.md) - [Auterion Skynode](companion_computer/auterion_skynode.md) - [Computer Vision](computer_vision/index.md) - - [Collision Prevention](computer_vision/collision_prevention.md) - [Path Planning Interface](computer_vision/path_planning_interface.md) - [Motion Capture (MoCap)](computer_vision/motion_capture.md) - [Visual Inertial Odometry (VIO)](computer_vision/visual_inertial_odometry.md) diff --git a/en/computer_vision/collision_prevention.md b/en/computer_vision/collision_prevention.md index b4fd048a1aad..edfc6dabaf29 100644 --- a/en/computer_vision/collision_prevention.md +++ b/en/computer_vision/collision_prevention.md @@ -1,89 +1,101 @@ # Collision Prevention _Collision Prevention_ may be used to automatically slow and stop a vehicle before it can crash into an obstacle. +It can be enabled for multicopter vehicles when using acceleration-based [Position mode](../flight_modes_mc/position.md) (or VTOL vehicles in MC mode). -It can be enabled for multicopter vehicles in [Position mode](../flight_modes_mc/position.md), and can use sensor data from an offboard companion computer, offboard rangefinders over MAVLink, a rangefinder attached to the flight controller, or any combination of the above. +## Overview -Collision prevention may restrict vehicle maximum speed if the sensor range isn't large enough! -It also prevents motion in directions where no sensor data is available (i.e. if you have no rear-sensor data, you will not be able to fly backwards). +The vehicle restricts the current velocity in order to slow down as it gets closer to obstacles and adapts the acceleration setpoint in order to disallow collision trajectories. +In order to move away from (or parallel to) an obstacle, the user must command the vehicle to move toward a setpoint that does not bring the vehicle closer to the obstacle. +The algorithm will make minor adjustments to the setpoint direction if it is determined that a "better" setpoint exists within a fixed margin on either side of the requested setpoint. -:::tip -If high flight speeds are critical, consider disabling collision prevention when not needed. -::: +Collision prevention prevents motion in directions where no sensor data is available (i.e. if you have no rear-sensor data, you will not be able to fly backwards). +It may also restrict vehicle maximum speed if the sensor range isn't large enough! + +Multiple sensors can be used to get information about, and prevent collisions with, objects _around_ the vehicle. +If multiple sources supply data for the _same_ orientation, the system uses the data that reports the smallest distance to an object. + +The feature requires obstacle information from a [distance sensor](../sensor/rangefinders.md). +The sensor may be connected to the flight controller (recommended). +It can also be used with distance information provided by an external system via MAVLink, but this is currently untested (see [companion setup](#companion) below). + +The [rangefinders](#rangefinder) that have been tested when directly connected to PX4 are listed below, along with setup instructions. +The [PX4 Configuration](#px4-configuration) specific to collision-prevention is the same for all sensors and independent of whether data is provided by a connected sensor or MAVLink. :::tip -Ensure that you have sensors/sensor data in all directions that you want to fly (when collision prevention is enabled). + +- If high flight speeds are critical, consider disabling collision prevention when not needed. +- Ensure that you have sensors/sensor data in all directions that you want to fly, including backwards (when collision prevention is enabled). + ::: -## Overview +## Supported Rangefinders {#rangefinder} -_Collision Prevention_ is enabled on PX4 by setting the parameter for minimum allowed approach distance ([CP_DIST](#CP_DIST)). +Collision Prevention has been tested with the following rangefinders attached to PX4 (not for providing data [supplied over MAVLink](#companion)). -The feature requires obstacle information from an external system (sent using the MAVLink [OBSTACLE_DISTANCE](https://mavlink.io/en/messages/common.html#OBSTACLE_DISTANCE) message) and/or a [distance sensor](../sensor/rangefinders.md) connected to the flight controller. +### Lanbao PSK-CM8JL65-CC5 -::: info -Multiple sensors can be used to get information about, and prevent collisions with, objects _around_ the vehicle. -If multiple sources supply data for the _same_ orientation, the system uses the data that reports the smallest distance to an object. -::: +At time of writing PX4 allows you to use the [Lanbao PSK-CM8JL65-CC5](../sensor/cm8jl65_ir_distance_sensor.md) IR distance sensor for collision prevention "out of the box", with minimal additional configuration: -The vehicle restricts the maximum velocity in order to slow down as it gets closer to obstacles, and will stop movement when it reaches the minimum allowed separation. -In order to move away from (or parallel to) an obstacle, the user must command the vehicle to move toward a setpoint that does not bring the vehicle closer to the obstacle. -The algorithm will make minor adjustments to the setpoint direction if it is determined that a "better" setpoint exists within a fixed margin on either side of the requested setpoint. +1. [Attach and configure the sensor](../sensor/cm8jl65_ir_distance_sensor.md). +1. Set the sensor orientation using [SENS_CM8JL65_R_0](../advanced_config/parameter_reference.md#SENS_CM8JL65_R_0). +1. [Configure and enable collision prevention](#px4-configuration) -Users are notified through _QGroundControl_ while _Collision Prevention_ is actively controlling velocity setpoints. +### LightWare LiDAR SF45 Rotating Lidar -PX4 software setup is covered in the next section. -If you are using a distance sensor attached to your flight controller for collision prevention, it will need to be attached and configured as described in [PX4 Distance Sensor](#rangefinder). -If you are using a companion computer to provide obstacle information see [companion setup](#companion). +PX4 v1.14 (and later) supports the [LightWare LiDAR SF45](https://www.lightwarelidar.com/shop/sf45-b-50-m/) rotating lidar which provides 320 degree sensing. -## PX4 (Software) Setup +The SF45 must be connected via a UART/serial port and configured as described below: -Configure collision prevention by [setting the following parameters](../advanced_config/parameters.md) in _QGroundControl_: +1. [LightWare Studio](https://www.lightwarelidar.com/resources-software) configuration: -| Parameter | Description | -| -------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [CP_DIST](../advanced_config/parameter_reference.md#CP_DIST) | Set the minimum allowed distance (the closest distance that the vehicle can approach the obstacle). Set negative to disable _collision prevention_.
> **Warning** This value is the distance to the sensors, not the outside of your vehicle or propellers. Be sure to leave a safe margin! | -| [CP_DELAY](../advanced_config/parameter_reference.md#CP_DELAY) | Set the sensor and velocity setpoint tracking delay. See [Delay Tuning](#delay_tuning) below. | -| [CP_GUIDE_ANG](../advanced_config/parameter_reference.md#CP_GUIDE_ANG) | Set the angle (to both sides of the commanded direction) within which the vehicle may deviate if it finds fewer obstacles in that direction. See [Guidance Tuning](#angle_change_tuning) below. | -| [CP_GO_NO_DATA](../advanced_config/parameter_reference.md#CP_GO_NO_DATA) | Set to 1 to allow the vehicle to move in directions where there is no sensor coverage (default is 0/`False`). | -| [MPC_POS_MODE](../advanced_config/parameter_reference.md#MPC_POS_MODE) | Set to `Direct velocity` or `Smoothed velocity` to enable Collision Prevention in Position Mode (default is `Acceleration based`). | + - In the LightWare Studio app enable scanning, set the scan angle, and change the baud rate to `921600`. -## Algorithm Description +1. Add [lightware_sf45_serial](../modules/modules_driver_distance_sensor.md#lightware-sf45-serial) driver to PX4 firmware: -The data from all sensors are fused into an internal representation of 36 sectors around the vehicle, each containing either the sensor data and information about when it was last observed, or an indication that no data for the sector was available. -When the vehicle is commanded to move in a particular direction, all sectors in the hemisphere of that direction are checked to see if the movement will bring the vehicle closer to any obstacles. -If so, the vehicle velocity is restricted. + 1. Open [menuconfig](../hardware/porting_guide_config.md#px4-menuconfig-setup) + 1. Under **drivers > Distance sensors** select `lightware_sf45_serial`. + 1. Recompile and upload to the flight controller. -This velocity restriction takes into account both the inner velocity loop tuned by [MPC_XY_P](../advanced_config/parameter_reference.md#MPC_XY_P), as well as the [jerk-optimal velocity controller](../config_mc/mc_jerk_limited_type_trajectory.md) via [MPC_JERK_MAX](../advanced_config/parameter_reference.md#MPC_JERK_MAX) and [MPC_ACC_HOR](../advanced_config/parameter_reference.md#MPC_ACC_HOR). -The velocity is restricted such that the vehicle will stop in time to maintain the distance specified in [CP_DIST](#CP_DIST). -The range of the sensors for each sector is also taken into account, limiting the velocity via the same mechanism. +1. [Set the following parameters](../advanced_config/parameters.md) via QGC to configure the driver: -::: info -If there is no sensor data in a particular direction, velocity in that direction is restricted to 0 (preventing the vehicle from crashing into unseen objects). -If you wish to move freely into directions without sensor coverage, this can be enabled by setting [CP_GO_NO_DATA](#CP_GO_NO_DATA) to 1. -::: + - [SENS_EN_SF45_CFG](../advanced_config/parameter_reference.md#SENS_EN_SF45_CFG): Set to the serial port you have the sensor connected to. + Make sure GPS or Telemetry are not enabled on this port. + - [SF45_ORIENT_CFG](../advanced_config/parameter_reference.md#SF45_ORIENT_CFG): Set the orientation of the sensor (facing up or down) + - [SF45_UPDATE_CFG](../advanced_config/parameter_reference.md#SF45_UPDATE_CFG): Set the update rate + - [SF45_YAW_CFG](../advanced_config/parameter_reference.md#SF45_YAW_CFG): Set the yaw orientation -Delay, both in the vehicle tracking velocity setpoints and in receiving sensor data from external sources, is conservatively estimated via the [CP_DELAY](#CP_DELAY) parameter. -This should be [tuned](#delay_tuning) to the specific vehicle. +1. [Configure and enable collision prevention](#px4-configuration) -If the sectors adjacent to the commanded sectors are 'better' by a significant margin, the direction of the requested input can be modified by up to the angle specified in [CP_GUIDE_ANG](#CP_GUIDE_ANG). -This helps to fine-tune user input to 'guide' the vehicle around obstacles rather than getting stuck against them. +PX4 will emit the [OBSTACLE_DISTANCE](https://mavlink.io/en/messages/common.html#OBSTACLE_DISTANCE) message when collision prevention is enabled. +In QGroundControl you should this in the [MAVLink console](../debug/mavlink_shell.md#qgroundcontrol-mavlink-console) if collision prevention is configured correctly and active. -### Range Data Loss +The obstacle overlay in QGC will look like this: -If the autopilot does not receive range data from any sensor for longer than 0.5s, it will output a warning _No range data received, no movement allowed_. -This will force the velocity setpoints in xy to zero. -After 5 seconds of not receiving any data, the vehicle will switch into [HOLD mode](../flight_modes_mc/hold.md). -If you want the vehicle to be able to move again, you will need to disable Collision Prevention by either setting the parameter [CP_DIST](#CP_DIST) to a negative value, or switching to a mode other than [Position mode](../flight_modes_mc/position.md) (e.g. to _Altitude mode_ or _Stabilized mode_). +![sf45](../../assets/sf45/sf45_obstacle_map.png) -If you have multiple sensors connected and you lose connection to one of them, you will still be able to fly inside the field of view (FOV) of the reporting sensors. -The data of the faulty sensor will expire and the region covered by this sensor will be treated as uncovered, meaning you will not be able to move there. +### Other Rangefinders -:::warning -Be careful when enabling [CP_GO_NO_DATA=1](#CP_GO_NO_DATA), which allows the vehicle to fly outside the area with sensor coverage. -If you lose connection to one of multiple sensors, the area covered by the faulty sensor is also treated as uncovered and you will be able to move there without constraint. +Other sensors may be enabled, but this requires modification of driver code to set the sensor orientation and field of view. + +- Attach and configure the distance sensor on a particular port (see [sensor-specific docs](../sensor/rangefinders.md)) and enable collision prevention using [CP_DIST](#CP_DIST). +- Modify the driver to set the orientation. + This should be done by mimicking the `SENS_CM8JL65_R_0` parameter (though you might also hard-code the orientation in the sensor _module.yaml_ file to something like `sf0x start -d ${SERIAL_DEV} -R 25` - where 25 is equivalent to `ROTATION_DOWNWARD_FACING`). +- Modify the driver to set the _field of view_ in the distance sensor UORB topic (`distance_sensor_s.h_fov`). + +:::tip +You can see the required modifications from the [feature PR](https://github.com/PX4/PX4-Autopilot/pull/12179). +Please contribute back your changes! ::: +## PX4 Configuration + +_Collision Prevention_ is enabled on PX4 by [setting the parameter](../advanced_config/parameters.md) for minimum allowed approach distance in QGroundControl to a positive value ([CP_DIST](#CP_DIST)). +Note that this value is the distance to the sensors, not the outside of your vehicle or propellers (set a safe margin!). + +In addition you will need to tune the [sendor delay](#delay_tuning) and [angle change tuning](#angle_change_tuning). +You may choose to enable [CP_GO_NO_DATA](#CP_GO_NO_DATA) in order to allow unprotected movement in directions where there is no rangefinder data/sensor. + ### CP_DELAY Delay Tuning {#delay_tuning} There are two main sources of delay which should be accounted for: _sensor delay_, and vehicle _velocity setpoint tracking delay_. @@ -115,75 +127,76 @@ The guidance feature will never direct the vehicle in a direction without sensor If the vehicle feels 'stuck' with only a single distance sensor pointing forwards, this is probably because the guidance cannot safely adapt the direction due to lack of information. ::: -## PX4 Distance Sensor {#rangefinder} +### Parameters -### Lanbao PSK-CM8JL65-CC5 +All relevant parameters are listed below: -At time of writing PX4 allows you to use the [Lanbao PSK-CM8JL65-CC5](../sensor/cm8jl65_ir_distance_sensor.md) IR distance sensor for collision prevention "out of the box", with minimal additional configuration: +| Parameter | Description | +| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [CP_DIST](../advanced_config/parameter_reference.md#CP_DIST) | Minimum allowed distance from the sensor (the closest distance that the vehicle can approach the obstacle). Set negative to _disable_ collision prevention. | +| [CP_DELAY](../advanced_config/parameter_reference.md#CP_DELAY) | Sensor and velocity setpoint tracking delay. See [Delay Tuning](#delay_tuning) below. | +| [CP_GUIDE_ANG](../advanced_config/parameter_reference.md#CP_GUIDE_ANG) | Angle (to both sides of the commanded direction) within which the vehicle may deviate if it finds fewer obstacles in that direction. See [Guidance Tuning](#angle_change_tuning) below. | +| [CP_GO_NO_DATA](../advanced_config/parameter_reference.md#CP_GO_NO_DATA) | Set to `1` to allow the vehicle to move in directions where there is no sensor coverage (default is 0/`False`). | +| [MPC_POS_MODE](../advanced_config/parameter_reference.md#MPC_POS_MODE) | Set to `Acceleration based` (default). Collision prevention is disabled for `Direct velocity` and `Smoothed velocity`. | -- First [attach and configure the sensor](../sensor/cm8jl65_ir_distance_sensor.md), and enable collision prevention (as described above, using [CP_DIST](#CP_DIST)). -- Set the sensor orientation using [SENS_CM8JL65_R_0](../advanced_config/parameter_reference.md#SENS_CM8JL65_R_0). +## Algorithm Description -### LightWare LiDAR SF45 Rotating Lidar +The data from all sensors are fused into an internal representation of 72 sectors around the vehicle, each containing either the sensor data and information about when it was last observed, or an indication that no data for the sector was available. +When the vehicle is commanded to move in a particular direction, all sectors in the hemisphere of that direction are checked to see if the movement will bring the vehicle closer than allowed to any obstacles. If so, the vehicle velocity is restricted. -PX4 v1.14 (and later) supports the [LightWare LiDAR SF45](https://www.lightwarelidar.com/shop/sf45-b-50-m/) rotating lidar which provides 320 degree sensing. +The Algorithm then can be split intwo two parts, the constraining of the acceleration setpoint coming from the operator, and the compensation of the current velocity of the vehicle. -The SF45 must be connected via a UART/serial port and configured as described below (In addition to the [collision prevention setup](#px4-software-setup)). +::: info +If there is no sensor data in a particular direction, movement in that direction is restricted to 0 (preventing the vehicle from crashing into unseen objects). +If you wish to move freely into directions without sensor coverage, this can be enabled by setting [CP_GO_NO_DATA](#CP_GO_NO_DATA) to 1. +::: -[LightWare Studio](https://www.lightwarelidar.com/resources-software) configuration: +### Acceleration Constraining -- In the LightWare Studio app enable scanning, set the scan angle, and change the baud rate to `921600`. +For this we split out Acceleration Setpoint into two components, one parallel to the closest distance to the obstacle and one normal to it. Then we scale each of these components according the the figure below. +![Scalefactor](../../assets/computer_vision/collision_prevention/scalefactor.png) -PX4 Configuration: + -- Add the [lightware_sf45_serial](../modules/modules_driver_distance_sensor.md#lightware-sf45-serial) driver in [menuconfig](../hardware/porting_guide_config.md#px4-menuconfig-setup): - - Under **drivers > Distance sensors** select `lightware_sf45_serial`. - - Recompile and upload to the flight controller. -- [Set the following parameters](../advanced_config/parameters.md) via QGC: - - [SENS_EN_SF45_CFG](../advanced_config/parameter_reference.md#SENS_EN_SF45_CFG): Set to the serial port you have the sensor connected to. - Make sure GPS or Telemetry are not enabled on this port. - - [SF45_ORIENT_CFG](../advanced_config/parameter_reference.md#SF45_ORIENT_CFG): Set the orientation of the sensor (facing up or down) - - [SF45_UPDATE_CFG](../advanced_config/parameter_reference.md#SF45_UPDATE_CFG): Set the update rate - - [SF45_YAW_CFG](../advanced_config/parameter_reference.md#SF45_YAW_CFG): Set the yaw orientation +### Velocity compensation -In QGroundControl you should see an [OBSTACLE_DISTANCE](https://mavlink.io/en/messages/common.html#OBSTACLE_DISTANCE) message in the [MAVLink console](../debug/mavlink_shell.md#qgroundcontrol-mavlink-console) if collision prevention is configured correctly and active. +This velocity restriction takes into account the [jerk-optimal velocity controller](../config_mc/mc_jerk_limited_type_trajectory.md) via [MPC_JERK_MAX](../advanced_config/parameter_reference.md#MPC_JERK_MAX) and [MPC_ACC_HOR](../advanced_config/parameter_reference.md#MPC_ACC_HOR). Whereby +The current velocity is compared with the maximum allowed velocity so that we are still able to break based on the maximal allowed jerk, acceleration and delay. from this we are able to use the proportional gain of the acceleration controller([MPC_XY_VEL_P_ACC](../advanced_config/parameter_reference.md#MPC_XY_VEL_P_ACC)) to transform it into an acceleration. -The obstacle overlay in QGC will look like this: +### Delay -![sf45](../../assets/sf45/sf45_obstacle_map.png) +The delay associated with collision prevention, both in the vehicle tracking velocity setpoints and in receiving sensor data from external sources, is conservatively estimated via the [CP_DELAY](#CP_DELAY) parameter. +This should be [tuned](#delay_tuning) to the specific vehicle. -### Rangefinder Support +If the sectors adjacent to the commanded sectors are 'better' by a significant margin, the direction of the requested input can be modified by up to the angle specified in [CP_GUIDE_ANG](#CP_GUIDE_ANG). +This helps to fine-tune user input to 'guide' the vehicle around obstacles rather than getting stuck against them. -Other sensors may be enabled, but this requires modification of driver code to set the sensor orientation and field of view. +### Range Data Loss -- Attach and configure the distance sensor on a particular port (see [sensor-specific docs](../sensor/rangefinders.md)) and enable collision prevention using [CP_DIST](#CP_DIST). -- Modify the driver to set the orientation. - This should be done by mimicking the `SENS_CM8JL65_R_0` parameter (though you might also hard-code the orientation in the sensor _module.yaml_ file to something like `sf0x start -d ${SERIAL_DEV} -R 25` - where 25 is equivalent to `ROTATION_DOWNWARD_FACING`). -- Modify the driver to set the _field of view_ in the distance sensor UORB topic (`distance_sensor_s.h_fov`). +If the autopilot does not receive range data from any sensor for longer than 0.5s, it will output a warning _No range data received, no movement allowed_. +This will force the velocity setpoints in xy to zero. +After 5 seconds of not receiving any data, the vehicle will switch into [HOLD mode](../flight_modes_mc/hold.md). +If you want the vehicle to be able to move again, you will need to disable Collision Prevention by either setting the parameter [CP_DIST](#CP_DIST) to a negative value, or switching to a mode other than [Position mode](../flight_modes_mc/position.md) (e.g. to _Altitude mode_ or _Stabilized mode_). -:::tip -You can see the required modifications from the [feature PR](https://github.com/PX4/PX4-Autopilot/pull/12179). -Please contribute back your changes! +If you have multiple sensors connected and you lose connection to one of them, you will still be able to fly inside the field of view (FOV) of the reporting sensors. +The data of the faulty sensor will expire and the region covered by this sensor will be treated as uncovered, meaning you will not be able to move there. + +:::warning +Be careful when enabling [CP_GO_NO_DATA=1](#CP_GO_NO_DATA), which allows the vehicle to fly outside the area with sensor coverage. +If you lose connection to one of multiple sensors, the area covered by the faulty sensor is also treated as uncovered and you will be able to move there without constraint. ::: ## Companion Setup {#companion} +::: warning +The companion implementation/setup is currently untested (the original companion project was unmaintained and has been archived). +::: + If using a companion computer or external sensor, it needs to supply a stream of [OBSTACLE_DISTANCE](https://mavlink.io/en/messages/common.html#OBSTACLE_DISTANCE) messages, which should reflect when and where obstacle were detected. The minimum rate at which messages _must_ be sent depends on vehicle speed - at higher rates the vehicle will have a longer time to respond to detected obstacles. - -::: info Initial testing of the system used a vehicle moving at 4 m/s with `OBSTACLE_DISTANCE` messages being emitted at 10Hz (the maximum rate supported by the vision system). The system may work well at significantly higher speeds and lower frequency distance updates. -::: - -The tested companion software is the _local_planner_ from the [PX4/PX4-Avoidance](https://github.com/PX4/PX4-Avoidance) repo. -For more information on hardware and software setup see: [PX4/PX4-Avoidance > Run on Hardware](https://github.com/PX4/PX4-Avoidance#run-on-hardware). - - - -The hardware and software should be set up as described in the [PX4/PX4-Avoidance](https://github.com/PX4/PX4-Avoidance) repo. -In order to emit `OBSTACLE_DISTANCE` messages you must use the _rqt_reconfigure_ tool and set the parameter `send_obstacles_fcu` to true. ## Gazebo Simulation @@ -196,10 +209,70 @@ make px4_sitl gz_x500_lidar_2d Next, adjust the relevant parameters to the appropriate values and add arbitrary obstacles to your simulation world to test the collision prevention functionality. -The diagram below shows how the simulation looks when viewed in Gazebo. +The diagram below shows a simulation of collision prevention as viewed in Gazebo. ![RViz image of collision detection using the x500_lidar_2d model in Gazebo](../../assets/simulation/gazebo/vehicles/x500_lidar_2d_viz.png) - - - +## Sensor Data Overview (Implementation Details) + +Collision Prevention has an internal obstacle distance map that divides the plane around the drone into 72 Sectors. +Internally this information is stored in the [`obstacle_distance`](../msg_docs/ObstacleDistance.md) UORB topic. +New sensor data is compared to the existing map, and used to update any sections that has changed. + +The angles in the `obstacle_distance` topic are defined as follows: + +![Obstacle_Distance Angles](../../assets/computer_vision/collision_prevention/obstacle_distance_def.svg) + +The data from rangefinders, rotary lidars, or companion computers, is processed differently, as described below. + +### Rotary Lidars + +Rotary Lidars add their data directly to the [`obstacle_distance`](../msg_docs/ObstacleDistance.md) uORB topic. + +### Rangefinders + +Rangefinders publish their data to the [`distance_sensor`](../msg_docs/DistanceSensor.md) uORB topic. + +This data is then mapped onto the `obstacle_distance` topic. +All sectors which have any overlap with the orientation (`orientation` and `q`) of the rangefinder, and the horizontal field of view (`h_fov`) are assigned that measurement value. +For example, a distance sensor measuring from 9.99° to 10.01° the measurements will get added to the bin's corresponding to 5° and 10° covering the arc from 2.5° and 12.5° + +::: info +the quaternion `q` is only used if the `orientation` is set to `ROTATION_CUSTOM`. +::: + +### Companion Computers + +Companion computers update the `obstacle_distance` topic using ROS2 or the [OBSTACLE_DISTANCE](https://mavlink.io/en/messages/common.html#OBSTACLE_DISTANCE) MAVLink message. + + + + diff --git a/en/computer_vision/index.md b/en/computer_vision/index.md index fc702d0e5740..85fd005663c9 100644 --- a/en/computer_vision/index.md +++ b/en/computer_vision/index.md @@ -11,7 +11,7 @@ PX4 uses computer vision systems (primarily running on [Companion Computers](../ - [Visual Inertial Odometry (VIO)](../computer_vision/visual_inertial_odometry.md) provides 3D pose and velocity estimation using an onboard vision system and IMU. It is used for navigation when global position information is absent or unreliable. - Avoidance/Path Planning: - - [Collision Prevention](../computer_vision/collision_prevention.md) is used to stop vehicles before they can crash into an obstacle (primarily when flying in manual modes). + - [Collision Prevention](../computer_vision/collision_prevention.md) is used to stop MC vehicles before they can crash into an obstacle (primarily when flying in manual modes). :::tip The [PX4 Vision Autonomy Development Kit](../complete_vehicles_mc/px4_vision_kit.md) (Holybro) is a robust and inexpensive kit for developers working with computer vision on PX4. diff --git a/en/features_mc/index.md b/en/features_mc/index.md index 004d0b5a5e83..cc959a429a54 100644 --- a/en/features_mc/index.md +++ b/en/features_mc/index.md @@ -3,6 +3,7 @@ This section lists features that are specific to (or customised for) multicopters: - [Flight Modes](../flight_modes_mc/index.md) +- [Collision Prevention](../computer_vision/collision_prevention.md) - [Precision Landing](../advanced_features/precland.md) - [Terrain Following/Holding](../flying/terrain_following_holding.md) - [Throw Launch](../flight_modes_mc/throw_launch.md) diff --git a/en/releases/main.md b/en/releases/main.md index fe897c59acef..31c8fa5f061c 100644 --- a/en/releases/main.md +++ b/en/releases/main.md @@ -75,6 +75,7 @@ Please continue reading for [upgrade instructions](#upgrade-guide). ### Multi-Rotor - Allow system-default [multicopter orbit mode](../flight_modes_mc/orbit.md) yaw behaviour to be configured, using the parameter [MC_ORBIT_YAW_MOD](../advanced_config/parameter_reference.md#MC_ORBIT_YAW_MOD) ([PX4-Autopilot#23358](https://github.com/PX4/PX4-Autopilot/pull/23358)) +- Adapted the [Collision Prevention](../computer_vision/collision_prevention.md) implementation to work in the default manual flight mode (Acceleration Based) [MPC_POS_MODE](../advanced_config/parameter_reference.md#MPC_POS_MODE). ([PX4-Autopilot#23507](https://github.com/PX4/PX4-Autopilot/pull/23507) ### VTOL