Skip to content

Commit 6d0b20a

Browse files
authoredDec 4, 2023
refactor(run_out): boost::optional to std::optional (#5760)
Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent 5dc7878 commit 6d0b20a

File tree

6 files changed

+32
-38
lines changed

6 files changed

+32
-38
lines changed
 

‎planning/behavior_velocity_run_out_module/src/dynamic_obstacle.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pcl::PointCloud<pcl::PointXYZ> extractLateralNearestPoints(
238238
return lateral_nearest_points;
239239
}
240240

241-
boost::optional<Eigen::Affine3f> getTransformMatrix(
241+
std::optional<Eigen::Affine3f> getTransformMatrix(
242242
const tf2_ros::Buffer & tf_buffer, const std::string & target_frame_id,
243243
const std::string & source_frame_id, const builtin_interfaces::msg::Time & stamp)
244244
{

‎planning/behavior_velocity_run_out_module/src/scene.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool RunOutModule::modifyPathVelocity(
136136
return true;
137137
}
138138

139-
boost::optional<DynamicObstacle> RunOutModule::detectCollision(
139+
std::optional<DynamicObstacle> RunOutModule::detectCollision(
140140
const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path)
141141
{
142142
if (path.points.size() < 2) {
@@ -197,7 +197,7 @@ boost::optional<DynamicObstacle> RunOutModule::detectCollision(
197197
return {};
198198
}
199199

200-
boost::optional<DynamicObstacle> RunOutModule::findNearestCollisionObstacle(
200+
std::optional<DynamicObstacle> RunOutModule::findNearestCollisionObstacle(
201201
const PathWithLaneId & path, const geometry_msgs::msg::Pose & base_pose,
202202
std::vector<DynamicObstacle> & dynamic_obstacles) const
203203
{
@@ -337,7 +337,7 @@ std::vector<DynamicObstacle> RunOutModule::checkCollisionWithObstacles(
337337

338338
// calculate the predicted pose of the obstacle on the predicted path with given travel time
339339
// assume that the obstacle moves with constant velocity
340-
boost::optional<geometry_msgs::msg::Pose> RunOutModule::calcPredictedObstaclePose(
340+
std::optional<geometry_msgs::msg::Pose> RunOutModule::calcPredictedObstaclePose(
341341
const std::vector<PredictedPath> & predicted_paths, const float travel_time,
342342
const float velocity_mps) const
343343
{
@@ -509,7 +509,7 @@ bool RunOutModule::checkCollisionWithPolygon() const
509509
}
510510

511511
std::optional<geometry_msgs::msg::Pose> RunOutModule::calcStopPoint(
512-
const boost::optional<DynamicObstacle> & dynamic_obstacle, const PathWithLaneId & path,
512+
const std::optional<DynamicObstacle> & dynamic_obstacle, const PathWithLaneId & path,
513513
const geometry_msgs::msg::Pose & current_pose, const float current_vel,
514514
const float current_acc) const
515515
{
@@ -625,7 +625,7 @@ void RunOutModule::insertStopPoint(
625625
}
626626

627627
void RunOutModule::insertVelocityForState(
628-
const boost::optional<DynamicObstacle> & dynamic_obstacle, const PlannerData planner_data,
628+
const std::optional<DynamicObstacle> & dynamic_obstacle, const PlannerData planner_data,
629629
const PlannerParam & planner_param, const PathWithLaneId & smoothed_path,
630630
PathWithLaneId & output_path)
631631
{
@@ -684,7 +684,7 @@ void RunOutModule::insertVelocityForState(
684684
}
685685

686686
void RunOutModule::insertStoppingVelocity(
687-
const boost::optional<DynamicObstacle> & dynamic_obstacle,
687+
const std::optional<DynamicObstacle> & dynamic_obstacle,
688688
const geometry_msgs::msg::Pose & current_pose, const float current_vel, const float current_acc,
689689
PathWithLaneId & output_path)
690690
{
@@ -739,7 +739,7 @@ void RunOutModule::applyMaxJerkLimit(
739739
return;
740740
}
741741

742-
const auto stop_point = path.points.at(stop_point_idx.get()).point.pose.position;
742+
const auto stop_point = path.points.at(stop_point_idx.value()).point.pose.position;
743743
const auto dist_to_stop_point =
744744
motion_utils::calcSignedArcLength(path.points, current_pose.position, stop_point);
745745

@@ -749,7 +749,7 @@ void RunOutModule::applyMaxJerkLimit(
749749
current_vel, dist_to_stop_point);
750750

751751
// overwrite velocity with limited velocity
752-
run_out_utils::insertPathVelocityFromIndex(stop_point_idx.get(), jerk_limited_vel, path.points);
752+
run_out_utils::insertPathVelocityFromIndex(stop_point_idx.value(), jerk_limited_vel, path.points);
753753
}
754754

755755
std::vector<DynamicObstacle> RunOutModule::excludeObstaclesOutSideOfPartition(
@@ -782,7 +782,7 @@ std::vector<DynamicObstacle> RunOutModule::excludeObstaclesOutSideOfPartition(
782782

783783
void RunOutModule::publishDebugValue(
784784
const PathWithLaneId & path, const std::vector<DynamicObstacle> extracted_obstacles,
785-
const boost::optional<DynamicObstacle> & dynamic_obstacle,
785+
const std::optional<DynamicObstacle> & dynamic_obstacle,
786786
const geometry_msgs::msg::Pose & current_pose) const
787787
{
788788
if (dynamic_obstacle) {

‎planning/behavior_velocity_run_out_module/src/scene.hpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@
2424

2525
#include <memory>
2626
#include <optional>
27-
#include <string>
2827
#include <vector>
2928

3029
namespace behavior_velocity_planner
3130
{
32-
namespace bg = boost::geometry;
3331
using autoware_auto_perception_msgs::msg::PredictedObjects;
3432
using autoware_auto_planning_msgs::msg::PathPointWithLaneId;
3533
using autoware_auto_planning_msgs::msg::PathWithLaneId;
@@ -68,7 +66,7 @@ class RunOutModule : public SceneModuleInterface
6866
// Function
6967
Polygons2d createDetectionAreaPolygon(const PathWithLaneId & smoothed_path) const;
7068

71-
boost::optional<DynamicObstacle> detectCollision(
69+
std::optional<DynamicObstacle> detectCollision(
7270
const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path_points);
7371

7472
float calcCollisionPositionOfVehicleSide(
@@ -81,11 +79,11 @@ class RunOutModule : public SceneModuleInterface
8179
const std::vector<DynamicObstacle> & dynamic_obstacles,
8280
std::vector<geometry_msgs::msg::Point> poly, const float travel_time) const;
8381

84-
boost::optional<DynamicObstacle> findNearestCollisionObstacle(
82+
std::optional<DynamicObstacle> findNearestCollisionObstacle(
8583
const PathWithLaneId & path, const geometry_msgs::msg::Pose & base_pose,
8684
std::vector<DynamicObstacle> & dynamic_obstacles) const;
8785

88-
boost::optional<geometry_msgs::msg::Pose> calcPredictedObstaclePose(
86+
std::optional<geometry_msgs::msg::Pose> calcPredictedObstaclePose(
8987
const std::vector<PredictedPath> & predicted_paths, const float travel_time,
9088
const float velocity_mps) const;
9189

@@ -108,7 +106,7 @@ class RunOutModule : public SceneModuleInterface
108106
const PoseWithRange & pose_with_range, const float x_offset, const float y_offset) const;
109107

110108
std::optional<geometry_msgs::msg::Pose> calcStopPoint(
111-
const boost::optional<DynamicObstacle> & dynamic_obstacle, const PathWithLaneId & path,
109+
const std::optional<DynamicObstacle> & dynamic_obstacle, const PathWithLaneId & path,
112110
const geometry_msgs::msg::Pose & current_pose, const float current_vel,
113111
const float current_acc) const;
114112

@@ -117,12 +115,12 @@ class RunOutModule : public SceneModuleInterface
117115
autoware_auto_planning_msgs::msg::PathWithLaneId & path);
118116

119117
void insertVelocityForState(
120-
const boost::optional<DynamicObstacle> & dynamic_obstacle, const PlannerData planner_data,
118+
const std::optional<DynamicObstacle> & dynamic_obstacle, const PlannerData planner_data,
121119
const PlannerParam & planner_param, const PathWithLaneId & smoothed_path,
122120
PathWithLaneId & output_path);
123121

124122
void insertStoppingVelocity(
125-
const boost::optional<DynamicObstacle> & dynamic_obstacle,
123+
const std::optional<DynamicObstacle> & dynamic_obstacle,
126124
const geometry_msgs::msg::Pose & current_pose, const float current_vel, const float current_acc,
127125
PathWithLaneId & output_path);
128126

@@ -140,7 +138,7 @@ class RunOutModule : public SceneModuleInterface
140138

141139
void publishDebugValue(
142140
const PathWithLaneId & path, const std::vector<DynamicObstacle> extracted_obstacles,
143-
const boost::optional<DynamicObstacle> & dynamic_obstacle,
141+
const std::optional<DynamicObstacle> & dynamic_obstacle,
144142
const geometry_msgs::msg::Pose & current_pose) const;
145143

146144
bool isMomentaryDetection();

‎planning/behavior_velocity_run_out_module/src/state_machine.hpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717

1818
#include "utils.hpp"
1919

20-
#include <memory>
2120
#include <string>
2221

23-
namespace behavior_velocity_planner
24-
{
25-
namespace run_out_utils
22+
namespace behavior_velocity_planner::run_out_utils
2623
{
2724

2825
class StateMachine
@@ -37,26 +34,25 @@ class StateMachine
3734

3835
struct StateInput
3936
{
40-
double current_velocity;
41-
double dist_to_collision;
42-
boost::optional<DynamicObstacle> current_obstacle;
37+
double current_velocity{};
38+
double dist_to_collision{};
39+
std::optional<DynamicObstacle> current_obstacle;
4340
};
4441

4542
explicit StateMachine(const StateParam & state_param) { state_param_ = state_param; }
4643
State getCurrentState() const { return state_; }
47-
boost::optional<DynamicObstacle> getTargetObstacle() const { return target_obstacle_; }
44+
std::optional<DynamicObstacle> getTargetObstacle() const { return target_obstacle_; }
4845
std::string toString(const State & state) const;
4946
void updateState(const StateInput & state_input, rclcpp::Clock & clock);
5047

5148
private:
52-
StateParam state_param_;
49+
StateParam state_param_{};
5350
State state_{State::GO};
5451
rclcpp::Time stop_time_;
5552
rclcpp::Time prev_approach_time_;
56-
boost::optional<DynamicObstacle> prev_obstacle_{};
57-
boost::optional<DynamicObstacle> target_obstacle_{};
53+
std::optional<DynamicObstacle> prev_obstacle_{};
54+
std::optional<DynamicObstacle> target_obstacle_{};
5855
};
59-
} // namespace run_out_utils
60-
} // namespace behavior_velocity_planner
56+
} // namespace behavior_velocity_planner::run_out_utils
6157

6258
#endif // STATE_MACHINE_HPP_

‎planning/behavior_velocity_run_out_module/src/utils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ bool isSamePoint(const geometry_msgs::msg::Point & p1, const geometry_msgs::msg:
133133
}
134134

135135
// if path points have the same point as target_point, return the index
136-
boost::optional<size_t> haveSamePoint(
136+
std::optional<size_t> haveSamePoint(
137137
const PathPointsWithLaneId & path_points, const geometry_msgs::msg::Point & target_point)
138138
{
139139
for (size_t i = 0; i < path_points.size(); i++) {
@@ -164,7 +164,7 @@ void insertPathVelocityFromIndex(
164164
}
165165
}
166166

167-
boost::optional<size_t> findFirstStopPointIdx(PathPointsWithLaneId & path_points)
167+
std::optional<size_t> findFirstStopPointIdx(PathPointsWithLaneId & path_points)
168168
{
169169
for (size_t i = 0; i < path_points.size(); i++) {
170170
const auto vel = path_points.at(i).point.longitudinal_velocity_mps;
@@ -272,7 +272,7 @@ PathWithLaneId trimPathFromSelfPose(
272272

273273
// create polygon for passing lines and deceleration line calculated by stopping jerk
274274
// note that this polygon is not closed
275-
boost::optional<std::vector<geometry_msgs::msg::Point>> createDetectionAreaPolygon(
275+
std::optional<std::vector<geometry_msgs::msg::Point>> createDetectionAreaPolygon(
276276
const std::vector<std::vector<geometry_msgs::msg::Point>> & passing_lines,
277277
const size_t deceleration_line_idx)
278278
{

‎planning/behavior_velocity_run_out_module/src/utils.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ std::vector<geometry_msgs::msg::Point> findLateralSameSidePoints(
209209
bool isSamePoint(const geometry_msgs::msg::Point & p1, const geometry_msgs::msg::Point & p2);
210210

211211
// if path points have the same point as target_point, return the index
212-
boost::optional<size_t> haveSamePoint(
212+
std::optional<size_t> haveSamePoint(
213213
const PathPointsWithLaneId & path_points, const geometry_msgs::msg::Point & target_point);
214214

215215
// insert path velocity which doesn't exceed original velocity
@@ -219,7 +219,7 @@ void insertPathVelocityFromIndexLimited(
219219
void insertPathVelocityFromIndex(
220220
const size_t & start_idx, const float velocity_mps, PathPointsWithLaneId & path_points);
221221

222-
boost::optional<size_t> findFirstStopPointIdx(PathPointsWithLaneId & path_points);
222+
std::optional<size_t> findFirstStopPointIdx(PathPointsWithLaneId & path_points);
223223

224224
LineString2d createLineString2d(const lanelet::BasicPolygon2d & poly);
225225

@@ -237,7 +237,7 @@ PathWithLaneId trimPathFromSelfPose(
237237

238238
// create polygon for passing lines and deceleration line calculated by stopping jerk
239239
// note that this polygon is not closed
240-
boost::optional<std::vector<geometry_msgs::msg::Point>> createDetectionAreaPolygon(
240+
std::optional<std::vector<geometry_msgs::msg::Point>> createDetectionAreaPolygon(
241241
const std::vector<std::vector<geometry_msgs::msg::Point>> & passing_lines,
242242
const size_t deceleration_line_idx);
243243

0 commit comments

Comments
 (0)
Please sign in to comment.