mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 22:53:34 +08:00
Collision Prevention: Scale obstacle distance with vehicle attitude for varying sensor orientations (#24107)
This commit is contained in:
@@ -400,11 +400,15 @@ CollisionPrevention::_addDistanceSensorData(distance_sensor_s &distance_sensor,
|
|||||||
int lower_bound = (int)round((sensor_yaw_body_deg - math::degrees(distance_sensor.h_fov / 2.0f)) / BIN_SIZE);
|
int lower_bound = (int)round((sensor_yaw_body_deg - math::degrees(distance_sensor.h_fov / 2.0f)) / BIN_SIZE);
|
||||||
int upper_bound = (int)round((sensor_yaw_body_deg + math::degrees(distance_sensor.h_fov / 2.0f)) / BIN_SIZE);
|
int upper_bound = (int)round((sensor_yaw_body_deg + math::degrees(distance_sensor.h_fov / 2.0f)) / BIN_SIZE);
|
||||||
|
|
||||||
|
const Quatf q_sensor(Quatf(cosf(sensor_yaw_body_rad / 2.f), 0.f, 0.f, sinf(sensor_yaw_body_rad / 2.f)));
|
||||||
|
|
||||||
// rotate vehicle attitude into the sensor body frame
|
const Vector3f forward_vector(1.0f, 0.0f, 0.0f);
|
||||||
Quatf attitude_sensor_frame = vehicle_attitude;
|
|
||||||
attitude_sensor_frame.rotate(Vector3f(0.f, 0.f, sensor_yaw_body_rad));
|
const Quatf q_sensor_rotation = vehicle_attitude * q_sensor;
|
||||||
float sensor_dist_scale = cosf(Eulerf(attitude_sensor_frame).theta()); // verify
|
|
||||||
|
const Vector3f rotated_sensor_vector = q_sensor_rotation.rotateVector(forward_vector);
|
||||||
|
|
||||||
|
const float sensor_dist_scale = rotated_sensor_vector.xy().norm();
|
||||||
|
|
||||||
if (distance_reading < distance_sensor.max_distance) {
|
if (distance_reading < distance_sensor.max_distance) {
|
||||||
distance_reading = distance_reading * sensor_dist_scale;
|
distance_reading = distance_reading * sensor_dist_scale;
|
||||||
|
|||||||
@@ -800,7 +800,10 @@ void GZBridge::laserScantoLidarSensorCallback(const gz::msgs::LaserScan &scan)
|
|||||||
pose_orientation.y(),
|
pose_orientation.y(),
|
||||||
pose_orientation.z());
|
pose_orientation.z());
|
||||||
|
|
||||||
|
const gz::math::Quaterniond q_left(0.7071068, 0, 0, -0.7071068);
|
||||||
|
|
||||||
const gz::math::Quaterniond q_front(0.7071068, 0.7071068, 0, 0);
|
const gz::math::Quaterniond q_front(0.7071068, 0.7071068, 0, 0);
|
||||||
|
|
||||||
const gz::math::Quaterniond q_down(0, 1, 0, 0);
|
const gz::math::Quaterniond q_down(0, 1, 0, 0);
|
||||||
|
|
||||||
if (q_sensor.Equal(q_front, 0.03)) {
|
if (q_sensor.Equal(q_front, 0.03)) {
|
||||||
@@ -809,8 +812,15 @@ void GZBridge::laserScantoLidarSensorCallback(const gz::msgs::LaserScan &scan)
|
|||||||
} else if (q_sensor.Equal(q_down, 0.03)) {
|
} else if (q_sensor.Equal(q_down, 0.03)) {
|
||||||
distance_sensor.orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
distance_sensor.orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||||
|
|
||||||
|
} else if (q_sensor.Equal(q_left, 0.03)) {
|
||||||
|
distance_sensor.orientation = distance_sensor_s::ROTATION_LEFT_FACING;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
distance_sensor.orientation = distance_sensor_s::ROTATION_CUSTOM;
|
distance_sensor.orientation = distance_sensor_s::ROTATION_CUSTOM;
|
||||||
|
distance_sensor.q[0] = q_sensor.W();
|
||||||
|
distance_sensor.q[1] = q_sensor.X();
|
||||||
|
distance_sensor.q[2] = q_sensor.Y();
|
||||||
|
distance_sensor.q[3] = q_sensor.Z();
|
||||||
}
|
}
|
||||||
|
|
||||||
_distance_sensor_pub.publish(distance_sensor);
|
_distance_sensor_pub.publish(distance_sensor);
|
||||||
|
|||||||
Reference in New Issue
Block a user