Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit a8b2943

Browse files
committed
set the trajectory speed limit based on the distance to the goal
1 parent 8ae4077 commit a8b2943

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

local_planner/include/local_planner/local_planner.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ class LocalPlanner {
8888
**/
8989
void generateHistogramImage(Histogram& histogram);
9090

91+
/**
92+
* @brief compute the maximum speed allowed based on sensor range and vehicle tuning
93+
* @param jerk, vehicle maximum jerk
94+
* @param accel, vehicle maximum horizontal acceleration
95+
* @param braking_distance, maximum sensor range
96+
* @returns maximum speed
97+
**/
98+
float computeMaxSpeedFromBrakingDistance(const float jerk, const float accel, const float braking_distance) const;
99+
100+
/**
101+
* @brief compute if the cruise speed requested by paramters or mission item is feasible based on vehicle dynamics
102+
*and sesnor range
103+
* @param jerk, vehicle maximum jerk
104+
* @param accel, vehicle maximum horizontal acceleration
105+
* @param braking_distance, maximum sensor range
106+
* @param mpc_xy_cruise, desired speed set from parameter
107+
* @param mission_item_speed, desired speed set from mission item
108+
* @returns maximum speed
109+
**/
110+
float getMaxSpeed(const float jerk, const float accel, const float braking_distance, const float mpc_xy_cruise,
111+
const float mission_item_speed) const;
112+
91113
public:
92114
std::vector<uint8_t> histogram_image_data_;
93115
std::vector<uint8_t> cost_image_data_;

local_planner/src/nodes/local_planner.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ void LocalPlanner::determineStrategy() {
128128
simulation_limits lims;
129129
lims.max_z_velocity = px4_.param_mpc_z_vel_max_up;
130130
lims.min_z_velocity = -1.0f * px4_.param_mpc_z_vel_max_dn;
131-
lims.max_xy_velocity_norm = px4_.param_mpc_xy_cruise;
131+
lims.max_xy_velocity_norm =
132+
std::min(getMaxSpeed(px4_.param_mpc_jerk_max, px4_.param_mpc_acc_hor, max_sensor_range_,
133+
px4_.param_mpc_xy_cruise, mission_item_speed_),
134+
getMaxSpeed(px4_.param_mpc_jerk_max, px4_.param_mpc_acc_hor, (goal_ - position_).norm(),
135+
px4_.param_mpc_xy_cruise, mission_item_speed_));
132136
lims.max_acceleration_norm = px4_.param_mpc_acc_hor;
133137
lims.max_jerk_norm = px4_.param_mpc_jerk_max;
134138
star_planner_->setParams(cost_params_, lims, px4_.param_nav_acc_rad);
@@ -212,24 +216,32 @@ avoidanceOutput LocalPlanner::getAvoidanceOutput() const {
212216
out.waypoint_type = waypoint_type_;
213217
out.obstacle_ahead = !polar_histogram_.isEmpty();
214218

215-
// calculate maximum speed given the sensor range and vehicle parameters
216-
// quadratic solve of 0 = u^2 + 2as, with s = u * |a/j| + r
217-
// u = initial velocity, a = max acceleration
218-
// s = stopping distance under constant acceleration
219-
// j = maximum jerk, r = maximum range sensor distance
220-
float accel_ramp_time = px4_.param_mpc_acc_hor / px4_.param_mpc_jerk_max;
221-
float a = 1;
222-
float b = 2 * px4_.param_mpc_acc_hor * accel_ramp_time;
223-
float c = 2 * -px4_.param_mpc_acc_hor * max_sensor_range_;
224-
float limited_speed = (-b + std::sqrt(b * b - 4 * a * c)) / (2 * a);
225-
226-
float speed = std::isfinite(mission_item_speed_) ? mission_item_speed_ : px4_.param_mpc_xy_cruise;
227-
float max_speed = std::min(speed, limited_speed);
219+
float max_speed = getMaxSpeed(px4_.param_mpc_jerk_max, px4_.param_mpc_acc_hor, max_sensor_range_,
220+
px4_.param_mpc_xy_cruise, mission_item_speed_);
228221

229222
out.cruise_velocity = max_speed;
230223
out.last_path_time = last_path_time_;
231224
out.tree_node_duration = tree_node_duration_;
232225
out.path_node_setpoints = star_planner_->path_node_setpoints_;
233226
return out;
234227
}
228+
229+
float LocalPlanner::computeMaxSpeedFromBrakingDistance(const float jerk, const float accel,
230+
const float braking_distance) const {
231+
// Calculate maximum speed given the sensor range and vehicle parameters
232+
// We assume a constant acceleration profile with a delay of 2*accel/jerk (time to reach the desired acceleration from
233+
// opposite max acceleration)
234+
// Equation to solve: 0 = vel^2 - 2*acc*(x - vel*2*acc/jerk)
235+
float b = 4.f * accel * accel / jerk;
236+
float c = -2.f * accel * braking_distance;
237+
238+
return 0.5f * (-b + sqrtf(b * b - 4.f * c));
239+
}
240+
241+
float LocalPlanner::getMaxSpeed(const float jerk, const float accel, const float braking_distance,
242+
const float mpc_xy_cruise, const float mission_item_speed) const {
243+
float limited_speed = computeMaxSpeedFromBrakingDistance(jerk, accel, braking_distance);
244+
float speed = std::isfinite(mission_item_speed) ? mission_item_speed : mpc_xy_cruise;
245+
return std::min(speed, limited_speed);
246+
}
235247
}

local_planner/src/nodes/tree_node.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
namespace avoidance {
44

55
TreeNode::TreeNode(int from, const simulation_state& start_state, const Eigen::Vector3f& sp)
6-
: total_cost_{0.0f},
7-
heuristic_{0.0f},
8-
origin_{from},
9-
closed_{false},
10-
state(start_state),
11-
setpoint(sp) {}
6+
: total_cost_{0.0f}, heuristic_{0.0f}, origin_{from}, closed_{false}, state(start_state), setpoint(sp) {}
127

138
void TreeNode::setCosts(float h, float c) {
149
heuristic_ = h;

0 commit comments

Comments
 (0)