26 return (v * v) / (2.0 * a);
37 return (std::pow(free_flow_speed, 2) - std::pow(current_speed, 2))/(2 * max_accel) + (std::pow(departure_speed, 2) - std::pow(free_flow_speed, 2))/(2* max_decel);
42 if (current_speed <= departure_speed +
epsilon_)
44 return (std::pow(departure_speed, 2) - std::pow(current_speed, 2))/(2 * max_accel);
48 return (std::pow(departure_speed, 2) - std::pow(current_speed, 2))/(2 * max_decel);
55 auto start_of_tbd_time = rclcpp::Time((lanelet::time::toSec(signal->recorded_time_stamps.back().first) +
EPSILON) * 1e9);
56 if (earliest_entry_time > start_of_tbd_time)
58 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"Not enough signals are available to check for EET, so returning EET at: " <<
std::to_string(earliest_entry_time.seconds()));
59 return earliest_entry_time;
62 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"No valid green entry time found, so returning start of TBD at: " <<
std::to_string(start_of_tbd_time.seconds()));
63 return start_of_tbd_time;
68 boost::posix_time::time_duration g = lanelet::time::durationFromSec(minimum_required_green_time);
69 boost::posix_time::ptime t = lanelet::time::timeFromSec(current_time.seconds());
70 boost::posix_time::ptime eet = lanelet::time::timeFromSec(earliest_entry_time.seconds());
73 bool has_green_signal =
false;
74 for (
auto pair : signal->recorded_time_stamps)
78 has_green_signal =
true;
83 if (!has_green_signal)
88 auto curr_pair = signal->predictState(t);
90 throw std::invalid_argument(
"Traffic signal with id:" +
std::to_string(signal->id()) +
", does not have any recorded time stamps!");
92 boost::posix_time::time_duration theta = curr_pair.get().first - t;
93 auto p = curr_pair.get().second;
102 g = boost::posix_time::seconds(0);
108 curr_pair = signal->predictState(t + boost::posix_time::milliseconds(20));
109 p = curr_pair.get().second;
110 theta = curr_pair.get().first - t;
116 curr_pair = signal->predictState(t + boost::posix_time::milliseconds(20));
117 p = curr_pair.get().second;
118 theta = curr_pair.get().first - t;
124 double cycle_duration = signal->fixed_cycle_duration.total_milliseconds()/1000.0;
125 if (cycle_duration < 0.001)
126 cycle_duration = lanelet::time::toSec(signal->recorded_time_stamps.back().first) - lanelet::time::toSec(signal->recorded_start_time_stamps.front());
128 t = t + lanelet::time::durationFromSec(std::floor((eet - t).total_milliseconds()/1000.0/cycle_duration) * cycle_duration);
129 curr_pair = signal->predictState(t + boost::posix_time::milliseconds(20));
130 p = curr_pair.get().second;
131 theta = curr_pair.get().first - t;
137 theta = theta - (eet - t);
142 curr_pair = signal->predictState(t + boost::posix_time::milliseconds(20));
143 p = curr_pair.get().second;
144 theta = curr_pair.get().first - t;
147 if (t != lanelet::time::timeFromSec(lanelet::time::INFINITY_END_TIME_FOR_NOT_ENOUGH_STATES))
154 return rclcpp::Time(lanelet::time::toSec(t) * 1e9);
160 double accel_ratio = max_accel / max_decel;
161 double remaining_time = time_remaining_at_free_flow - full_cycle_duration / 2;
162 double inflection_speed = (max_accel * remaining_time - accel_ratio * departure_speed + current_speed)/ (1 - accel_ratio);
163 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"ENTER TRAJ CALC: time_remaining_at_free_flow: " << time_remaining_at_free_flow <<
", full_cycle_duration: " << full_cycle_duration <<
", inflection_speed: " << inflection_speed);
165 if (remaining_time < 0)
168 if (inflection_speed > 0 && inflection_speed <= speed_limit + epsilon_ && inflection_speed >= departure_speed -
epsilon_)
172 double d = (std::pow(inflection_speed, 2) - std::pow (current_speed, 2)) / (2 * max_accel) + (std::pow(departure_speed, 2) - std::pow(inflection_speed, 2)) / (2 * max_decel);
173 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"calculated distance WITHOUT cruising: " << d);
180 double decel_time = (current_speed - speed_limit) / max_decel;
181 double accel_time = (speed_limit - current_speed) / max_accel;
182 double cruising_time = remaining_time - decel_time - accel_time;
183 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"decel_time: " << decel_time <<
", accel_time: " << accel_time <<
", cruising_time: " << cruising_time);
184 double d = (std::pow(speed_limit, 2) - std::pow (current_speed, 2)) / (2 * max_accel) + (std::pow(departure_speed, 2) - std::pow(speed_limit, 2)) / (2 * max_decel) + cruising_time * speed_limit;
185 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"calculated distance with cruising: " << d <<
", accel_seg: " << (std::pow(speed_limit, 2) - std::pow (current_speed, 2)) / (2 * max_accel) <<
186 ", cruising: " << + cruising_time * speed_limit <<
", decel_seg:" << (std::pow(departure_speed, 2) - std::pow(speed_limit, 2)) / (2 * max_decel));
193 double x = remaining_distance;
198 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"x: " <<
x <<
", x2: " << x2 <<
", x1: " << x1 <<
", v_hat: " << v_hat);
202 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"Detected that v_hat is smaller than allowed!!!: " << v_hat);
206 if (v_hat >= free_flow_speed +
epsilon_)
208 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"Detected that v_hat is Bigger than allowed!!!: " << v_hat);
209 v_hat = free_flow_speed;
212 rclcpp::Duration t_accel(0,0);
213 if ( x < x2 && current_speed > departure_speed)
215 t_accel = rclcpp::Duration(0.0);
219 t_accel = rclcpp::Duration(std::max((v_hat - current_speed) / max_accel, 0.0) * 1e9);
221 rclcpp::Duration t_decel(0,0);
222 if (
x < x2 && current_speed < departure_speed)
224 t_decel = rclcpp::Duration(0.0);
230 t_decel = rclcpp::Duration(std::max((v_hat - current_speed) / max_decel, 0.0) * 1e9);
235 t_decel = rclcpp::Duration(std::max((departure_speed - v_hat) / max_decel, 0.0) * 1e9);
239 rclcpp::Duration t_cruise(0,0);
242 t_cruise = rclcpp::Duration(std::max((
x - x1)/v_hat, 0.0) * 1e9);
246 t_cruise = rclcpp::Duration(0.0);
248 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"t_accel: " << t_accel.seconds() <<
", t_cruise: " << t_cruise.seconds() <<
", t_decel: " << t_decel.seconds());
249 return t_accel + t_cruise + t_decel;
255 if(traffic_light->signal_durations.find(lanelet::CarmaTrafficSignalState::PROTECTED_MOVEMENT_ALLOWED) != traffic_light->signal_durations.end())
257 return traffic_light->signal_durations[lanelet::CarmaTrafficSignalState::PROTECTED_MOVEMENT_ALLOWED];
260 return traffic_light->signal_durations[lanelet::CarmaTrafficSignalState::PERMISSIVE_MOVEMENT_ALLOWED];
266 rclcpp::Time nearest_green_entry_time = rclcpp::Time(0);
267 bool is_entry_time_within_green_or_tbd =
false;
273 is_entry_time_within_green_or_tbd =
true;
275 if (!nearest_green_entry_time_optional)
277 nearest_green_entry_time =
get_eet_or_tbd(earliest_entry_time, traffic_light);
282 nearest_green_entry_time = nearest_green_entry_time_optional.value() + rclcpp::Duration(
EPSILON * 1e9);
287 nearest_green_entry_time = rclcpp::Time(std::max(earliest_entry_time.seconds(), (
scheduled_enter_time_)/1000.0) * 1e9) + rclcpp::Duration(
EPSILON * 1e9);
293 for (
auto pair : traffic_light->recorded_time_stamps)
295 if (lanelet::time::timeFromSec(nearest_green_entry_time.seconds()) < pair.first)
299 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"ET is inside the GREEN phase! where starting time: " <<
std::to_string(lanelet::time::toSec(traffic_light->recorded_start_time_stamps[
i]))
300 <<
", ending time of that green signal is: " <<
std::to_string(lanelet::time::toSec(pair.first)));
301 is_entry_time_within_green_or_tbd =
true;
305 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"Vehicle should plan cruise and stop as ET is inside the RED or YELLOW phase! where starting time: " <<
std::to_string(lanelet::time::toSec(traffic_light->recorded_start_time_stamps[
i]))
306 <<
", ending time of that green signal is: " <<
std::to_string(lanelet::time::toSec(pair.first)));
307 is_entry_time_within_green_or_tbd =
false;
318 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"ET is inside TBD phase! where starting time: " <<
std::to_string(lanelet::time::toSec(traffic_light->recorded_time_stamps.back().first)));
319 is_entry_time_within_green_or_tbd =
true;
323 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"nearest_green_entry_time: " << nearest_green_entry_time.get_clock_type());
324 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"current_state.stamp: " << current_state.
stamp.get_clock_type());
326 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"nearest_green_entry_time: " <<
std::to_string(nearest_green_entry_time.seconds()) <<
", with : " <<
std::to_string((nearest_green_entry_time - current_state.
stamp).seconds()) <<
" seconds left at: " <<
std::to_string(current_state.
stamp.seconds()));
333 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"After accounting for cached - nearest_green_entry_time: " <<
std::to_string(nearest_green_entry_time.seconds()) <<
", with : " <<
std::to_string((nearest_green_entry_time - current_state.
stamp).seconds()) <<
" seconds left at: " <<
std::to_string(current_state.
stamp.seconds()));
337 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"Applying green_light_buffer for the first time and caching! nearest_green_entry_time (without buffer):" <<
std::to_string(nearest_green_entry_time.seconds()) <<
", and earliest_entry_time: " <<
std::to_string(earliest_entry_time.seconds()));
341 rclcpp::Time early_arrival_time_green_et =
344 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"early_arrival_time_green_et: " <<
std::to_string(early_arrival_time_green_et.seconds()));
346 auto early_arrival_state_green_et_optional = traffic_light->predictState(lanelet::time::timeFromSec(early_arrival_time_green_et.seconds()));
348 if (!
validLightState(early_arrival_state_green_et_optional, early_arrival_time_green_et))
350 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"Unable to resolve give signal...");
351 return std::make_tuple(rclcpp::Time(0), is_entry_time_within_green_or_tbd, in_tbd);
354 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"early_arrival_state_green_et: " << early_arrival_state_green_et_optional.get().second);
356 bool can_make_early_arrival =
isStateAllowedGreen(early_arrival_state_green_et_optional.get().second);
359 if (can_make_early_arrival)
367 rclcpp::Time nearest_green_signal_start_time = rclcpp::Time(0);
368 if (traffic_light->fixed_cycle_duration.total_milliseconds()/1000.0 > 1.0)
370 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"UC2 Handling");
371 auto normal_arrival_state_green_et_optional = traffic_light->predictState(lanelet::time::timeFromSec(nearest_green_entry_time.seconds()));
373 if (!
validLightState(normal_arrival_state_green_et_optional, nearest_green_entry_time))
375 RCLCPP_ERROR_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"Unable to resolve give signal...");
376 return std::make_tuple(rclcpp::Time(0), is_entry_time_within_green_or_tbd, in_tbd);
379 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"normal_arrival_signal_end_time: " <<
std::to_string(lanelet::time::toSec(normal_arrival_state_green_et_optional.get().first)));
386 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"UC3 Handling");
388 for (
size_t i = 0;
i < traffic_light->recorded_start_time_stamps.size();
i++)
391 lanelet::time::timeFromSec(nearest_green_entry_time.seconds()) < traffic_light->recorded_time_stamps[
i].first )
393 nearest_green_signal_start_time = rclcpp::Time(lanelet::time::toSec(traffic_light->recorded_start_time_stamps[
i]) * 1e9);
398 if (nearest_green_signal_start_time == rclcpp::Time(0))
400 nearest_green_signal_start_time = rclcpp::Time(lanelet::time::toSec(traffic_light->recorded_time_stamps.back().first) * 1e9);
423 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"Earliest entry time... has gone past the cashed entering time. nearest_green_entry_time_cached_ (which can also be TBD):" <<
std::to_string(
nearest_green_entry_time_cached_.get().seconds()) <<
", and earliest_entry_time: " <<
std::to_string(earliest_entry_time.seconds()));
425 return std::make_tuple(nearest_green_entry_time, is_entry_time_within_green_or_tbd, in_tbd);
432 return free_flow_speed;
434 else if (x1 >
x &&
x >= x2)
436 return std::sqrt((2 *
x * max_accel * max_decel + max_decel * std::pow(current_speed, 2) - max_accel * (std::pow(departure_speed, 2)))/(max_decel - max_accel));
440 if (current_speed <= departure_speed)
442 return std::sqrt(2 *
x * max_accel + std::pow(current_speed, 2));
446 return std::sqrt(2 *
x * max_decel + std::pow(current_speed, 2));
457 t_entry = 2*entry_dist/(current_speed + departure_speed);
466 distances.
dx1 = ((pow(v_max, 2) - pow(v0, 2)) / (2 * a_max)) + ((pow(v1, 2) - pow(v_max, 2)) / (2 * a_min));
468 distances.
dx2 = ((pow(v1, 2) - pow(v0, 2)) / (2 * a_max));
470 distances.
dx2 = ((pow(v1, 2) - pow(v0, 2)) / (2 * a_min));
472 distances.
dx3 = ((pow(v_min, 2) - pow(v0, 2)) / (2 * a_min)) + ((pow(v1, 2) - pow(v_min, 2)) / (2 * a_max));
473 distances.
dx4 = ((pow(v_min, 2) - pow(v0, 2)) / (2 * a_min));
474 distances.
dx5 = - pow(v0, 2) / (2 * a_min);
481 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"\n");
482 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"t0: " <<
std::to_string(params.
t0_));
483 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"v0: " << params.
v0_);
484 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"x0: " << params.
x0_);
486 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"t1: " <<
std::to_string(params.
t1_));
487 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"v1: " << params.
v1_);
488 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"x1: " << params.
x1_);
489 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"a1: " << params.
a1_);
491 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"t2: " <<
std::to_string(params.
t2_));
492 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"v2: " << params.
v2_);
493 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"x2: " << params.
x2_);
494 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"a2: " << params.
a2_);
496 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"t3: " <<
std::to_string(params.
t3_));
497 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"v3: " << params.
v3_);
498 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"x3: " << params.
x3_);
499 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"a3: " << params.
a3_);
501 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"\n");
506 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"\n");
507 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"dx1: " << delta_xs.
dx1);
508 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"dx2: " << delta_xs.
dx2);
509 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"dx3: " << delta_xs.
dx3);
510 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"dx4: " << delta_xs.
dx4);
511 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"dx5: " << delta_xs.
dx5 <<
"\n");
514std::vector<TrajectoryParams>
LCIStrategicPlugin::get_boundary_traj_params(
double t,
double v0,
double v1,
double v_max,
double v_min,
double a_max,
double a_min,
double x0,
double x_end,
double dx,
BoundaryDistances boundary_distances)
516 double dx1 = boundary_distances.
dx1;
517 double dx2 = boundary_distances.
dx2;
518 double dx3 = boundary_distances.
dx3;
519 double dx4 = boundary_distances.
dx4;
520 double dx5 = boundary_distances.
dx5;
586 return {traj1, traj2, traj3, traj4, traj5, traj6, traj7, traj8};
589TrajectoryParams LCIStrategicPlugin::get_ts_case(
double t,
double et,
double v0,
double v1,
double v_max,
double v_min,
double a_max,
double a_min,
double x0,
double x_end,
double dx,
BoundaryDistances boundary_distances, std::vector<TrajectoryParams> params)
591 double dx1 = boundary_distances.
dx1;
592 double dx2 = boundary_distances.
dx2;
593 double dx3 = boundary_distances.
dx3;
594 double dx4 = boundary_distances.
dx4;
595 double dx5 = boundary_distances.
dx5;
597 if (params.size() != 8)
599 throw std::invalid_argument(
"Not enough trajectory paras given! Given size: " +
std::to_string(params.size()));
613 if (traj1.
t3_ <= et && et < traj2.
t3_)
615 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CALCULATED: case 1");
616 veh_traj =
ts_case1(t, et, v0, v1, v_max, a_max, a_min, x0, x_end, dx);
619 else if (traj2.
t3_ <= et && et < traj3.
t3_)
621 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CALCULATED: case 2");
622 veh_traj =
ts_case2(t, et, v0, v1, a_max, a_min, x0, x_end, dx);
625 else if (traj3.
t3_ <= et && et < traj4.
t3_)
627 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CALCULATED: case 3");
628 veh_traj =
ts_case3(t, et, v0, v1, a_max, a_min, x0, x_end, dx);
631 else if (traj4.
t3_ <= et && et < traj5.
t3_)
633 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CALCULATED: case 4");
634 veh_traj =
ts_case4(t, et, v0, v1, v_min, a_max, a_min, x0, x_end, dx);
637 else if (traj5.
t3_ <= et && et < traj6.
t3_)
639 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CALCULATED: case 5");
640 veh_traj =
ts_case5(t, et, v0, a_max, a_min, x0, x_end, dx);
643 else if (traj6.
t3_ <= et && et < traj7.
t3_)
645 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CALCULATED: case 6");
646 veh_traj =
ts_case6(t, et, v0, v_min, a_min, x0, x_end, dx, dx3, traj6);
649 else if (traj7.
t3_ <= et && et <= traj8.
t3_)
651 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CALCULATED: case 7");
652 veh_traj =
ts_case7(t, et, v0, v_min, a_min, x0, x_end, dx);
657 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CALCULATED: case 8");
658 veh_traj =
ts_case8(dx, dx5, traj8);
675 double nom1 = 2 * dx * (((1 - (a_max / a_min)) * v_max) + ((a_max / a_min) * v1) - v0);
676 double nom2 = dt * (((1 - (a_max / a_min)) * pow(v_max, 2)) + ((a_max / a_min) * pow(v1, 2)) - pow(v0, 2));
677 double den = pow(v_max - v0, 2) - ((a_max / a_min) * pow(v_max - v1, 2));
679 if (den <= epsilon_ && den >= -
epsilon_)
680 throw std::invalid_argument(
"CASE1: Received den near zero..." +
std::to_string(den));
682 double tc = (nom1 - nom2) / den;
686 if (dt - tc <= epsilon_ && dt - tc >= -
epsilon_)
687 throw std::invalid_argument(
"CASE1: Received dt - tc near zero..." +
std::to_string(dt - tc));
689 traj.
a1_ = (((1 - (a_max / a_min)) * v_max) + ((a_max / a_min) * v1) - v0) / (dt - tc);
693 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CASE1: Received traj.a1_ near zero...");
694 traj.
t1_ = traj.
t0_ + ((dt - tc) * (a_max / (a_min + a_max)));
700 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
705 traj.
x2_ = traj.
x1_ + (v_max * tc);
708 traj.
a3_ = traj.
a1_ * (a_min / a_max);
725 if (dt <= epsilon_ && dt >= -
epsilon_)
726 throw std::invalid_argument(
"CASE2: Received dt near zero..." +
std::to_string(dt));
728 double sqr1 = pow(1 - (a_max / a_min), 2) * pow(dx / dt, 2);
729 double sqr2 = (1 - (a_max / a_min)) * (((a_max / a_min) * v1 * (v1 - (2 * dx / dt))) + (v0 * ((2 * dx / dt) - v0)));
730 double v_hat = (dx / dt) + (sqrt(sqr1 - sqr2) / (1 - (a_max / a_min)));
733 traj.
a1_ = (((1 - (a_max / a_min)) * v_hat) + ((a_max / a_min) * v1) - v0) / dt;
737 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CASE2: Received traj.a1_ near zero...");
738 traj.
t1_ = traj.
t0_ + (dt * (a_max / (a_min + a_max)));
744 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
748 traj.
a2_ = traj.
a1_ * a_min / a_max;
752 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CASE2: Received traj.a2_ near zero...");
753 traj.
t2_ = traj.
t1_ + (dt * (a_min / (a_min + a_max)));
779 if (dt <= epsilon_ && dt >= -
epsilon_)
780 throw std::invalid_argument(
"CASE3: Received dt near zero..." +
std::to_string(dt));
782 double sqr1 = pow((a_max / a_min) - 1, 2) * pow(dx / dt, 2);
783 double sqr2 = ((a_max / a_min) - 1) * ((v1 * (v1 - (2 * dx / dt))) + ((a_max / a_min) * v0 * ((2 * dx / dt) - v0)));
784 double v_hat = (dx / dt) + (sqrt(sqr1 - sqr2) / ((a_max / a_min) - 1));
787 traj.
a1_ = (((1 - (a_min / a_max)) * v_hat) + ((a_min / a_max) * v1) - v0) / dt;
791 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CASE3: Received traj.a1_ near zero...");
792 traj.
t1_ = traj.
t0_ + (dt * (a_max / (a_min + a_max)));
798 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
802 traj.
a2_ = traj.
a1_ * a_max / a_min;
822 double nom1 = 2 * dx * ((((a_max / a_min) - 1) * v_min) + v1 - ((a_max / a_min) * v0));
823 double nom2 = dt * ((((a_max / a_min) - 1) * pow(v_min, 2)) + pow(v1, 2) - ((a_max / a_min) * pow(v0, 2)));
824 double den = ((a_max / a_min) * pow(v_min - v0, 2)) - pow(v_min - v1, 2);
826 if (den <= epsilon_ && den >= -
epsilon_)
827 throw std::invalid_argument(
"CASE4: Received den near zero..." +
std::to_string(den));
829 double tc = (nom1 - nom2) / den;
833 if (dt - tc <= epsilon_ && dt - tc >= -
epsilon_)
834 throw std::invalid_argument(
"CASE4: Received dt - tc near zero..." +
std::to_string(dt - tc));
836 traj.
a1_ = (((1 - (a_min / a_max)) * v_min) + ((a_min / a_max) * v1) - v0) / (dt - tc);
840 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CASE4: Received traj.a1_ near zero...");
841 traj.
t1_ = traj.
t0_ + ((dt - tc) * (a_min / (a_min + a_max)));
847 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
853 traj.
x2_ = traj.
x1_ + (v_min * tc);
856 traj.
a3_ = traj.
a1_ * a_max / a_min;
872 double sqr = ((a_max / a_min) - 1) * ((2 * a_min * (dx - (v0 * dt))) - pow(a_min * dt, 2));
873 double v_hat = (v0 + (a_min * dt)) - (sqrt(sqr) / ((a_max / a_min) - 1));
874 double v_p = ((1 - (a_max / a_min)) * v_hat) + ((a_max / a_min) * v0) + (a_max * dt);
880 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
908 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
915 tc = traj6.
t2_ - traj6.
t1_;
920 traj.
x2_ = traj.
x1_ + (v_min * tc);
922 double dt_p = dt - (traj.
t1_ - traj.
t0_) - tc;
924 if (dt_p <= epsilon_ && dt_p >= -
epsilon_)
925 throw std::invalid_argument(
"CASE6: Received dt_p near zero..." +
std::to_string(dt_p));
927 double v_p = ((2 * a_min * (dx - (v_min * tc))) - (pow(v_min, 2) - pow(v0, 2)) - (v_min * dt_p * a_min)) / (dt_p * a_min);
930 traj.
a3_ = (v_p - v_min) / dt_p;
948 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
951 double v_p = v_min - sqrt(pow(v_min - v0, 2) - (2 * a_min * ((v_min * dt) - dx)));
952 double dt_p = (v_p - v_min) / a_min;
954 if (dt_p <= epsilon_ && dt_p >= -
epsilon_)
955 throw std::invalid_argument(
"CASE7: Received dt_p near zero..." +
std::to_string(dt_p));
957 double tc = dt - ((v_p - v0) / a_min);
962 traj.
x2_ = traj.
x1_ + (v_min * tc);
965 traj.
a3_ = (v_p - v_min) / dt_p;
978 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"CASE8: Not within safe stopping distance originally planned!");
989 t_end = t + (sqrt(pow(v0, 2) + (2 * a_max * dx)) - v0)/a_max;
991 t_end = t + (sqrt(pow(v0, 2) + (2 * a_min * dx)) - v0) / a_min;
1004 traj.v1_ = sqrt(pow(v0, 2) + (2 * a_max * dx));
1009 traj.v1_ = sqrt(pow(v0, 2) + (2 * a_min * dx));
1014 traj.t2_ = traj.t1_;
1016 traj.v2_ = traj.v1_;
1017 traj.x2_ = traj.x1_;
1019 traj.t3_ = traj.t1_;
1021 traj.v3_ = traj.v1_;
1022 traj.x3_ = traj.x1_;
1030 double v_hat = sqrt(((2 * dx * a_max * a_min) + (a_min * pow(v0, 2)) - (a_max * pow(v1, 2))) / (a_min - a_max));
1031 double t_end = t + ((v_hat * (a_min - a_max)) - (v0 * a_min) + (v1 * a_max)) / (a_max * a_min);
1043 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
1061 double t_end = t + (dx / v_max) + (pow(v_max - v0, 2) / (2 * a_max * v_max)) - (pow(v1 - v_max, 2) / (2 * a_min * v_max));
1072 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
1076 traj.
t2_ = t_end - ((v1 - v_max) / a_min);
1077 traj.
x2_ = x_end - ((pow(v1, 2) - pow(v_max, 2)) / (2 * a_min));
1089 double nom = (v_max - v0) + ((a_max / a_min) * (v1 - v_max));
1090 double den = (pow(v_max, 2) - pow(v0, 2)) + ((a_max / a_min) * (pow(v1, 2) - pow(v_max, 2)));
1092 if (den <= epsilon_ && den >= -
epsilon_)
1093 throw std::invalid_argument(
"boundary_accel_nocruise_maxspeed_decel: Received den near zero..." +
std::to_string(den));
1095 double t_end = t + (2 * dx * nom / den);
1103 double dt = t_end - t;
1108 if (dt - tc <= epsilon_ && dt - tc >= -
epsilon_)
1109 throw std::invalid_argument(
"boundary_accel_nocruise_maxspeed_decel: Received dt - tc near zero..." +
std::to_string(dt - tc));
1111 traj.a1_ = (((1 - (a_max / a_min)) * v_max) + ((a_max / a_min) * v1) - v0) / (dt - tc);
1115 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"lci_strategic_plugin"),
"boundary_accel_nocruise_maxspeed_decel: Received traj.a1_ near zero...");
1116 traj.t1_ = traj.t0_ + (dt * (a_max / (a_min + a_max)));
1117 traj.x1_ = traj.x0_ + (v_max * (traj.t1_ - traj.t0_));
1121 traj.t1_ = traj.t0_ + ((traj.v1_ - traj.v0_) / traj.a1_);
1122 traj.x1_ = traj.x0_ + ((pow(traj.v1_, 2) - pow(traj.v0_, 2)) / (2 * traj.a1_));
1126 traj.a2_ = ((((a_min / a_max) - 1) * v_max) + v1 - ((a_min / a_max) * v0)) / (dt - tc);
1130 traj.t3_ = traj.t2_;
1132 traj.v3_ = traj.v2_;
1133 traj.x3_ = traj.x2_;
1140 if (v0 + v1 <= epsilon_ && v0 + v1 >= -
epsilon_)
1141 throw std::invalid_argument(
"boundary_accel_or_decel_complete_upper: Received v0 + v1 near zero..." +
std::to_string(v0 + v1));
1143 double t_end = t + ((2 * dx) / (v0 + v1));
1153 if (dx <= epsilon_ && dx >= -
epsilon_)
1154 throw std::invalid_argument(
"boundary_accel_or_decel_complete_upper: Received dx near zero..." +
std::to_string(dx));
1156 traj.a1_ = (pow(v1, 2) - pow(v0, 2)) / (2 * dx);
1160 traj.t2_ = traj.t1_;
1162 traj.v2_ = traj.v1_;
1163 traj.x2_ = traj.x1_;
1165 traj.t3_ = traj.t1_;
1167 traj.v3_ = traj.v1_;
1168 traj.x3_ = traj.x1_;
1175 double v_hat = sqrt(((2 * dx * a_max * a_min) + (a_max * pow(v0, 2)) - (a_min * pow(v1, 2))) / (a_max - a_min));
1176 double t_end = t + ((v_hat * (a_max - a_min)) - (v0 * a_max) + (v1 * a_min)) / (a_max * a_min);
1187 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
1204 double sqr = sqrt((2 * a_max * dx) - ((pow(v_min, 2) - pow(v0, 2)) * (a_max / a_min)) + pow(v_min, 2));
1206 double t_end = t + ((sqr - v_min) / a_max) + ((v_min - v0) / a_min);
1217 traj.
x1_ = traj.
x0_ + (pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * a_min);
1234 double nom = (v1 - v_min) + ((a_max / a_min) * (v_min - v0));
1235 double den = (pow(v1, 2) - pow(v_min, 2)) + ((a_max / a_min) * (pow(v_min, 2) - pow(v0, 2)));
1237 if (den <= epsilon_ && den >= -
epsilon_)
1238 throw std::invalid_argument(
"boundary_decel_nocruise_minspeed_accel_complete: Received den near zero..." +
std::to_string(den));
1240 double t_end = t + (2 * dx * nom / den);
1247 double dt = t_end - t;
1252 if (dt - tc <= epsilon_ && dt - tc >= -
epsilon_)
1253 throw std::invalid_argument(
"boundary_decel_nocruise_minspeed_accel_complete: Received dt - tc near zero..." +
std::to_string(dt - tc));
1255 traj.a1_ = (((1 - (a_min / a_max)) * v_min) + ((a_min / a_max) * v1) - v0) / (dt - tc);
1256 traj.t1_ = traj.t0_ + ((traj.v1_ - traj.v0_) / traj.a1_);
1257 traj.x1_ = traj.x0_ + ((pow(traj.v1_, 2) - pow(traj.v0_, 2)) / (2 * traj.a1_));
1260 traj.a2_ = ((((a_max / a_min) - 1) * v_min) + v1 - ((a_max / a_min) * v0)) / (dt - tc);
1264 traj.t3_ = traj.t2_;
1266 traj.v3_ = traj.v2_;
1267 traj.x3_ = traj.x2_;
1273 double t_end = t + (dx / v_min) + ((pow(v_min - v0, 2)) / (2 * a_min * v_min)) - ((pow(v1 - v_min, 2)) / (2 * a_max * v_min));
1284 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
1288 traj.
t2_ = t_end - ((v1 - v_min) / a_max);
1289 traj.
x2_ = x_end - ((pow(v1, 2) - pow(v_min, 2)) / (2 * a_max));
1301 double t_end = t + (dx / v_min) + (pow(v_min - v0, 2) / (2 * a_min * v_min));
1312 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
1328 double t_end = t + (sqrt(pow(v0, 2) + (2 * a_min * dx)) - v0) / a_min;
1337 traj.v1_ = sqrt(pow(v0, 2) + (2 * a_min * dx));
1341 traj.t2_ = traj.t1_;
1343 traj.v2_ = traj.v1_;
1344 traj.x2_ = traj.x1_;
1346 traj.t3_ = traj.t1_;
1348 traj.v3_ = traj.v1_;
1349 traj.x3_ = traj.x1_;
1355 double t_end = t + (dx / v_min) + (v0 * (v0 - (2 * v_min)) / (2 * a_min * v_min));
1366 traj.
x1_ = traj.
x0_ + ((pow(traj.
v1_, 2) - pow(traj.
v0_, 2)) / (2 * traj.
a1_));
1370 traj.
t2_ = t_end - ((0 - traj.
v2_) / a_min);
1371 traj.
x2_ = x_end - ((0 - pow(traj.
v2_, 2)) / (2 * a_min));
TrajectoryParams boundary_decel_nocruise_notminspeed_accel(double t, double v0, double v1, double v_min, double a_max, double a_min, double x0, double x_end, double dx)
TrajectoryParams boundary_decel_cruise_minspeed_decel(double t, double v0, double v_min, double a_min, double x0, double x_end, double dx)
LCIStrategicPluginConfig config_
Config containing configurable algorithm parameters.
BoundaryDistances get_delta_x(double v0, double v1, double v_max, double v_min, double a_max, double a_min)
Get boundary distances used to compare against current state in order to create trajectory smoothing ...
double get_distance_to_accel_or_decel_twice(double free_flow_speed, double current_speed, double departure_speed, double max_accel, double max_decel) const
Get required distance to accel then decel, or vise versa - each at least once - to reach departure_sp...
rclcpp::Time get_eet_or_tbd(const rclcpp::Time &earliest_entry_time, const lanelet::CarmaTrafficSignalPtr &signal) const
Returns the later of earliest_entry_time or the end of the available signal states in the traffic_sig...
double estimate_time_to_stop(double d, double v) const
Helper method to use basic kinematics to compute an estimated stopping time from from the inputs.
bool validLightState(const boost::optional< std::pair< boost::posix_time::ptime, lanelet::CarmaTrafficSignalState > > &optional_state, const rclcpp::Time &source_time) const
Helper method that checks both if the input optional light state is set and if the state it contains ...
TrajectoryParams ts_case7(double t, double et, double v0, double v_min, double a_min, double x0, double x_end, double dx)
boost::optional< rclcpp::Time > nearest_green_entry_time_cached_
TrajectoryParams boundary_accel_nocruise_maxspeed_decel(double t, double v0, double v1, double v_max, double a_max, double a_min, double x0, double x_end, double dx)
TrajectoryParams ts_case1(double t, double et, double v0, double v1, double v_max, double a_max, double a_min, double x0, double x_end, double dx)
Trajectory Smoothing Algorithm 8 cases. TSMO UC2, UC3 algorithm equations.
TrajectoryParams boundary_accel_or_decel_complete_upper(double t, double v0, double v1, double x0, double x_end, double dx)
std::optional< rclcpp::Time > get_nearest_green_entry_time(const rclcpp::Time ¤t_time, const rclcpp::Time &earliest_entry_time, const lanelet::CarmaTrafficSignalPtr &signal, double minimum_required_green_time=0.0) const
Provides the scheduled entry time for the vehicle in the future. This scheduled time is the earliest ...
TrajectoryParams boundary_accel_or_decel_incomplete_upper(double t, double v0, double v1, double a_max, double a_min, double x0, double x_end, double dx)
unsigned long long scheduled_enter_time_
double calc_estimated_entry_time_left(double entry_dist, double current_speed, double departure_speed) const
calculate the time vehicle will enter to intersection with optimal deceleration
rclcpp::Duration get_earliest_entry_time(double remaining_distance, double free_flow_speed, double current_speed, double departure_speed, double max_accel, double max_decel) const
Gets the earliest entry time into the intersection that is kinematically possible for the vehicle....
boost::posix_time::time_duration getMovementAllowedDuration(lanelet::CarmaTrafficSignalPtr traffic_light)
Returns the duration for the allowed movements.
TrajectoryParams boundary_accel_nocruise_notmaxspeed_decel(double t, double v0, double v1, double a_max, double a_min, double x0, double x_end, double dx)
TrajectoryParams boundary_decel_nocruise_minspeed_accel_incomplete(double t, double v0, double v_min, double a_max, double a_min, double x0, double x_end, double dx)
std::tuple< rclcpp::Time, bool, bool > get_final_entry_time_and_conditions(const VehicleState ¤t_state, const rclcpp::Time &earliest_entry_time, lanelet::CarmaTrafficSignalPtr traffic_light)
Get the final entry time from either vehicle's own internal ET calculation (TSMO UC2) or from carma-s...
TrajectoryParams boundary_accel_cruise_maxspeed_decel(double t, double v0, double v1, double v_max, double a_max, double a_min, double x0, double x_end, double dx)
TrajectoryParams boundary_decel_incomplete_lower(double t, double v0, double a_min, double x0, double x_end, double dx)
TrajectoryParams ts_case6(double t, double et, double v0, double v_min, double a_min, double x0, double x_end, double dx, double dx3, TrajectoryParams traj6)
TrajectoryParams ts_case4(double t, double et, double v0, double v1, double v_min, double a_max, double a_min, double x0, double x_end, double dx)
TrajectoryParams boundary_decel_cruise_minspeed_accel(double t, double v0, double v1, double v_min, double a_max, double a_min, double x0, double x_end, double dx)
void print_params(TrajectoryParams params)
Helper method to print TrajectoryParams.
TrajectoryParams ts_case2(double t, double et, double v0, double v1, double a_max, double a_min, double x0, double x_end, double dx)
TrajectoryParams get_ts_case(double t, double et, double v0, double v1, double v_max, double v_min, double a_max, double a_min, double x0, double x_end, double dx, BoundaryDistances boundary_distances, std::vector< TrajectoryParams > params)
TrajectoryParams boundary_decel_nocruise_minspeed_accel_complete(double t, double v0, double v1, double v_max, double v_min, double a_max, double a_min, double x0, double x_end, double dx)
double get_distance_to_accel_or_decel_once(double current_speed, double departure_speed, double max_accel, double max_decel) const
Get required distance to accel or decel to reach departure_speed with given speed and acceleration pa...
TrajectoryParams boundary_decel_cruise_minspeed(double t, double v0, double v_min, double a_min, double x0, double x_end, double dx)
double get_inflection_speed_value(double x, double x1, double x2, double free_flow_speed, double current_speed, double departure_speed, double max_accel, double max_decel) const
Get the speed between the acceleration and deceleration pieces.
double get_trajectory_smoothing_activation_distance(double time_remaining_at_free_flow, double full_cycle_duration, double current_speed, double speed_limit, double departure_speed, double max_accel, double max_decel) const
Gets maximum distance (nearest downtrack) the trajectory smoothing algorithm makes difference than si...
TrajectoryParams ts_case8(double dx, double dx5, TrajectoryParams traj8)
TrajectoryParams ts_case3(double t, double et, double v0, double v1, double a_max, double a_min, double x0, double x_end, double dx)
double estimate_distance_to_stop(double v, double a) const
Helper method to use basic kinematics to compute an estimated stopping distance from from the inputs.
bool isStateAllowedGreen(const lanelet::CarmaTrafficSignalState &state) const
Method to check if the state is an allowed green movement state. Currently Permissive and Protected g...
TrajectoryParams ts_case5(double t, double et, double v0, double a_max, double a_min, double x0, double x_end, double dx)
std::vector< TrajectoryParams > get_boundary_traj_params(double t, double v0, double v1, double v_max, double v_min, double a_max, double a_min, double x0, double x_end, double dx, BoundaryDistances boundary_distances)
Get all possible trajectory smoothing parameters for each segments. Later this will be used to genera...
void print_boundary_distances(BoundaryDistances delta_xs)
Helper method to print TrajectoryParams.
auto to_string(const UtmZone &zone) -> std::string
bool enable_carma_streets_connection
Bool: Enable carma streets connection.
double algo_minimum_speed
Minimum allowable speed TS algorithm in m/s.
double green_light_time_buffer
A buffer in seconds around the green phase which will reduce the phase length such that vehicle still...
Struct representing a vehicle state for the purposes of planning.
bool is_algorithm_successful