# 防撞功能

It can be enabled for multicopter vehicles in Position mode, and can use sensor data from an offboard companion computer, a rangefinder attached to the flight controller, or both (fused).

## 综述

The feature requires obstacle information from either an external system (sent using the MAVLink OBSTACLE_DISTANCE message) or a distance sensor connected to the flight controller.

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.

## PX4 (软件) 设置

Enabled collision prevention by setting the following parameter in QGroundControl:

• MPC_COL_PREV_D - 设置最小安全距离（飞机靠近障碍物的最小距离）。 设置为负值将禁用 防撞 功能。

调参应根据期望 的最小距离与飞机大致的速度。

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 the next section. If you are using a companion computer to provide obstacle information see companion setup.

## PX4 Distance Sensor

At time of writing PX4 allows you to use the Lanbao PSK-CM8JL65-CC5 IR distance sensor for collision prevention "out of the box", with minimal additional configuration:

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) and enable collision prevention using MPC_COL_PREV_D.
• 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).

You can see the required modifications from the feature PR. Please contribute back your changes!

## Companion Setup

If using a companion computer, it needs to supply a stream of OBSTACLE_DISTANCE messages when an obstacle is 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.

Initial testing of the system used a vehicle moving at 4 m/s with OBSTACLE_DISTANCE messages being emitted at 30Hz (the maximum rate supported by the vision system). The system may work well at significantly higher speeds and lower frequency distance updates.

The tested hardware/software platform is Auterion IF750A reference multicopter running the local_planner avoidance software from the PX4/avoidance repo.

The hardware and software should be set up as described in the 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设置

Collision Prevention can also be tested using Gazebo. See PX4/avoidance for setup instructions.

© PX4 Dev Team. License: CC BY 4.0            Updated: 2019-08-21 00:47:52