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

RJD-1388/follow_trajectory #44

Open
wants to merge 82 commits into
base: master
Choose a base branch
from

Conversation

robomic
Copy link

@robomic robomic commented Nov 12, 2024

Abstract

This PR contains the refactor of follow_trajectory namespace, in particular makeUpdatedStatus function.

Details

  1. As functionalities have been divided into several files, this namespace now has its own follow_trajectory directory.
  2. ValidatedEntityStatus serves as a simple structure that holds repeatedly used variables. Its construction checks and validates numerous conditions that were previously handled in makeUpdatedStatus. An instance of ValidatedEntityStatus is passed as an argument to follow_trajectory::makeUpdatedEntityStatus.
  3. follow_trajectory::makeUpdatedEntityStatus is now the new entry point of the algorithm. It replaces the recursion from the original makeUpdatedStatus with a while loop, iterating over the trajectory.
  4. PolylineTrajectoryPositioner is responsible for a single step in the aforementioned while loop. In its constructor, it calculates several variables that were previously computed by lambdas in the makeUpdatedStatus function.
  5. PolylineTrajectoryPositioner::makeUpdatedEntityStatus contains what remains of the original makeUpdatedStatus, now focusing solely on its core logic.

References

Regressions TODO

@robomic robomic self-assigned this Nov 12, 2024
TauTheLepton and others added 18 commits December 18, 2024 19:28
Signed-off-by: Mateusz Palczuk <[email protected]>
…e polyline_trajectory_follower file to follow_trajectory

Signed-off-by: Mateusz Palczuk <[email protected]>
…e polyline_trajectory_follower file to follow_trajectory

Change include paths and include guards

Signed-off-by: Mateusz Palczuk <[email protected]>
Add "_" suffix to PolylineTrajectoryPositioner data fields

Modify distanceAlongLanelet function to take 2 different bounding boxes as arguments

Add comments on what data fields are implicitly required by functions used in PolylineTrajectoryPositioner constructor

Signed-off-by: Mateusz Palczuk <[email protected]>
…at is wrong, but passes github CI test

Signed-off-by: Mateusz Palczuk <[email protected]>
Signed-off-by: Mateusz Palczuk <[email protected]>
@robomic robomic requested a review from dmoszynski January 7, 2025 15:39
/// @note side effects on polyline_trajectory
auto makeUpdatedEntityStatus(
const ValidatedEntityStatus & validated_entity_status,
const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils_ptr,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please always pass std::shared_ptr<hdmap_utils::HdMapUtils> as the last argument - in the near future it will be removed, it is easier to make such changes for the last argument

@@ -30,11 +30,11 @@ namespace traffic_simulator
{
namespace follow_trajectory
{
struct ControllerError : public common::Error
struct ControllerError : public common::SimulationError

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -231,7 +231,7 @@ class FollowWaypointController
max_acceleration_rate{behavior_parameter.dynamic_constraints.max_acceleration_rate},
max_deceleration{behavior_parameter.dynamic_constraints.max_deceleration},
max_deceleration_rate{behavior_parameter.dynamic_constraints.max_deceleration_rate},
target_speed{(target_speed) ? target_speed.value() : max_speed}
target_speed{target_speed.value_or(max_speed)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -144,15 +144,15 @@ class EntityBase
virtual void requestLaneChange(const lanelet::Id)
{
/**
* @note There are Entities such as MiscObjectEntity for which lane change is not possible,
* @note There are Entities such as MiscObjectEntity for which lane change is not possible,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse changes in comments (even such as whitespace characters)

@@ -112,6 +112,14 @@ auto distanceToStopLine(
const traffic_simulator_msgs::msg::WaypointsArray & waypoints_array,
const lanelet::Id target_stop_line_id,
const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils_ptr) -> std::optional<double>;

auto distanceAlongLanelet(
const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils_ptr,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please always pass std::shared_ptr<hdmap_utils::HdMapUtils> as the last argument - in the near future it will be removed, it is easier to make such changes for the last argument

@@ -176,7 +178,7 @@ auto FollowWaypointController::clampAcceleration(
const double candidate_acceleration, const double acceleration, const double speed) const
-> double
{
auto [local_min_acceleration, local_max_acceleration] =
const auto && [local_min_acceleration, local_max_acceleration] =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto [local_min_acceleration, local_max_acceleration]

@@ -273,7 +275,7 @@ auto FollowWaypointController::getPredictedWaypointArrivalState(

// Count the distance and time of movement with constant speed, use this to prediction.
if (const double const_speed_distance = remaining_distance - state.traveled_distance;
const_speed_distance >= std::numeric_limits<double>::max() * const_speed_value) {
const_speed_distance == std::numeric_limits<double>::infinity()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const_speed_distance >= std::numeric_limits<double>::max() * const_speed_value)

@@ -334,7 +337,7 @@ auto FollowWaypointController::getAcceleration(
const double remaining_time_source, const double remaining_distance, const double acceleration,
const double speed) const -> double
{
const auto [local_min_acceleration, local_max_acceleration] =
const auto && [local_min_acceleration, local_max_acceleration] =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto && [local_min_acceleration, local_max_acceleration] =


if (const auto predicted_state_opt = getPredictedStopStateWithoutConsideringTime(
candidate_acceleration, remaining_distance, acceleration, speed);
predicted_state_opt) {
if (const auto distance_diff = remaining_distance - predicted_state_opt->traveled_distance;
(distance_diff >= 0 || min_distance_diff < 0) &&
if (const double distance_diff = remaining_distance - predicted_state_opt->traveled_distance;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why auto -> double?

@@ -311,5 +312,29 @@ auto distanceToStopLine(
return spline.getCollisionPointIn2D(polygon);
}
}

auto distanceAlongLanelet(
const std::shared_ptr<hdmap_utils::HdMapUtils> & hdmap_utils_ptr,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please always pass std::shared_ptr<hdmap_utils::HdMapUtils> as the last argument - in the near future it will be removed, it is easier to make such changes for the last argument

Comment on lines +324 to +337
if (const auto from_lanelet_pose =
hdmap_utils_ptr->toLaneletPose(from_position, from_bounding_box, false, matching_distance);
from_lanelet_pose.has_value()) {
if (const auto to_lanelet_pose =
hdmap_utils_ptr->toLaneletPose(to_position, to_bounding_box, false, matching_distance);
to_lanelet_pose.has_value()) {
if (const auto distance = hdmap_utils_ptr->getLongitudinalDistance(
from_lanelet_pose.value(), to_lanelet_pose.value());
distance.has_value()) {
return distance.value();
}
}
}
return math::geometry::hypot(from_position, to_position);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (const auto from_lanelet_pose =
hdmap_utils_ptr->toLaneletPose(from_position, from_bounding_box, false, matching_distance);
from_lanelet_pose.has_value()) {
if (const auto to_lanelet_pose =
hdmap_utils_ptr->toLaneletPose(to_position, to_bounding_box, false, matching_distance);
to_lanelet_pose.has_value()) {
if (const auto distance = hdmap_utils_ptr->getLongitudinalDistance(
from_lanelet_pose.value(), to_lanelet_pose.value());
distance.has_value()) {
return distance.value();
}
}
}
return math::geometry::hypot(from_position, to_position);
/// @note due to this hardcoded value, the method cannot be used for calculations along a crosswalk (for pedestrians)
constexpr auto include_crosswalk{false};
if (const auto from_lanelet_pose =
hdmap_utils_ptr->toLaneletPose(from_position, from_bounding_box, include_crosswalk, matching_distance)) {
if (const auto to_lanelet_pose =
hdmap_utils_ptr->toLaneletPose(to_position, to_bounding_box, include_crosswalk, matching_distance)) {
if (const auto distance = hdmap_utils_ptr->getLongitudinalDistance(
from_lanelet_pose.value(), to_lanelet_pose.value());
distance.has_value()) {
return distance.value();
}
}
}
return math::geometry::hypot(from_position, to_position);

Copy link

@dmoszynski dmoszynski Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of trouble I would not return the euclidean distance but std::optional,
only inside FollowTrajectoryAction I would implement if unable to calculate along the lane use euclidean - because it is a specific approach in FTA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants