Skip to content

Commit

Permalink
switched to resolution of 5 degrees, and adapted tests to reflect the…
Browse files Browse the repository at this point in the history
… change
  • Loading branch information
Claudio-Chies committed Nov 14, 2024
1 parent 3a52a6e commit efb2015
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 95 deletions.
15 changes: 6 additions & 9 deletions src/lib/collision_prevention/CollisionPrevention.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void CollisionPrevention::_updateObstacleMap()
}

// publish fused obtacle distance message with data from offboard obstacle_distance and distance sensor
_obstacle_distance_pub.publish(_obstacle_map_body_frame);
_obstacle_distance_fused_pub.publish(_obstacle_map_body_frame);
}

void CollisionPrevention::_updateObstacleData()
Expand Down Expand Up @@ -228,6 +228,7 @@ void CollisionPrevention::_calculateConstrainedSetpoint(Vector2f &setpoint_accel
}
}

// TODO this gives false output if the offset is not a multiple of the resolution. to be fixed...
void CollisionPrevention::_addObstacleSensorData(const obstacle_distance_s &obstacle, const float vehicle_yaw)
{
int msg_index = 0;
Expand All @@ -239,7 +240,7 @@ void CollisionPrevention::_addObstacleSensorData(const obstacle_distance_s &obst
// corresponding data index (convert to world frame and shift by msg offset)
for (int i = 0; i < BIN_COUNT; i++) {
float bin_angle_deg = (float)i * BIN_SIZE + _obstacle_map_body_frame.angle_offset;
msg_index = ceil(_wrap_360(vehicle_orientation_deg + bin_angle_deg - obstacle.angle_offset) * increment_factor);
msg_index = round(_wrap_360(vehicle_orientation_deg + bin_angle_deg - obstacle.angle_offset) * increment_factor);

//add all data points inside to FOV
if (obstacle.distances[msg_index] != UINT16_MAX) {
Expand Down Expand Up @@ -357,18 +358,14 @@ CollisionPrevention::_addDistanceSensorData(distance_sensor_s &distance_sensor,
float sensor_yaw_body_deg = math::degrees(wrap_2pi(sensor_yaw_body_rad));

// calculate the field of view boundary bin indices
int lower_bound = (int)floor((sensor_yaw_body_deg - math::degrees(distance_sensor.h_fov / 2.0f)) / BIN_SIZE);
int upper_bound = (int)floor((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);

// floor values above zero, ceil values below zero
if (lower_bound < 0) { lower_bound++; }

if (upper_bound < 0) { upper_bound++; }

// rotate vehicle attitude into the sensor body frame
Quatf attitude_sensor_frame = vehicle_attitude;
attitude_sensor_frame.rotate(Vector3f(0.f, 0.f, sensor_yaw_body_rad));
float sensor_dist_scale = cosf(Eulerf(attitude_sensor_frame).theta());
float sensor_dist_scale = cosf(Eulerf(attitude_sensor_frame).theta()); // verify

if (distance_reading < distance_sensor.max_distance) {
distance_reading = distance_reading * sensor_dist_scale;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/collision_prevention/CollisionPrevention.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class CollisionPrevention : public ModuleParams
*/
void modifySetpoint(matrix::Vector2f &setpoint_accel, const matrix::Vector2f &setpoint_vel);

static constexpr int BIN_COUNT = 72;
static constexpr int BIN_SIZE = 360 / BIN_COUNT; // cannot be lower than 5 degrees, should divide 360 evenly

protected:
/** Aggregates the sensor data into an internal obstacle map in body frame */
void _updateObstacleMap();
Expand All @@ -90,9 +93,6 @@ class CollisionPrevention : public ModuleParams
/** Calculate the constrained setpoint considering the current obstacle distances, acceleration setpoint and velocity setpoint */
void _calculateConstrainedSetpoint(matrix::Vector2f &setpoint_accel, const matrix::Vector2f &setpoint_vel);

static constexpr int BIN_COUNT = 36;
static constexpr int BIN_SIZE = 360 / BIN_COUNT; // cannot be lower than 5 degrees, should divide 360 evenly

obstacle_distance_s _obstacle_map_body_frame{};
bool _data_fov[BIN_COUNT] {};
uint64_t _data_timestamps[BIN_COUNT] {};
Expand Down Expand Up @@ -179,7 +179,7 @@ class CollisionPrevention : public ModuleParams
float _vehicle_yaw{0.f};

uORB::Publication<collision_constraints_s> _constraints_pub{ORB_ID(collision_constraints)}; /**< constraints publication */
uORB::Publication<obstacle_distance_s> _obstacle_distance_pub{ORB_ID(obstacle_distance_fused)}; /**< obstacle_distance publication */
uORB::Publication<obstacle_distance_s> _obstacle_distance_fused_pub{ORB_ID(obstacle_distance_fused)}; /**< obstacle_distance publication */
uORB::Publication<vehicle_command_s> _vehicle_command_pub{ORB_ID(vehicle_command)}; /**< vehicle command do publication */

uORB::SubscriptionData<obstacle_distance_s> _sub_obstacle_distance{ORB_ID(obstacle_distance)}; /**< obstacle distances received form a range sensor */
Expand Down
Loading

0 comments on commit efb2015

Please sign in to comment.