Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
sci_strategic_plugin.hpp
Go to the documentation of this file.
1#pragma once
2
3/*
4 * Copyright (C) 2022 LEIDOS.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19#include <rclcpp/rclcpp.hpp>
20#include <string>
21#include <carma_planning_msgs/srv/plan_maneuvers.hpp>
22#include <carma_planning_msgs/msg/plugin.hpp>
23#include <carma_planning_msgs/msg/guidance_state.hpp>
24#include <carma_v2x_msgs/msg/mobility_operation.hpp>
27#include <carma_ros2_utils/carma_lifecycle_node.hpp>
28#include <bsm_helper/bsm_helper.h>
29#include <carma_wm/Geometry.hpp>
30#include <lanelet2_core/Forward.h>
31#include <gtest/gtest_prod.h>
32#include <boost/property_tree/ptree.hpp>
33#include <boost/property_tree/json_parser.hpp>
34#include <carma_v2x_msgs/msg/bsm.hpp>
35#include <boost/algorithm/string/split.hpp>
36#include <boost/algorithm/string/classification.hpp>
39
41{
45 Left
46};
47
49{
50public:
55 {
56 rclcpp::Time stamp; // Timestamp of this state data
57 double downtrack; // The downtrack of the vehicle along the route at time stamp
58 double speed; // The speed of the vehicle at time stamp
59 lanelet::Id lane_id; // The current lane id of the vehicle at time stamp
60 };
61
62
66 explicit SCIStrategicPlugin(const rclcpp::NodeOptions &);
67
73
81 std::shared_ptr<rmw_request_id_t> srv_header,
82 carma_planning_msgs::srv::PlanManeuvers::Request::SharedPtr req,
83 carma_planning_msgs::srv::PlanManeuvers::Response::SharedPtr resp);
84
88 rcl_interfaces::msg::SetParametersResult
89 parameter_update_callback(const std::vector<rclcpp::Parameter> &parameters);
90
96 void mobilityOperationCb(carma_v2x_msgs::msg::MobilityOperation::UniquePtr msg);
97
102 void currentPoseCb(geometry_msgs::msg::PoseStamped::UniquePtr msg);
103
118 carma_planning_msgs::msg::Maneuver composeLaneFollowingManeuverMessage(int case_num, double start_dist, double end_dist, double start_speed,
119 double target_speed, rclcpp::Time start_time, double time_to_stop,
120 std::vector<lanelet::Id> lane_ids);
121
122 carma_planning_msgs::msg::Maneuver composeStopAndWaitManeuverMessage(double current_dist, double end_dist, double start_speed,
123 const lanelet::Id& starting_lane_id, const lanelet::Id& ending_lane_id,
124 double stopping_accel, rclcpp::Time start_time, rclcpp::Time end_time) const;
125
126 carma_planning_msgs::msg::Maneuver composeIntersectionTransitMessage(double start_dist, double end_dist, double start_speed,
127 double target_speed, rclcpp::Time start_time, rclcpp::Time end_time, TurnDirection turn_direction,
128 const lanelet::Id& starting_lane_id, const lanelet::Id& ending_lane_id) const;
129
138 VehicleState extractInitialState(const carma_planning_msgs::srv::PlanManeuvers::Request& req) const;
139
145 std::vector<lanelet::ConstLanelet> getLaneletsBetweenWithException(double start_downtrack, double end_downtrack,
146 bool shortest_path_only = false,
147 bool bounds_inclusive = true) const;
148
149
159 double findSpeedLimit(const lanelet::ConstLanelet& llt) const;
160
161
175 int determine_speed_profile_case(double stop_dist, double current_speed, double schedule_stop_time, double speed_limit);
176
188 double calc_speed_before_decel(double stop_time, double stop_dist, double current_speed) const;
189
195 void parseStrategyParams(const std::string& strategy_params);
196
206 double calcEstimatedStopTime(double stop_dist, double current_speed) const;
207
220 void caseOneSpeedProfile(double speed_before_decel, double current_speed, double stop_time, std::vector<double>* float_metadata_list) const;
221
236 void caseTwoSpeedProfile(double stop_dist, double speed_before_decel, double current_speed, double stop_time, double speed_limit, std::vector<double>* float_metadata_list) const;
237
250 double caseThreeSpeedProfile(double stop_dist, double current_speed, double stop_time) const;
251
257 carma_v2x_msgs::msg::MobilityOperation generateMobilityOperation();
258
262 void BSMCb(carma_v2x_msgs::msg::BSM::UniquePtr msg);
263
268 void guidance_state_cb(const carma_planning_msgs::msg::GuidanceState::UniquePtr msg);
269
278 TurnDirection getTurnDirectionAtIntersection(std::vector<lanelet::ConstLanelet> lanelets_list);
279
281 carma_ros2_utils::CallbackReturn on_configure_plugin();
282 carma_ros2_utils::CallbackReturn on_activate_plugin();
283
284 bool get_availability();
285 std::string get_version_id();
286
287
289
290 // CARMA Streets Variakes
291 // timestamp for msg received from carma streets
292 unsigned long long street_msg_timestamp_ = 0;
293 // scheduled stop time
294 unsigned long long scheduled_stop_time_ = 0;
295 // scheduled enter time
296 unsigned long long scheduled_enter_time_ = 0;
297 // scheduled depart time
298 unsigned long long scheduled_depart_time_ = 0;
299 // scheduled latest depart position
300 uint32_t scheduled_departure_position_ = std::numeric_limits<uint32_t>::max();
301 // flag to show if the vehicle is allowed in intersection
302 bool is_allowed_int_ = false;
303
305 bool vehicle_engaged_ = false;
306
307 // approximate speed limit
308 double speed_limit_ = 100.0;
309
310 // downtrack of host vehicle
311 double current_downtrack_ = 0.0;
312
314
315 std::string bsm_id_ = "default_bsm_id";
316 uint8_t bsm_msg_count_ = 0;
317 uint16_t bsm_sec_mark_ = 0;
318
319 private:
320
321 carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::MobilityOperation> mob_operation_sub_;
322 carma_ros2_utils::SubPtr<geometry_msgs::msg::PoseStamped> current_pose_sub_;
323 carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::BSM> bsm_sub_;
324 carma_ros2_utils::PubPtr<carma_v2x_msgs::msg::MobilityOperation> mobility_operation_pub_;
325 carma_ros2_utils::SubPtr<carma_planning_msgs::msg::GuidanceState> guidance_state_sub_;
326
327 bool guidance_engaged_ = false;
328
329 // timer to publish mobility operation message
330 rclcpp::TimerBase::SharedPtr mob_op_pub_timer_;
331
334
337
339 boost::optional<double> intersection_speed_;
340 boost::optional<double> intersection_end_downtrack_;
341
342 // strategy for stop controlled intersection
343 std::string stop_controlled_intersection_strategy_ = "Carma/stop_controlled_intersection";
344 std::string previous_strategy_params_ = "";
345
346 // Unit test helper functions
348 void set_wm(carma_wm::WorldModelConstPtr new_wm) { wm_ = new_wm; }
349
350 // Unit Test Accessors
351 FRIEND_TEST(SCIStrategicPluginTest, findSpeedLimit);
352 FRIEND_TEST(SCIStrategicPluginTest, moboperationcbtest);
353 FRIEND_TEST(SCIStrategicPluginTest, parseStrategyParamstest);
354 FRIEND_TEST(SCIStrategicPluginTest, calcEstimatedStopTimetest);
355 FRIEND_TEST(SCIStrategicPluginTest, calc_speed_before_deceltest);
356 FRIEND_TEST(SCIStrategicPluginTest, determine_speed_profile_casetest);
357 FRIEND_TEST(SCIStrategicPluginTest, caseOneSpeedProfiletest);
358 FRIEND_TEST(SCIStrategicPluginTest, caseTwoSpeedProfiletest);
359 FRIEND_TEST(SCIStrategicPluginTest, caseThreeSpeedProfiletest);
360 FRIEND_TEST(SCIStrategicPluginTest, testIntersectionturndirection);
361 FRIEND_TEST(SCIStrategicPluginTest, DISABLED_maneuvercbtest);
362 FRIEND_TEST(SCIStrategicPluginTest, maneuvercbtest);
363};
364} // namespace sci_strategic_plugin
StrategicPlugin base class which can be extended by user provided plugins which wish to implement the...
FRIEND_TEST(SCIStrategicPluginTest, maneuvercbtest)
carma_wm::WorldModelConstPtr wm_
World Model pointer.
std::vector< lanelet::ConstLanelet > getLaneletsBetweenWithException(double start_downtrack, double end_downtrack, bool shortest_path_only=false, bool bounds_inclusive=true) const
Helper method which calls carma_wm::WorldModel::getLaneletsBetween(start_downtrack,...
FRIEND_TEST(SCIStrategicPluginTest, moboperationcbtest)
void set_wm(carma_wm::WorldModelConstPtr new_wm)
double calcEstimatedStopTime(double stop_dist, double current_speed) const
calculate the time vehicle will stop with optimal decelarion
void guidance_state_cb(const carma_planning_msgs::msg::GuidanceState::UniquePtr msg)
Callback for the Guidance State.
int determine_speed_profile_case(double stop_dist, double current_speed, double schedule_stop_time, double speed_limit)
Determine the speed profile case fpr approaching an intersection.
carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseStamped > current_pose_sub_
VehicleState extractInitialState(const carma_planning_msgs::srv::PlanManeuvers::Request &req) const
Helper method to extract the initial vehicle state from the planning request method based on if the p...
void parseStrategyParams(const std::string &strategy_params)
parse strategy parameters
FRIEND_TEST(SCIStrategicPluginTest, caseTwoSpeedProfiletest)
void BSMCb(carma_v2x_msgs::msg::BSM::UniquePtr msg)
BSM callback function.
TurnDirection getTurnDirectionAtIntersection(std::vector< lanelet::ConstLanelet > lanelets_list)
Determine the turn direction at intersection.
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Callback for dynamic parameter updates.
FRIEND_TEST(SCIStrategicPluginTest, determine_speed_profile_casetest)
double caseThreeSpeedProfile(double stop_dist, double current_speed, double stop_time) const
Determine the desired speed profile parameters for Case 3.
FRIEND_TEST(SCIStrategicPluginTest, caseOneSpeedProfiletest)
void plan_maneuvers_callback(std::shared_ptr< rmw_request_id_t > srv_header, carma_planning_msgs::srv::PlanManeuvers::Request::SharedPtr req, carma_planning_msgs::srv::PlanManeuvers::Response::SharedPtr resp)
Service callback for arbitrator maneuver planning.
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::GuidanceState > guidance_state_sub_
carma_ros2_utils::CallbackReturn on_activate_plugin()
Method which is triggered when this plugin is moved from the INACTIVE to ACTIVE states....
rclcpp::TimerBase::SharedPtr mob_op_pub_timer_
bool get_availability()
Get the availability status of this plugin based on the current operating environment....
FRIEND_TEST(SCIStrategicPluginTest, parseStrategyParamstest)
FRIEND_TEST(SCIStrategicPluginTest, calc_speed_before_deceltest)
carma_ros2_utils::PubPtr< carma_v2x_msgs::msg::MobilityOperation > mobility_operation_pub_
void currentPoseCb(geometry_msgs::msg::PoseStamped::UniquePtr msg)
callback function for current pose
void publishMobilityOperation()
Method to publish mobility operation msgs at a fixed rate of 10hz if approaching intersection.
boost::optional< double > intersection_end_downtrack_
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::MobilityOperation > mob_operation_sub_
carma_ros2_utils::CallbackReturn on_configure_plugin()
Method which is triggered when this plugin is moved from the UNCONFIGURED to INACTIVE states....
carma_planning_msgs::msg::Maneuver composeIntersectionTransitMessage(double start_dist, double end_dist, double start_speed, double target_speed, rclcpp::Time start_time, rclcpp::Time end_time, TurnDirection turn_direction, const lanelet::Id &starting_lane_id, const lanelet::Id &ending_lane_id) const
FRIEND_TEST(SCIStrategicPluginTest, caseThreeSpeedProfiletest)
FRIEND_TEST(SCIStrategicPluginTest, DISABLED_maneuvercbtest)
double calc_speed_before_decel(double stop_time, double stop_dist, double current_speed) const
calculate the speed, right before the car starts to decelerate for stopping
SCIStrategicPluginConfig config_
Config containing configurable algorithm parameters.
carma_v2x_msgs::msg::MobilityOperation generateMobilityOperation()
Generates Mobility Operation messages.
void mobilityOperationCb(carma_v2x_msgs::msg::MobilityOperation::UniquePtr msg)
callback function for mobility operation
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::BSM > bsm_sub_
FRIEND_TEST(SCIStrategicPluginTest, findSpeedLimit)
double findSpeedLimit(const lanelet::ConstLanelet &llt) const
Given a Lanelet, find it's associated Speed Limit.
std::string get_version_id()
Returns the version id of this plugin.
boost::optional< double > intersection_speed_
Cache variables for storing the current intersection state between state machine transitions.
FRIEND_TEST(SCIStrategicPluginTest, testIntersectionturndirection)
void caseOneSpeedProfile(double speed_before_decel, double current_speed, double stop_time, std::vector< double > *float_metadata_list) const
Determine the desired speed profile parameters for Case 1.
carma_planning_msgs::msg::Maneuver composeStopAndWaitManeuverMessage(double current_dist, double end_dist, double start_speed, const lanelet::Id &starting_lane_id, const lanelet::Id &ending_lane_id, double stopping_accel, rclcpp::Time start_time, rclcpp::Time end_time) const
SCIStrategicPlugin(const rclcpp::NodeOptions &)
Default constructor for RouteFollowingPlugin class.
carma_planning_msgs::msg::Maneuver composeLaneFollowingManeuverMessage(int case_num, double start_dist, double end_dist, double start_speed, double target_speed, rclcpp::Time start_time, double time_to_stop, std::vector< lanelet::Id > lane_ids)
Compose a lane keeping maneuver message based on input params.
void caseTwoSpeedProfile(double stop_dist, double speed_before_decel, double current_speed, double stop_time, double speed_limit, std::vector< double > *float_metadata_list) const
Determine the desired speed profile parameters for Case 2.
FRIEND_TEST(SCIStrategicPluginTest, calcEstimatedStopTimetest)
std::shared_ptr< const WorldModel > WorldModelConstPtr
Definition: WorldModel.hpp:452
Struct to store the configuration settings for the WzStrategicPlugin class.
Struct representing a vehicle state for the purposes of planning.