PX4 Firmware
PX4 Autopilot Software http://px4.io
|
#include <CollisionPrevention.hpp>
Public Member Functions | |
CollisionPrevention (ModuleParams *parent) | |
virtual | ~CollisionPrevention () |
bool | is_active () |
Returs true if Collision Prevention is running. More... | |
void | modifySetpoint (matrix::Vector2f &original_setpoint, const float max_speed, const matrix::Vector2f &curr_pos, const matrix::Vector2f &curr_vel) |
Computes collision free setpoints. More... | |
Protected Member Functions | |
void | _addDistanceSensorData (distance_sensor_s &distance_sensor, const matrix::Quatf &vehicle_attitude) |
void | _addObstacleSensorData (const obstacle_distance_s &obstacle, const matrix::Quatf &vehicle_attitude) |
Updates obstacle distance message with measurement from offboard. More... | |
void | _adaptSetpointDirection (matrix::Vector2f &setpoint_dir, int &setpoint_index, float vehicle_yaw_angle_rad) |
Computes an adaption to the setpoint direction to guide towards free space. More... | |
bool | _enterData (int map_index, float sensor_range, float sensor_reading) |
Determines whether a new sensor measurement is used. More... | |
virtual hrt_abstime | getTime () |
virtual hrt_abstime | getElapsedTime (const hrt_abstime *ptr) |
Protected Attributes | |
obstacle_distance_s | _obstacle_map_body_frame {} |
uint64_t | _data_timestamps [sizeof(_obstacle_map_body_frame.distances)/sizeof(_obstacle_map_body_frame.distances[0])] |
uint16_t | _data_maxranges [sizeof(_obstacle_map_body_frame.distances)/sizeof(_obstacle_map_body_frame.distances[0])] |
in cm More... | |
Private Member Functions | |
DEFINE_PARAMETERS ((ParamFloat< px4::params::CP_DIST >) _param_cp_dist,(ParamFloat< px4::params::CP_DELAY >) _param_cp_delay,(ParamFloat< px4::params::CP_GUIDE_ANG >) _param_cp_guide_ang,(ParamFloat< px4::params::CP_GO_NO_DATA >) _param_cp_go_nodata,(ParamFloat< px4::params::MPC_XY_P >) _param_mpc_xy_p,(ParamFloat< px4::params::MPC_JERK_MAX >) _param_mpc_jerk_max,(ParamFloat< px4::params::MPC_ACC_HOR >) _param_mpc_acc_hor) float _sensorOrientationToYawOffset(const distance_sensor_s &distance_sensor | |
Transforms the sensor orientation into a yaw in the local frame. More... | |
void | _calculateConstrainedSetpoint (matrix::Vector2f &setpoint, const matrix::Vector2f &curr_pos, const matrix::Vector2f &curr_vel) |
Computes collision free setpoints. More... | |
void | _publishConstrainedSetpoint (const matrix::Vector2f &original_setpoint, const matrix::Vector2f &adapted_setpoint) |
Publishes collision_constraints message. More... | |
void | _publishObstacleDistance (obstacle_distance_s &obstacle) |
Publishes obstacle_distance message with fused data from offboard and from distance sensors. More... | |
void | _updateObstacleMap () |
Aggregates the sensor data into a internal obstacle map in body frame. More... | |
void | _publishVehicleCmdDoLoiter () |
Publishes vehicle command. More... | |
Private Attributes | |
bool | _interfering {false} |
states if the collision prevention interferes with the user input More... | |
bool | _was_active {false} |
states if the collision prevention interferes with the user input More... | |
orb_advert_t | _mavlink_log_pub {nullptr} |
Mavlink log uORB handle. More... | |
uORB::Publication< collision_constraints_s > | _constraints_pub {ORB_ID(collision_constraints)} |
constraints publication More... | |
uORB::Publication< obstacle_distance_s > | _obstacle_distance_pub {ORB_ID(obstacle_distance_fused)} |
obstacle_distance publication More... | |
uORB::PublicationQueued< vehicle_command_s > | _vehicle_command_pub {ORB_ID(vehicle_command)} |
vehicle command do publication More... | |
uORB::SubscriptionData< obstacle_distance_s > | _sub_obstacle_distance {ORB_ID(obstacle_distance)} |
obstacle distances received form a range sensor More... | |
uORB::Subscription | _sub_distance_sensor [ORB_MULTI_MAX_INSTANCES] {{ORB_ID(distance_sensor), 0}, {ORB_ID(distance_sensor), 1}, {ORB_ID(distance_sensor), 2}, {ORB_ID(distance_sensor), 3}} |
distance data received from onboard rangefinders More... | |
uORB::SubscriptionData< vehicle_attitude_s > | _sub_vehicle_attitude {ORB_ID(vehicle_attitude)} |
hrt_abstime | _last_collision_warning {0} |
hrt_abstime | _last_timeout_warning {0} |
hrt_abstime | _time_activated {0} |
float angle_offset | const |
Static Private Attributes | |
static constexpr uint64_t | RANGE_STREAM_TIMEOUT_US {500_ms} |
static constexpr uint64_t | TIMEOUT_HOLD_US {5_s} |
Definition at line 64 of file CollisionPrevention.hpp.
CollisionPrevention::CollisionPrevention | ( | ModuleParams * | parent | ) |
Definition at line 68 of file CollisionPrevention.cpp.
References _data_maxranges, _data_timestamps, _obstacle_map_body_frame, obstacle_distance_s::angle_offset, obstacle_distance_s::distances, getTime(), obstacle_distance_s::increment, obstacle_distance_s::max_distance, obstacle_distance_s::min_distance, and obstacle_distance_s::timestamp.
|
virtual |
Definition at line 90 of file CollisionPrevention.cpp.
References _mavlink_log_pub, and orb_unadvertise().
|
protected |
Computes an adaption to the setpoint direction to guide towards free space.
setpoint_dir,setpoint | direction before collision prevention intervention |
setpoint_index,index | of the setpoint in the internal obstacle map |
vehicle_yaw_angle_rad,vehicle | orientation |
Definition at line 298 of file CollisionPrevention.cpp.
References _obstacle_map_body_frame, matrix::abs(), obstacle_distance_s::angle_offset, obstacle_distance_s::distances, matrix::floor(), M_PI_F, distance_sensor_s::orientation, distance_sensor_s::q, math::radians(), ROTATION_YAW_135, ROTATION_YAW_180, ROTATION_YAW_225, ROTATION_YAW_270, ROTATION_YAW_315, ROTATION_YAW_45, ROTATION_YAW_90, and matrix::wrap_2pi().
Referenced by _calculateConstrainedSetpoint().
|
protected |
Definition at line 252 of file CollisionPrevention.cpp.
References _data_maxranges, _data_timestamps, _enterData(), _obstacle_map_body_frame, obstacle_distance_s::angle_offset, distance_sensor_s::current_distance, math::degrees(), obstacle_distance_s::distances, f(), matrix::floor(), distance_sensor_s::h_fov, distance_sensor_s::max_distance, math::min(), distance_sensor_s::min_distance, matrix::Quaternion< Type >::rotate(), obstacle_distance_s::timestamp, and matrix::wrap_2pi().
Referenced by _updateObstacleMap().
|
protected |
Updates obstacle distance message with measurement from offboard.
obstacle,obstacle_distance | message to be updated |
Definition at line 121 of file CollisionPrevention.cpp.
References _data_maxranges, _data_timestamps, _enterData(), _mavlink_log_pub, _obstacle_map_body_frame, obstacle_distance_s::angle_offset, matrix::ceil(), math::degrees(), obstacle_distance_s::distances, obstacle_distance_s::frame, obstacle_distance_s::increment, mavlink_log_critical, obstacle_distance_s::max_distance, and obstacle_distance_s::timestamp.
Referenced by _updateObstacleMap().
|
private |
Computes collision free setpoints.
setpoint,setpoint | before collision prevention intervention |
curr_pos,current | vehicle position |
curr_vel,current | vehicle velocity |
Definition at line 390 of file CollisionPrevention.cpp.
References _adaptSetpointDirection(), _data_maxranges, _data_timestamps, _last_timeout_warning, _mavlink_log_pub, _obstacle_map_body_frame, _publishVehicleCmdDoLoiter(), _sub_vehicle_attitude, _time_activated, _updateObstacleMap(), obstacle_distance_s::angle_offset, attitude, math::trajectory::computeMaxSpeedFromDistance(), math::degrees(), obstacle_distance_s::distances, matrix::Vector< Type, M >::dot(), f(), matrix::floor(), uORB::SubscriptionData< T >::get(), getElapsedTime(), getTime(), hrt_abstime, mavlink_log_critical, math::max(), math::min(), obstacle_distance_s::min_distance, matrix::Vector< Type, M >::norm(), vehicle_attitude_s::q, math::radians(), RANGE_STREAM_TIMEOUT_US, TIMEOUT_HOLD_US, obstacle_distance_s::timestamp, and matrix::wrap_2pi().
Referenced by modifySetpoint().
|
protected |
Determines whether a new sensor measurement is used.
map_index,index | of the bin in the internal map the measurement belongs in |
sensor_range,max | range of the sensor in meters |
sensor_reading,distance | measurement in meters |
Definition at line 170 of file CollisionPrevention.cpp.
References _data_maxranges, _obstacle_map_body_frame, and obstacle_distance_s::distances.
Referenced by _addDistanceSensorData(), and _addObstacleSensorData().
|
private |
Publishes collision_constraints message.
original_setpoint,setpoint | before collision prevention intervention |
adapted_setpoint,collision | prevention adaped setpoint |
|
private |
Publishes obstacle_distance message with fused data from offboard and from distance sensors.
obstacle,obstacle_distance | message to be publsihed |
|
private |
Publishes vehicle command.
Definition at line 536 of file CollisionPrevention.cpp.
References _vehicle_command_pub, command, getTime(), uORB::PublicationQueued< T >::publish(), PX4_CUSTOM_MAIN_MODE_AUTO, and PX4_CUSTOM_SUB_MODE_AUTO_LOITER.
Referenced by _calculateConstrainedSetpoint().
|
private |
Aggregates the sensor data into a internal obstacle map in body frame.
Definition at line 202 of file CollisionPrevention.cpp.
References _addDistanceSensorData(), _addObstacleSensorData(), _obstacle_distance_pub, _obstacle_map_body_frame, _sub_distance_sensor, _sub_obstacle_distance, _sub_vehicle_attitude, uORB::Subscription::copy(), uORB::SubscriptionData< T >::get(), getElapsedTime(), obstacle_distance_s::increment, math::max(), obstacle_distance_s::max_distance, math::min(), obstacle_distance_s::min_distance, ORB_MULTI_MAX_INSTANCES, uORB::Publication< T >::publish(), vehicle_attitude_s::q, RANGE_STREAM_TIMEOUT_US, obstacle_distance_s::timestamp, and uORB::SubscriptionData< T >::update().
Referenced by _calculateConstrainedSetpoint().
|
private |
Transforms the sensor orientation into a yaw in the local frame.
distance_sensor,distance | sensor message |
angle_offset,sensor | body frame offset |
_param_cp_dist | collision prevention keep minimum distance |
_param_cp_delay | delay of the range measurement data |
_param_cp_guide_ang | collision prevention change setpoint angle |
_param_cp_go_nodata | movement allowed where no data |
_param_mpc_xy_p | p gain from position controller |
_param_mpc_jerk_max | vehicle maximum jerk |
_param_mpc_acc_hor | vehicle maximum horizontal acceleration |
|
protectedvirtual |
Reimplemented in TestTimingCollisionPrevention.
Definition at line 103 of file CollisionPrevention.cpp.
References hrt_absolute_time().
Referenced by _calculateConstrainedSetpoint(), _updateObstacleMap(), and modifySetpoint().
|
protectedvirtual |
Reimplemented in TestTimingCollisionPrevention.
Definition at line 98 of file CollisionPrevention.cpp.
References hrt_absolute_time().
Referenced by _calculateConstrainedSetpoint(), _publishVehicleCmdDoLoiter(), CollisionPrevention(), is_active(), and modifySetpoint().
bool CollisionPrevention::is_active | ( | ) |
Returs true if Collision Prevention is running.
Definition at line 108 of file CollisionPrevention.cpp.
References _time_activated, _was_active, and getTime().
Referenced by FlightTaskManualPosition::_scaleSticks(), and TEST_F().
void CollisionPrevention::modifySetpoint | ( | matrix::Vector2f & | original_setpoint, |
const float | max_speed, | ||
const matrix::Vector2f & | curr_pos, | ||
const matrix::Vector2f & | curr_vel | ||
) |
Computes collision free setpoints.
original_setpoint,setpoint | before collision prevention intervention |
max_speed,maximum | xy speed |
curr_pos,current | vehicle position |
curr_vel,current | vehicle velocity |
Definition at line 504 of file CollisionPrevention.cpp.
References _calculateConstrainedSetpoint(), _constraints_pub, _interfering, _last_collision_warning, _mavlink_log_pub, matrix::Matrix< Type, M, N >::copyTo(), getElapsedTime(), getTime(), mavlink_log_info, uORB::Publication< T >::publish(), and collision_constraints_s::timestamp.
Referenced by FlightTaskManualPosition::_scaleSticks(), and TEST_F().
|
private |
constraints publication
Definition at line 130 of file CollisionPrevention.hpp.
Referenced by modifySetpoint().
|
protected |
in cm
Definition at line 91 of file CollisionPrevention.hpp.
Referenced by _addDistanceSensorData(), _addObstacleSensorData(), _calculateConstrainedSetpoint(), _enterData(), and CollisionPrevention().
|
protected |
Definition at line 89 of file CollisionPrevention.hpp.
Referenced by _addDistanceSensorData(), _addObstacleSensorData(), _calculateConstrainedSetpoint(), and CollisionPrevention().
|
private |
states if the collision prevention interferes with the user input
Definition at line 125 of file CollisionPrevention.hpp.
Referenced by modifySetpoint().
|
private |
Definition at line 141 of file CollisionPrevention.hpp.
Referenced by modifySetpoint().
|
private |
Definition at line 142 of file CollisionPrevention.hpp.
Referenced by _calculateConstrainedSetpoint().
|
private |
Definition at line 128 of file CollisionPrevention.hpp.
Referenced by _addObstacleSensorData(), _calculateConstrainedSetpoint(), modifySetpoint(), and ~CollisionPrevention().
|
private |
obstacle_distance publication
Definition at line 131 of file CollisionPrevention.hpp.
Referenced by _updateObstacleMap().
|
protected |
Definition at line 88 of file CollisionPrevention.hpp.
Referenced by _adaptSetpointDirection(), _addDistanceSensorData(), _addObstacleSensorData(), _calculateConstrainedSetpoint(), _enterData(), _updateObstacleMap(), and CollisionPrevention().
|
private |
distance data received from onboard rangefinders
Definition at line 135 of file CollisionPrevention.hpp.
Referenced by _updateObstacleMap().
|
private |
obstacle distances received form a range sensor
Definition at line 134 of file CollisionPrevention.hpp.
Referenced by _updateObstacleMap().
|
private |
Definition at line 136 of file CollisionPrevention.hpp.
Referenced by _calculateConstrainedSetpoint(), and _updateObstacleMap().
|
private |
Definition at line 143 of file CollisionPrevention.hpp.
Referenced by _calculateConstrainedSetpoint(), and is_active().
|
private |
vehicle command do publication
Definition at line 132 of file CollisionPrevention.hpp.
Referenced by _publishVehicleCmdDoLoiter().
|
private |
states if the collision prevention interferes with the user input
Definition at line 126 of file CollisionPrevention.hpp.
Referenced by is_active().
|
private |
Definition at line 160 of file CollisionPrevention.hpp.
|
staticprivate |
Definition at line 138 of file CollisionPrevention.hpp.
Referenced by _calculateConstrainedSetpoint(), and _updateObstacleMap().
|
staticprivate |
Definition at line 139 of file CollisionPrevention.hpp.
Referenced by _calculateConstrainedSetpoint().