Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(autoware_map_based_prediction): replace pow #8751

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions perception/autoware_map_based_prediction/src/path_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,18 @@

path.reserve(static_cast<size_t>(duration / sampling_time_interval_));
for (double t = 0.0; t <= duration; t += sampling_time_interval_) {
const auto t2 = t * t;
const auto t3 = t2 * t;
const auto t4 = t3 * t;
const auto t5 = t4 * t;

Check warning on line 266 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L263-L266

Added lines #L263 - L266 were not covered by tests
const double current_acc =
0.0; // Currently we assume the object is traveling at a constant speed
const double d_next_ = current_point.d + current_point.d_vel * t +
current_acc * 2.0 * std::pow(t, 2) + lat_coeff(0) * std::pow(t, 3) +
lat_coeff(1) * std::pow(t, 4) + lat_coeff(2) * std::pow(t, 5);
const double d_next_ = current_point.d + current_point.d_vel * t + current_acc * 2.0 * t2 +
lat_coeff(0) * t3 + lat_coeff(1) * t4 + lat_coeff(2) * t5;

Check warning on line 270 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L269-L270

Added lines #L269 - L270 were not covered by tests
// t > lateral_duration: 0.0, else d_next_
const double d_next = t > lateral_duration ? 0.0 : d_next_;
const double s_next = current_point.s + current_point.s_vel * t +
2.0 * current_acc * std::pow(t, 2) + lon_coeff(0) * std::pow(t, 3) +
lon_coeff(1) * std::pow(t, 4);
const double s_next = current_point.s + current_point.s_vel * t + 2.0 * current_acc * t2 +
lon_coeff(0) * t3 + lon_coeff(1) * t4;

Check warning on line 274 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L273-L274

Added lines #L273 - L274 were not covered by tests
if (s_next > max_length) {
break;
}
Expand Down Expand Up @@ -302,10 +304,14 @@
// b = np.matrix([[xe - self.a0 - self.a1 * T - self.a2 * T**2],
// [vxe - self.a1 - 2 * self.a2 * T],
// [axe - 2 * self.a2]])
const auto T2 = T * T;
const auto T3 = T2 * T;
const auto T4 = T3 * T;
const auto T5 = T4 * T;

Check warning on line 310 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L307-L310

Added lines #L307 - L310 were not covered by tests

Eigen::Matrix3d A_lat_inv;
A_lat_inv << 10 / std::pow(T, 3), -4 / std::pow(T, 2), 1 / (2 * T), -15 / std::pow(T, 4),
7 / std::pow(T, 3), -1 / std::pow(T, 2), 6 / std::pow(T, 5), -3 / std::pow(T, 4),
1 / (2 * std::pow(T, 3));
A_lat_inv << 10 / T3, -4 / T2, 1 / (2 * T), -15 / T4, 7 / T3, -1 / T2, 6 / T5, -3 / T4,
1 / (2 * T3);

Check warning on line 314 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L313-L314

Added lines #L313 - L314 were not covered by tests
Eigen::Vector3d b_lat;
b_lat[0] = target_point.d - current_point.d - current_point.d_vel * T;
b_lat[1] = target_point.d_vel - current_point.d_vel;
Expand All @@ -323,9 +329,11 @@
// [-1/(2*T**3), 1/(4*T**2)]])
// b = np.matrix([[vxe - self.a1 - 2 * self.a2 * T],
// [axe - 2 * self.a2]])
const auto T2 = T * T;
const auto T3 = T2 * T;

Check warning on line 333 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L332-L333

Added lines #L332 - L333 were not covered by tests

Eigen::Matrix2d A_lon_inv;
A_lon_inv << 1 / std::pow(T, 2), -1 / (3 * T), -1 / (2 * std::pow(T, 3)),
1 / (4 * std::pow(T, 2));
A_lon_inv << 1 / T2, -1 / (3 * T), -1 / (2 * T3), 1 / (4 * T2);

Check warning on line 336 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L336

Added line #L336 was not covered by tests
Eigen::Vector2d b_lon;
b_lon[0] = target_point.s_vel - current_point.s_vel;
b_lon[1] = 0.0;
Expand Down Expand Up @@ -474,6 +482,8 @@
// Get velocity after time horizon
const auto terminal_velocity = v + a * (1.0 / lambda) * (1 - std::exp(-lambda * t_h));

const auto lambda_2 = lambda * lambda;

// If vehicle is decelerating, make sure its speed does not change signs (we assume it will, at
// most stop, not reverse its direction)
if (!have_same_sign(terminal_velocity, v)) {
Expand All @@ -489,8 +499,7 @@

// Calculate the distance traveled until stopping
auto distance_to_reach_zero_speed =
v * t_stop + a * t_stop * (1.0 / lambda) +
a * (1.0 / std::pow(lambda, 2)) * std::expm1(-lambda * t_h);
v * t_stop + a * t_stop * (1.0 / lambda) + a * (1.0 / lambda_2) * std::expm1(-lambda * t_h);

Check warning on line 502 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L502

Added line #L502 was not covered by tests
// Output an equivalent constant speed
return distance_to_reach_zero_speed / t_h;
}
Expand All @@ -500,7 +509,7 @@
// assume it will continue accelerating (reckless driving)
const bool object_has_surpassed_limit_already = v > speed_limit;
if (terminal_velocity < speed_limit || object_has_surpassed_limit_already)
return v + a * (1.0 / lambda) + (a / (t_h * std::pow(lambda, 2))) * std::expm1(-lambda * t_h);
return v + a * (1.0 / lambda) + (a / (t_h * lambda_2)) * std::expm1(-lambda * t_h);

Check warning on line 512 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L512

Added line #L512 was not covered by tests

// It is assumed the vehicle accelerates until final_speed is reached and
// then continues at constant speed for the rest of the time horizon
Expand All @@ -510,8 +519,7 @@
const double t_f = (-1.0 / lambda) * std::log(1 - ((speed_limit - v) * lambda) / a);
const double distance_covered =
// Distance covered while accelerating
a * (1.0 / lambda) * t_f + a * (1.0 / std::pow(lambda, 2)) * std::expm1(-lambda * t_f) +
v * t_f +
a * (1.0 / lambda) * t_f + a * (1.0 / lambda_2) * std::expm1(-lambda * t_f) + v * t_f +

Check warning on line 522 in perception/autoware_map_based_prediction/src/path_generator.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_map_based_prediction/src/path_generator.cpp#L522

Added line #L522 was not covered by tests
// Distance covered at constant speed for the rest of the horizon time
speed_limit * (t_h - t_f);
return distance_covered / t_h;
Expand Down
Loading