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.
arbitrator::ArbitratorNode Class Reference

#include <arbitrator_node.hpp>

Inheritance diagram for arbitrator::ArbitratorNode:
Inheritance graph
Collaboration diagram for arbitrator::ArbitratorNode:
Collaboration graph

Public Member Functions

 ArbitratorNode (const rclcpp::NodeOptions &options)
 Constructor. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &)
 
carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &)
 

Private Member Functions

std::map< std::string, double > plugin_priorities_map_from_json (const std::string &json_string)
 

Private Attributes

carma_ros2_utils::SubPtr< geometry_msgs::msg::TwistStamped > twist_sub_
 
Config config_
 
std::shared_ptr< carma_wm::WMListenerwm_listener_
 
carma_wm::WorldModelConstPtr wm_
 
std::shared_ptr< Arbitratorarbitrator_
 
rclcpp::TimerBase::SharedPtr bumper_pose_timer_
 
rclcpp::TimerBase::SharedPtr arbitrator_run_
 

Detailed Description

An arbitrator node instance with currently used configuration/planning paradigms

Governs the interactions of plugins during the maneuver planning phase of the CARMA planning process by internally using a worker class with generic planning interface.

Definition at line 49 of file arbitrator_node.hpp.

Constructor & Destructor Documentation

◆ ArbitratorNode()

arbitrator::ArbitratorNode::ArbitratorNode ( const rclcpp::NodeOptions &  options)
explicit

Constructor.

Definition at line 22 of file arbitrator_node.cpp.

22 : carma_ros2_utils::CarmaLifecycleNode(options)
23 {
24 // Create initial config
25 config_ = Config();
26
27 config_.min_plan_duration = declare_parameter<double>("min_plan_duration", config_.min_plan_duration);
28 config_.target_plan_duration = declare_parameter<double>("target_plan_duration", config_.target_plan_duration);
29 config_.planning_frequency = declare_parameter<double>("planning_frequency", config_.planning_frequency);
30 config_.beam_width = declare_parameter<int>("beam_width", config_.beam_width);
31 config_.use_fixed_costs = declare_parameter<bool>("use_fixed_costs", config_.use_fixed_costs);
32 config_.plugin_priorities = plugin_priorities_map_from_json(declare_parameter<std::string>("plugin_priorities", ""));
33 }
std::map< std::string, double > plugin_priorities_map_from_json(const std::string &json_string)
std::map< std::string, double > plugin_priorities

References arbitrator::Config::beam_width, config_, arbitrator::Config::min_plan_duration, arbitrator::Config::planning_frequency, arbitrator::Config::plugin_priorities, plugin_priorities_map_from_json(), arbitrator::Config::target_plan_duration, and arbitrator::Config::use_fixed_costs.

Here is the call graph for this function:

Member Function Documentation

◆ handle_on_activate()

carma_ros2_utils::CallbackReturn arbitrator::ArbitratorNode::handle_on_activate ( const rclcpp_lifecycle::State &  )

Definition at line 96 of file arbitrator_node.cpp.

97 {
98 bumper_pose_timer_ = create_timer(get_clock(),
99 std::chrono::milliseconds(100),
100 [this]() {this->arbitrator_->bumper_pose_cb();});
101
102 arbitrator_run_ = create_timer(get_clock(),
103 std::chrono::duration<double>(1/(config_.planning_frequency * 2 )), //there is waiting state between each planning state
104 [this]() {this->arbitrator_->run();});
105 //The intention is to keep the arbitrator planning at intended frequency - 1s. Looks like ROS2 conversion kept the WAITING state from ROS1,
106 //which occurs between PLANNING state in the state machine. So if the timer calls state callback each 1 second, the arbitrator ends up planning
107 //every 2s due to PLANNING > WAITING > PLANNING transition. That's why the frequency is doubled.
108 RCLCPP_INFO_STREAM(rclcpp::get_logger("arbitrator"), "Arbitrator started, beginning arbitrator state machine.");
109 return CallbackReturn::SUCCESS;
110 }
rclcpp::TimerBase::SharedPtr bumper_pose_timer_
rclcpp::TimerBase::SharedPtr arbitrator_run_
std::shared_ptr< Arbitrator > arbitrator_

References arbitrator_, arbitrator_run_, bumper_pose_timer_, config_, and arbitrator::Config::planning_frequency.

◆ handle_on_configure()

carma_ros2_utils::CallbackReturn arbitrator::ArbitratorNode::handle_on_configure ( const rclcpp_lifecycle::State &  )

Definition at line 35 of file arbitrator_node.cpp.

36 {
37 // Handle dependency injection
38 auto ci = std::make_shared<arbitrator::CapabilitiesInterface>(shared_from_this());
40
41 // Reset config
42 config_ = Config();
43
44 get_parameter<double>("min_plan_duration", config_.min_plan_duration);
45 get_parameter<double>("target_plan_duration", config_.target_plan_duration);
46 get_parameter<double>("planning_frequency", config_.planning_frequency);
47 get_parameter<int>("beam_width", config_.beam_width);
48 get_parameter<bool>("use_fixed_costs", config_.use_fixed_costs);
49 std::string json_string;
50 get_parameter<std::string>("plugin_priorities", json_string);
51
53
54 RCLCPP_INFO_STREAM(rclcpp::get_logger("arbitrator"), "Arbitrator Loaded Params: " << config_);
55
56 std::shared_ptr<arbitrator::CostFunction> cf;
58
61 cf = std::make_shared<arbitrator::FixedPriorityCostFunction>(fpcf);
62 } else {
63 cscf.init(shared_from_this());
64 cf = std::make_shared<arbitrator::CostSystemCostFunction>(cscf);
65 }
66
67 auto bss = std::make_shared<arbitrator::BeamSearchStrategy>(config_.beam_width);
68
69 auto png = std::make_shared<arbitrator::PluginNeighborGenerator<arbitrator::CapabilitiesInterface>>(ci);
70 arbitrator::TreePlanner tp(cf, png, bss, rclcpp::Duration(config_.target_plan_duration* 1e9));
71
72 wm_listener_ = std::make_shared<carma_wm::WMListener>(
73 this->get_node_base_interface(), this->get_node_logging_interface(),
74 this->get_node_topics_interface(), this->get_node_parameters_interface()
75 );
76
77 wm_ = wm_listener_->getWorldModel();
78
79 arbitrator_ = std::make_shared<Arbitrator>(
80 shared_from_this(),
81 std::make_shared<ArbitratorStateMachine>(sm),
82 ci,
83 std::make_shared<TreePlanner>(tp),
84 rclcpp::Duration(config_.min_plan_duration* 1e9),
86 wm_ );
87
88
89 twist_sub_ = create_subscription<geometry_msgs::msg::TwistStamped>("current_velocity", 1, std::bind(&Arbitrator::twist_cb, arbitrator_.get(), std::placeholders::_1));
90
91 arbitrator_->initializeBumperTransformLookup();
92
93 return CallbackReturn::SUCCESS;
94 }
carma_wm::WorldModelConstPtr wm_
carma_ros2_utils::SubPtr< geometry_msgs::msg::TwistStamped > twist_sub_
std::shared_ptr< carma_wm::WMListener > wm_listener_
void twist_cb(geometry_msgs::msg::TwistStamped::UniquePtr msg)
Callback for the twist subscriber, which will store latest twist locally.
Definition: arbitrator.cpp:206
Implementation of the CostFunction interface.
void init(std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh)
Implementation of the CostFunction interface.
Implementation of PlanningStrategy using a generic tree search algorithm.

References arbitrator_, arbitrator::Config::beam_width, config_, arbitrator::CostSystemCostFunction::init(), arbitrator::Config::min_plan_duration, arbitrator::Config::planning_frequency, arbitrator::Config::plugin_priorities, plugin_priorities_map_from_json(), arbitrator::Config::target_plan_duration, arbitrator::Arbitrator::twist_cb(), twist_sub_, arbitrator::Config::use_fixed_costs, wm_, and wm_listener_.

Here is the call graph for this function:

◆ plugin_priorities_map_from_json()

std::map< std::string, double > arbitrator::ArbitratorNode::plugin_priorities_map_from_json ( const std::string &  json_string)
private

Definition at line 112 of file arbitrator_node.cpp.

113 {
114 std::map<std::string, double> map;
115
116 rapidjson::Document d;
117 if(d.Parse(json_string.c_str()).HasParseError())
118 {
119 RCLCPP_WARN(rclcpp::get_logger("arbitrator"), "Failed to parse plugin_priorities map. Invalid json structure");
120 return map;
121 }
122 if (!d.HasMember("plugin_priorities")) {
123 RCLCPP_WARN(rclcpp::get_logger("arbitrator"), "No plugin_priorities found in arbitrator config");
124 return map;
125 }
126 rapidjson::Value& map_value = d["plugin_priorities"];
127
128 for (rapidjson::Value::ConstMemberIterator it = map_value.MemberBegin();
129 it != map_value.MemberEnd(); it++)
130 {
131 map[it->name.GetString()] = it->value.GetDouble();
132 }
133 return map;
134
135 }

Referenced by ArbitratorNode(), and handle_on_configure().

Here is the caller graph for this function:

Member Data Documentation

◆ arbitrator_

std::shared_ptr<Arbitrator> arbitrator::ArbitratorNode::arbitrator_
private

Definition at line 72 of file arbitrator_node.hpp.

Referenced by handle_on_activate(), and handle_on_configure().

◆ arbitrator_run_

rclcpp::TimerBase::SharedPtr arbitrator::ArbitratorNode::arbitrator_run_
private

Definition at line 74 of file arbitrator_node.hpp.

Referenced by handle_on_activate().

◆ bumper_pose_timer_

rclcpp::TimerBase::SharedPtr arbitrator::ArbitratorNode::bumper_pose_timer_
private

Definition at line 73 of file arbitrator_node.hpp.

Referenced by handle_on_activate().

◆ config_

Config arbitrator::ArbitratorNode::config_
private

Definition at line 68 of file arbitrator_node.hpp.

Referenced by ArbitratorNode(), handle_on_activate(), and handle_on_configure().

◆ twist_sub_

carma_ros2_utils::SubPtr<geometry_msgs::msg::TwistStamped> arbitrator::ArbitratorNode::twist_sub_
private

Definition at line 66 of file arbitrator_node.hpp.

Referenced by handle_on_configure().

◆ wm_

carma_wm::WorldModelConstPtr arbitrator::ArbitratorNode::wm_
private

Definition at line 71 of file arbitrator_node.hpp.

Referenced by handle_on_configure().

◆ wm_listener_

std::shared_ptr<carma_wm::WMListener> arbitrator::ArbitratorNode::wm_listener_
private

Definition at line 70 of file arbitrator_node.hpp.

Referenced by handle_on_configure().


The documentation for this class was generated from the following files: