15 #ifndef TRAFFIC_SIMULATOR__BEHAVIOR__FOLLOW_WAYPOINT_CONTROLLER_HPP_
16 #define TRAFFIC_SIMULATOR__BEHAVIOR__FOLLOW_WAYPOINT_CONTROLLER_HPP_
25 #include <traffic_simulator_msgs/msg/behavior_parameter.hpp>
26 #include <traffic_simulator_msgs/msg/entity_status.hpp>
27 #include <traffic_simulator_msgs/msg/polyline_trajectory.hpp>
31 namespace follow_trajectory
35 template <
typename... Ts>
38 "An error occurred in the internal controller operation in the FollowTrajectoryAction. ",
39 "Please report the following information to the developer: ",
40 std::forward<decltype(
xs)>(
xs)...))
52 auto moveStraight(
const double step_acceleration,
const double step_time) ->
void
65 template <
typename StreamType>
68 stream << std::setprecision(16) << std::fixed;
69 stream <<
"PredictedState: acceleration: " << state.acceleration <<
", speed: " << state.speed
70 <<
", distance: " << state.traveled_distance <<
", time: " << state.travel_time <<
". ";
77 const double step_time;
78 const bool with_breaking;
80 const double max_speed;
81 const double max_acceleration;
82 const double max_acceleration_rate;
83 const double max_deceleration;
84 const double max_deceleration_rate;
86 const double target_speed;
95 static constexpr
double local_epsilon = 1e-12;
104 static constexpr
double step_time_tolerance = 1e-6;
113 static constexpr
double finish_distance_tolerance = 1e-2;
123 static constexpr
double predicted_distance_tolerance = 1.0;
132 static constexpr std::size_t number_of_acceleration_candidates = 30;
137 template <
typename StreamType>
140 stream << std::setprecision(16) << std::fixed;
141 stream <<
"FollowWaypointController: step_time: " << c.step_time
142 <<
", with_breaking: " << c.with_breaking <<
", max_speed: " << c.max_speed
143 <<
", max_acceleration: " << c.max_acceleration
144 <<
", max_deceleration: " << c.max_deceleration
145 <<
", max_acceleration_rate: " << c.max_acceleration_rate
146 <<
", max_deceleration_rate: " << c.max_deceleration_rate
147 <<
", target_speed: " << c.target_speed <<
". ";
183 auto getAnalyticalAccelerationForLastSteps(
184 const double remaining_time,
const double remaining_distance,
const double acceleration,
185 const double speed)
const -> double;
193 auto roundTimeToFullStepsWithTolerance(
194 const double remaining_time_source,
const double time_tolerance)
const -> double;
202 auto getTimeRequiredForNonAcceleration(
const double acceleration)
const -> double;
209 auto getAccelerationLimits(
const double acceleration,
const double speed)
const
210 -> std::pair<double, double>;
212 auto clampAcceleration(
213 const double candidate_acceleration,
const double acceleration,
const double speed)
const
216 auto moveStraight(
PredictedState & state,
const double candidate_acceleration)
const -> void;
218 auto getPredictedStopStateWithoutConsideringTime(
219 const double step_acceleration,
const double remaining_distance,
const double acceleration,
220 const double speed)
const -> std::optional<PredictedState>;
224 const traffic_simulator_msgs::msg::BehaviorParameter & behavior_parameter,
225 const double step_time,
const bool with_breaking,
226 const std::optional<double> & target_speed = std::nullopt)
227 : step_time{step_time},
228 with_breaking{with_breaking},
229 max_speed{behavior_parameter.dynamic_constraints.max_speed},
230 max_acceleration{behavior_parameter.dynamic_constraints.max_acceleration},
231 max_acceleration_rate{behavior_parameter.dynamic_constraints.max_acceleration_rate},
232 max_deceleration{behavior_parameter.dynamic_constraints.max_deceleration},
233 max_deceleration_rate{behavior_parameter.dynamic_constraints.max_deceleration_rate},
234 target_speed{(target_speed) ? target_speed.value() : max_speed}
242 const traffic_simulator_msgs::msg::PolylineTrajectory & polyline_trajectory)
const
245 if (
const auto & vertices = polyline_trajectory.shape.vertices; !vertices.empty()) {
246 std::stringstream waypoint_details;
247 waypoint_details <<
"Currently followed waypoint: ";
248 if (
const auto first_waypoint_with_arrival_time_specified = std::find_if(
249 vertices.begin(), vertices.end(),
250 [](
auto && vertex) { return not std::isnan(vertex.time); });
251 first_waypoint_with_arrival_time_specified !=
252 std::end(polyline_trajectory.shape.vertices)) {
253 waypoint_details <<
"[" << first_waypoint_with_arrival_time_specified->position.position.x
254 <<
", " << first_waypoint_with_arrival_time_specified->position.position.y
255 <<
"] with specified time equal to "
256 << first_waypoint_with_arrival_time_specified->time <<
"s. ";
258 waypoint_details <<
"[" << vertices.back().position.position.x <<
", "
259 << vertices.back().position.position.y <<
"] without specified time. ";
261 return waypoint_details.str();
263 return "No followed waypoint - trajectory is empty.";
272 const double step_acceleration,
const double remaining_time,
const double remaining_distance,
273 const double acceleration,
const double speed)
const -> std::optional<PredictedState>;
280 const double remaining_distance,
const double acceleration,
const double speed)
const -> double;
287 const double remaining_time_source,
const double remaining_distance,
const double acceleration,
288 const double speed)
const -> double;
291 const double acceleration,
const double speed,
const double distance)
const ->
double
293 return (!with_breaking || std::abs(speed) < local_epsilon) &&
294 std::abs(acceleration) < local_epsilon &&
distance < finish_distance_tolerance;
Definition: follow_waypoint_controller.hpp:76
auto getAcceleration(const double remaining_distance, const double acceleration, const double speed) const -> double
Definition: follow_waypoint_controller.cpp:296
friend auto operator<<(StreamType &stream, const FollowWaypointController &c) -> StreamType &
Definition: follow_waypoint_controller.hpp:138
constexpr FollowWaypointController(const traffic_simulator_msgs::msg::BehaviorParameter &behavior_parameter, const double step_time, const bool with_breaking, const std::optional< double > &target_speed=std::nullopt)
Definition: follow_waypoint_controller.hpp:223
auto getPredictedWaypointArrivalState(const double step_acceleration, const double remaining_time, const double remaining_distance, const double acceleration, const double speed) const -> std::optional< PredictedState >
Definition: follow_waypoint_controller.cpp:207
auto getFollowedWaypointDetails(const traffic_simulator_msgs::msg::PolylineTrajectory &polyline_trajectory) const -> std::string
Definition: follow_waypoint_controller.hpp:241
auto areConditionsOfArrivalMet(const double acceleration, const double speed, const double distance) const -> double
Definition: follow_waypoint_controller.hpp:290
auto concatenate
Definition: concatenate.hpp:27
Definition: concatenate.hpp:24
auto distance(const geometry_msgs::Pose &pose1, const geometry_msgs::Pose &pose2)
Definition: detection_sensor.cpp:34
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: exception.hpp:27
Definition: follow_waypoint_controller.hpp:34
ControllerError(Ts &&... xs)
Definition: follow_waypoint_controller.hpp:36
Definition: follow_waypoint_controller.hpp:46
friend auto operator<<(StreamType &stream, const PredictedState &state) -> StreamType &
Definition: follow_waypoint_controller.hpp:66
double traveled_distance
Definition: follow_waypoint_controller.hpp:49
double acceleration
Definition: follow_waypoint_controller.hpp:47
double speed
Definition: follow_waypoint_controller.hpp:48
double travel_time
Definition: follow_waypoint_controller.hpp:50
auto moveStraight(const double step_acceleration, const double step_time) -> void
Definition: follow_waypoint_controller.hpp:52
auto isImmobile(const double tolerance) const
Definition: follow_waypoint_controller.hpp:60