Skip to content

Commit 323a1ac

Browse files
committed
Replaced hardcoded values with named constants.
1 parent fcaa48d commit 323a1ac

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/follow_lane_sequence/follow_front_entity_action.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class FollowFrontEntityAction : public entity_behavior::VehicleActionNode
4242

4343
private:
4444
std::optional<double> distance_to_front_entity_;
45+
static constexpr double kWaypointInterval = 1.0;
46+
static constexpr double kFrontEntityMargin = 5.0;
47+
static constexpr double kSpeedStep = 2.0;
4548
};
4649
} // namespace follow_lane_sequence
4750
} // namespace vehicle

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/follow_lane_sequence/follow_lane_action.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class FollowLaneAction : public entity_behavior::VehicleActionNode
4343

4444
private:
4545
std::optional<traffic_simulator::LaneletPose> target_lanelet_pose_;
46+
static constexpr double kWaypointInterval = 1.0;
47+
static constexpr double kFrontEntityStopMargin = 5.0;
48+
static constexpr double kBoundingBoxHalfFactor = 0.5;
49+
static constexpr double kStopLineMargin = 5.0;
50+
static constexpr double kConflictingEntityMargin = 3.0;
4651
};
4752
} // namespace follow_lane_sequence
4853
} // namespace vehicle

simulation/behavior_tree_plugin/include/behavior_tree_plugin/vehicle/follow_lane_sequence/stop_at_stop_line_action.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class StopAtStopLineAction : public entity_behavior::VehicleActionNode
4343

4444
private:
4545
std::optional<double> distance_to_stopline_;
46+
static constexpr double kWaypointInterval = 1.0;
47+
static constexpr double kBoundingBoxHalfFactor = 0.5;
48+
static constexpr double kStopMargin = 1.0;
49+
static constexpr double kFrontStoplineMargin = 5.0;
50+
static constexpr double kVelocityEpsilon = 0.001;
4651
};
4752
} // namespace follow_lane_sequence
4853
} // namespace vehicle

simulation/behavior_tree_plugin/src/vehicle/follow_lane_sequence/follow_front_entity_action.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const traffic_simulator_msgs::msg::WaypointsArray FollowFrontEntityAction::calcu
6060
double horizon = getHorizon();
6161
const auto lanelet_pose = canonicalized_entity_status_->getLaneletPose();
6262
waypoints.waypoints = reference_trajectory->getTrajectory(
63-
lanelet_pose.s, lanelet_pose.s + horizon, 1.0, lanelet_pose.offset);
63+
lanelet_pose.s, lanelet_pose.s + horizon, kWaypointInterval, lanelet_pose.offset);
6464
trajectory = std::make_unique<math::geometry::CatmullRomSubspline>(
6565
reference_trajectory, lanelet_pose.s, lanelet_pose.s + horizon);
6666
return waypoints;
@@ -127,15 +127,17 @@ BT::NodeStatus FollowFrontEntityAction::tick()
127127
if (
128128
distance_to_front_entity_.value() >=
129129
(calculateStopDistance(behavior_parameter_.dynamic_constraints) +
130-
vehicle_parameters.bounding_box.dimensions.x + 5)) {
131-
setCanonicalizedEntityStatus(calculateUpdatedEntityStatus(front_entity_linear_velocity + 2));
130+
vehicle_parameters.bounding_box.dimensions.x + kFrontEntityMargin)) {
131+
setCanonicalizedEntityStatus(
132+
calculateUpdatedEntityStatus(front_entity_linear_velocity + kSpeedStep));
132133
setOutput("waypoints", waypoints);
133134
setOutput("obstacle", calculateObstacle(waypoints));
134135
return BT::NodeStatus::RUNNING;
135136
} else if (
136137
distance_to_front_entity_.value() <=
137138
calculateStopDistance(behavior_parameter_.dynamic_constraints)) {
138-
setCanonicalizedEntityStatus(calculateUpdatedEntityStatus(front_entity_linear_velocity - 2));
139+
setCanonicalizedEntityStatus(
140+
calculateUpdatedEntityStatus(front_entity_linear_velocity - kSpeedStep));
139141
setOutput("waypoints", waypoints);
140142
setOutput("obstacle", calculateObstacle(waypoints));
141143
return BT::NodeStatus::RUNNING;

simulation/behavior_tree_plugin/src/vehicle/follow_lane_sequence/follow_lane_action.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const traffic_simulator_msgs::msg::WaypointsArray FollowLaneAction::calculateWay
4646
traffic_simulator_msgs::msg::WaypointsArray waypoints;
4747
const auto lanelet_pose = canonicalized_entity_status_->getLaneletPose();
4848
waypoints.waypoints = reference_trajectory->getTrajectory(
49-
lanelet_pose.s, lanelet_pose.s + getHorizon(), 1.0, lanelet_pose.offset);
49+
lanelet_pose.s, lanelet_pose.s + getHorizon(), kWaypointInterval, lanelet_pose.offset);
5050
trajectory = std::make_unique<math::geometry::CatmullRomSubspline>(
5151
reference_trajectory, lanelet_pose.s, lanelet_pose.s + getHorizon());
5252
return waypoints;
@@ -97,7 +97,7 @@ BT::NodeStatus FollowLaneAction::tick()
9797
if (
9898
distance_to_front_entity.value() <=
9999
calculateStopDistance(behavior_parameter_.dynamic_constraints) +
100-
vehicle_parameters.bounding_box.dimensions.x + 5) {
100+
vehicle_parameters.bounding_box.dimensions.x + kFrontEntityStopMargin) {
101101
return BT::NodeStatus::FAILURE;
102102
}
103103
}
@@ -116,14 +116,14 @@ BT::NodeStatus FollowLaneAction::tick()
116116
if (
117117
distance_to_stopline.value() <=
118118
calculateStopDistance(behavior_parameter_.dynamic_constraints) +
119-
vehicle_parameters.bounding_box.dimensions.x * 0.5 + 5) {
119+
vehicle_parameters.bounding_box.dimensions.x * kBoundingBoxHalfFactor + kStopLineMargin) {
120120
return BT::NodeStatus::FAILURE;
121121
}
122122
}
123123
if (distance_to_conflicting_entity) {
124124
if (
125125
distance_to_conflicting_entity.value() <
126-
(vehicle_parameters.bounding_box.dimensions.x + 3 +
126+
(vehicle_parameters.bounding_box.dimensions.x + kConflictingEntityMargin +
127127
calculateStopDistance(behavior_parameter_.dynamic_constraints))) {
128128
return BT::NodeStatus::FAILURE;
129129
}

simulation/behavior_tree_plugin/src/vehicle/follow_lane_sequence/stop_at_stop_line_action.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const traffic_simulator_msgs::msg::WaypointsArray StopAtStopLineAction::calculat
5757
double horizon = getHorizon();
5858
const auto lanelet_pose = canonicalized_entity_status_->getLaneletPose();
5959
waypoints.waypoints = reference_trajectory->getTrajectory(
60-
lanelet_pose.s, lanelet_pose.s + horizon, 1.0, lanelet_pose.offset);
60+
lanelet_pose.s, lanelet_pose.s + horizon, kWaypointInterval, lanelet_pose.offset);
6161
trajectory = std::make_unique<math::geometry::CatmullRomSubspline>(
6262
reference_trajectory, lanelet_pose.s, lanelet_pose.s + horizon);
6363
return waypoints;
@@ -75,7 +75,8 @@ std::optional<double> StopAtStopLineAction::calculateTargetSpeed(double current_
7575
* @brief hard coded parameter!! 1.0 is a stop margin
7676
*/
7777
double rest_distance =
78-
distance_to_stopline_.value() - (vehicle_parameters.bounding_box.dimensions.x * 0.5 + 1.0);
78+
distance_to_stopline_.value() -
79+
(vehicle_parameters.bounding_box.dimensions.x * kBoundingBoxHalfFactor + kStopMargin);
7980
if (rest_distance < calculateStopDistance(behavior_parameter_.dynamic_constraints)) {
8081
return 0;
8182
}
@@ -124,9 +125,11 @@ BT::NodeStatus StopAtStopLineAction::tick()
124125
}
125126
}
126127

127-
if (std::fabs(canonicalized_entity_status_->getTwist().linear.x) < 0.001) {
128+
if (std::fabs(canonicalized_entity_status_->getTwist().linear.x) < kVelocityEpsilon) {
128129
if (distance_to_stopline_) {
129-
if (distance_to_stopline_.value() <= vehicle_parameters.bounding_box.dimensions.x + 5) {
130+
if (
131+
distance_to_stopline_.value() <=
132+
vehicle_parameters.bounding_box.dimensions.x + kFrontStoplineMargin) {
130133
if (!target_speed_) {
131134
target_speed_ = hdmap_utils_->getSpeedLimit(route_lanelets_);
132135
}

0 commit comments

Comments
 (0)