22 return 4 * area / (a * b * c);
26 std::vector<double> &velocities) {
27 for (
const auto &k : curvatures) {
42 std::vector<double> &velocities,
43 const std::vector<double> &curvatures) {
45 for (
int i = 1; i < (int)points.size(); i++) {
46 double dx = points[i].position.x - points[i - 1].position.x;
47 double dy = points[i].position.y - points[i - 1].position.y;
48 double d = std::sqrt(dx * dx + dy * dy);
51 double ay = std::min(velocities[i - 1] * velocities[i - 1] * std::abs(curvatures[i - 1]),
61 std::sqrt(std::max(0.0, velocities[i - 1] * velocities[i - 1] + 2 * ax_max * d));
62 velocities[i] = std::min(velocities[i], max_velocity);
67 std::vector<double> &velocities,
68 const std::vector<double> &curvatures) {
69 for (
int i =
static_cast<int>(points.size()) - 2; i >= 0; i--) {
72 double distance = std::hypot(points[j].position.x - points[i].position.x,
73 points[j].position.y - points[i].position.y);
77 double ay = std::min(velocities[j] * velocities[j] * std::abs(curvatures[j]),
90 std::sqrt(std::max(0.0, velocities[j] * velocities[j] + 2 * ax_brake * distance));
93 velocities[i] = std::min(max_speed, velocities[i]);
98 int path_size =
static_cast<int>(final_path.size());
101 for (
auto &p : final_path) {
107 std::vector<double> curvatures(path_size, 0.0);
108 for (
int i = 1; i < path_size - 1; ++i) {
109 curvatures[i] =
find_curvature(final_path[i - 1], final_path[i], final_path[i + 1]);
112 std::vector<double> velocities;
117 for (
int i = 0; i < path_size; ++i) {
120 final_path[i].ideal_velocity = velocities[i];
125 int path_size =
static_cast<int>(final_path.size());
127 for (
auto &p : final_path) {
134 std::vector<PathPoint> triple_path;
135 triple_path.reserve(3 * path_size);
136 for (
int lap = 0; lap < 3; ++lap) {
137 for (
int i = 0; i < path_size; ++i) {
138 triple_path.push_back(final_path[i]);
145 int offset = path_size;
146 for (
int i = 0; i < path_size; ++i) {
147 final_path[i].ideal_velocity = triple_path[offset + i].ideal_velocity;
152 int path_size = final_path.size();
153 if (path_size <= 3) {
154 for (
auto &p : final_path) {
157 RCLCPP_ERROR(rclcpp::get_logger(
"planning"),
"Not enough path point to do velocity profile.");
163 while (dist < braking_distance && index < path_size) {
164 dist += final_path[index].position.euclidean_distance(final_path[index - 1].position);
168 while (index <
static_cast<int>(path_size) - 1 && final_path[index].ideal_velocity > 0.0) {
172 double d = final_path[j].position.euclidean_distance(final_path[index].position);
174 double vi = final_path[index].ideal_velocity;
178 double ay = std::min(vi * vi *
180 final_path[index], final_path[j])),
184 double ax_available =
191 double vj = std::sqrt(std::max(0.0, vi * vi + 2.0 * ax_available * d));
192 vj = std::max(vj, 0.0);
194 final_path[j].ideal_velocity = std::min(final_path[j].ideal_velocity, vj);
199 while (index < path_size) {
200 final_path[index].ideal_velocity = 0.0;
static constexpr double epsilon
Numerical tolerance for floating-point comparisons.
void acceleration_limiter(const std::vector< PathPoint > &points, std::vector< double > &velocities, const std::vector< double > &curvatures)
Limits velocities based on forward acceleration constraints and friction ellipse.
double find_curvature(const PathPoint &p1, const PathPoint &p2, const PathPoint &p3)
Computes the curvature at a point using the Menger curvature formula.
void point_speed(const std::vector< double > &curvatures, std::vector< double > &velocities)
Computes the maximum velocity at each point based on curvature constraints.
void braking_limiter(std::vector< PathPoint > &points, std::vector< double > &velocities, const std::vector< double > &curvatures)
Limits velocities based on backward braking constraints and friction ellipse.
VelocityPlanningConfig config_
configuration of the velocity planning algorithm
void stop(std::vector< PathPoint > &final_path, double braking_distance)
Applies a braking velocity profile starting after a given braking distance.
void set_velocity(std::vector< PathPoint > &final_path)
Assigns an velocity to each point of the path.
void trackdrive_velocity(std::vector< PathPoint > &final_path)
Computes velocity for trackdrive scenarios.
double desired_velocity_
The desired velocity of the car.
bool use_velocity_planning_
Flag to enable/disable velocity planning.
double lateral_acceleration_
Maximum lateral acceleration.
double acceleration_
Maximum forward acceleration.
double longitudinal_acceleration_
Maximum longitudinal acceleration.
double braking_acceleration_
Maximum braking acceleration.
double minimum_velocity_
Minimum speed in the velocity planning.