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::CostSystemCostFunction Class Reference

Implementation of the CostFunction interface. More...

#include <cost_system_cost_function.hpp>

Inheritance diagram for arbitrator::CostSystemCostFunction:
Inheritance graph
Collaboration diagram for arbitrator::CostSystemCostFunction:
Collaboration graph

Public Member Functions

 CostSystemCostFunction ()
 Constructor for FixedPriorityCostFunction. More...
 
void init (std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh)
 
double compute_total_cost (const carma_planning_msgs::msg::ManeuverPlan &plan)
 Compute the unit cost over distance of a given maneuver plan. More...
 
double compute_cost_per_unit_distance (const carma_planning_msgs::msg::ManeuverPlan &plan)
 Compute the unit cost over distance of a given maneuver plan. More...
 
- Public Member Functions inherited from arbitrator::CostFunction
virtual double compute_total_cost (const carma_planning_msgs::msg::ManeuverPlan &plan)=0
 Compute the cost of a given maneuver plan. More...
 
virtual double compute_cost_per_unit_distance (const carma_planning_msgs::msg::ManeuverPlan &plan)=0
 Compute the unit cost over distance of a given maneuver plan. More...
 
virtual ~CostFunction ()
 Virtual destructor provided for memory safety. More...
 

Private Attributes

carma_ros2_utils::ClientPtr< carma_planning_msgs::srv::ComputePlanCost > cost_system_sc_
 
bool initialized_ = false
 

Detailed Description

Implementation of the CostFunction interface.

Implements costs by utilizing a ROS service call to the CARMA cost plugin system. Passes on the input maneuver plan to the Cost Plugin System for computation of the actual cost and cost per unit distance.

Definition at line 36 of file cost_system_cost_function.hpp.

Constructor & Destructor Documentation

◆ CostSystemCostFunction()

arbitrator::CostSystemCostFunction::CostSystemCostFunction ( )
inline

Constructor for FixedPriorityCostFunction.

Definition at line 42 of file cost_system_cost_function.hpp.

42{};

Member Function Documentation

◆ compute_cost_per_unit_distance()

double arbitrator::CostSystemCostFunction::compute_cost_per_unit_distance ( const carma_planning_msgs::msg::ManeuverPlan &  plan)
virtual

Compute the unit cost over distance of a given maneuver plan.

Parameters
planThe plan to evaluate
Returns
double The total cost divided by the total distance of the plan
Exceptions
std::logic_errorif not initialized

Implements arbitrator::CostFunction.

Definition at line 55 of file cost_system_cost_function.cpp.

56 {
58 return compute_total_cost(plan) / plan_dist;
59 }
double compute_total_cost(const carma_planning_msgs::msg::ManeuverPlan &plan)
Compute the unit cost over distance of a given maneuver plan.
double get_plan_end_distance(const carma_planning_msgs::msg::ManeuverPlan &)
Get the end distance of the first maneuver in the plan.
double get_plan_start_distance(const carma_planning_msgs::msg::ManeuverPlan &)
Get the start distance of the first maneuver in the plan.

References compute_total_cost(), arbitrator_utils::get_plan_end_distance(), and arbitrator_utils::get_plan_start_distance().

Here is the call graph for this function:

◆ compute_total_cost()

double arbitrator::CostSystemCostFunction::compute_total_cost ( const carma_planning_msgs::msg::ManeuverPlan &  plan)
virtual

Compute the unit cost over distance of a given maneuver plan.

Parameters
planThe plan to evaluate
Returns
double The total cost divided by the total distance of the plan
Exceptions
std::logic_errorif not initialized

Implements arbitrator::CostFunction.

Definition at line 31 of file cost_system_cost_function.cpp.

32 {
33 if (!initialized_) {
34 throw std::logic_error("Attempt to use CostSystemCostFunction before initialization.");
35 }
36
37 double total_cost = std::numeric_limits<double>::infinity();
38
39 auto service_message = std::make_shared<carma_planning_msgs::srv::ComputePlanCost::Request>();
40 service_message->maneuver_plan = plan;
41
42 auto resp = cost_system_sc_->async_send_request(service_message);
43
44 auto future_status = resp.wait_for(std::chrono::milliseconds(500));
45
46 if (future_status == std::future_status::ready){
47 total_cost = resp.get()->plan_cost;
48 } else {
49 RCLCPP_WARN_STREAM(rclcpp::get_logger("arbitrator"), "Unable to get cost for plan from CostPluginSystem due to service call failure.");
50 }
51
52 return total_cost;
53 }
carma_ros2_utils::ClientPtr< carma_planning_msgs::srv::ComputePlanCost > cost_system_sc_

References cost_system_sc_, and initialized_.

Referenced by compute_cost_per_unit_distance().

Here is the caller graph for this function:

◆ init()

void arbitrator::CostSystemCostFunction::init ( std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode >  nh)

Initialize the CostSystemCostFunction to communicate over the network. Sets up any ROS service clients needed to interact with the cost plugin system.

Must be called before using this cost function implementation.

Parameters
nhA publicly namespaced nodehandle

Definition at line 25 of file cost_system_cost_function.cpp.

26 {
27 cost_system_sc_ = nh->create_client<carma_planning_msgs::srv::ComputePlanCost>("compute_plan_cost");
28 initialized_ = true;
29 }

References cost_system_sc_, and initialized_.

Referenced by arbitrator::ArbitratorNode::handle_on_configure().

Here is the caller graph for this function:

Member Data Documentation

◆ cost_system_sc_

carma_ros2_utils::ClientPtr<carma_planning_msgs::srv::ComputePlanCost> arbitrator::CostSystemCostFunction::cost_system_sc_
private

Definition at line 71 of file cost_system_cost_function.hpp.

Referenced by compute_total_cost(), and init().

◆ initialized_

bool arbitrator::CostSystemCostFunction::initialized_ = false
private

Definition at line 72 of file cost_system_cost_function.hpp.

Referenced by compute_total_cost(), and init().


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