Skip to content

Commit 1cbbbc5

Browse files
authored
Merge pull request #1411 from tier4/RJD-1337/getQuadraticAccelerationDuration
RJD-1337 Fix getQuadraticAccelerationDuration returning negative duration
2 parents 842235e + 7ed87b4 commit 1cbbbc5

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

simulation/traffic_simulator/src/behavior/longitudinal_speed_planning.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ auto LongitudinalSpeedPlanner::getQuadraticAccelerationDuration(
194194
double v = getVelocityWithConstantJerk(
195195
current_twist, current_accel, constraints.max_acceleration_rate, duration);
196196
// While quadratic acceleration, the entity does not reached the target speed.
197-
if (std::abs(v - target_speed) >= 0.01) {
197+
if (v < target_speed) {
198198
return duration;
199199
}
200200
// While quadratic acceleration, the entity reached the target speed.
@@ -208,7 +208,7 @@ auto LongitudinalSpeedPlanner::getQuadraticAccelerationDuration(
208208
double v = getVelocityWithConstantJerk(
209209
current_twist, current_accel, -constraints.max_deceleration_rate, duration);
210210
// While quadratic acceleration, the entity does not reached the target speed.
211-
if (std::abs(v - target_speed) >= 0.01) {
211+
if (v < target_speed) {
212212
return duration;
213213
}
214214
// While quadratic acceleration, the entity reached the target speed.

simulation/traffic_simulator/test/src/behavior/test_longitudinal_speed_planner.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,49 @@ TEST_F(LongitudinalSpeedPlannerTest, getAccelerationDuration_acceleration)
121121
8.5, constraints, makeTwistWithLinearX(1.0), makeAccelWithLinearX(1.0)),
122122
4.0, 1e-5);
123123
}
124+
/**
125+
* @note Test calculations correctness when difference between getVelocityWithConstantJerk
126+
* and target_speed is more than 0.01, https://github.com/tier4/scenario_simulator_v2/issues/1395
127+
*/
128+
129+
TEST_F(LongitudinalSpeedPlannerTest, getAccelerationDuration_targetSpeed_difference)
130+
{
131+
geometry_msgs::msg::Twist current_twist{};
132+
geometry_msgs::msg::Accel current_accel{};
133+
current_twist.linear.x = 1.0;
134+
current_accel.linear.x = 1.0;
135+
136+
const auto constraints =
137+
traffic_simulator_msgs::build<traffic_simulator_msgs::msg::DynamicConstraints>()
138+
.max_acceleration(1.0)
139+
.max_acceleration_rate(1.0)
140+
.max_deceleration(1.0)
141+
.max_deceleration_rate(1.0)
142+
.max_speed(10.0);
143+
144+
constexpr double epsilon = 1e-5;
145+
{
146+
const double target_speed = current_twist.linear.x + epsilon;
147+
const double result_duration =
148+
planner.getAccelerationDuration(target_speed, constraints, current_twist, current_accel);
149+
EXPECT_GE(result_duration, 0.0);
150+
EXPECT_LE(result_duration, epsilon);
151+
}
152+
{
153+
const double target_speed = current_twist.linear.x + 0.0100;
154+
const double result_duration =
155+
planner.getAccelerationDuration(target_speed, constraints, current_twist, current_accel);
156+
EXPECT_GE(result_duration, 0.0);
157+
EXPECT_LE(result_duration, 0.0100 + epsilon);
158+
}
159+
{
160+
const double target_speed = current_twist.linear.x + 0.0099;
161+
const double result_duration =
162+
planner.getAccelerationDuration(target_speed, constraints, current_twist, current_accel);
163+
EXPECT_GE(result_duration, 0.0);
164+
EXPECT_LE(result_duration, 0.0099 + epsilon);
165+
}
166+
}
124167

125168
/**
126169
* @note Test functionality aggregation used in other classes.

0 commit comments

Comments
 (0)