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.
guidance::GuidanceWorker Class Reference

Worker class for the Guidance node. More...

#include <guidance_worker.hpp>

Inheritance diagram for guidance::GuidanceWorker:
Inheritance graph
Collaboration diagram for guidance::GuidanceWorker:
Collaboration graph

Public Member Functions

 GuidanceWorker (const rclcpp::NodeOptions &)
 GuidanceWorker constructor. More...
 
rcl_interfaces::msg::SetParametersResult parameter_update_callback (const std::vector< rclcpp::Parameter > &parameters)
 Callback for dynamic parameter updates. More...
 
bool spin_cb ()
 Timer callback. More...
 
void route_event_cb (carma_planning_msgs::msg::RouteEvent::UniquePtr msg)
 Callback for route event messages. More...
 
void robot_status_cb (carma_driver_msgs::msg::RobotEnabled::UniquePtr msg)
 Callback for robot enabled messages. More...
 
void vehicle_status_cb (const autoware_msgs::msg::VehicleStatus::UniquePtr msg)
 Callback for vehicle status messages. More...
 
bool guidance_activation_cb (const std::shared_ptr< rmw_request_id_t >, const std::shared_ptr< carma_planning_msgs::srv::SetGuidanceActive::Request > req, std::shared_ptr< carma_planning_msgs::srv::SetGuidanceActive::Response > resp)
 Set_guidance_active service callback. User can attempt to activate the guidance system by calling this service. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &prev_state)
 
carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &)
 
carma_ros2_utils::CallbackReturn handle_on_shutdown (const rclcpp_lifecycle::State &prev_state)
 

Private Attributes

carma_ros2_utils::SubPtr< carma_driver_msgs::msg::RobotEnabled > robot_status_subscriber_
 
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::RouteEvent > route_event_subscriber_
 
carma_ros2_utils::SubPtr< autoware_msgs::msg::VehicleStatus > vehicle_status_subscriber_
 
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::GuidanceState > state_publisher_
 
carma_ros2_utils::ClientPtr< carma_driver_msgs::srv::SetEnableRobotic > enable_client_
 
carma_ros2_utils::ServicePtr< carma_planning_msgs::srv::SetGuidanceActive > guidance_activate_service_server_
 
rclcpp::TimerBase::SharedPtr spin_timer_
 
Config config_
 
GuidanceStateMachine gsm_
 

Detailed Description

Worker class for the Guidance node.

Definition at line 39 of file guidance_worker.hpp.

Constructor & Destructor Documentation

◆ GuidanceWorker()

guidance::GuidanceWorker::GuidanceWorker ( const rclcpp::NodeOptions &  options)
explicit

GuidanceWorker constructor.

Definition at line 22 of file guidance_worker.cpp.

23 : carma_ros2_utils::CarmaLifecycleNode(options),
24 gsm_(this->get_node_logging_interface())
25 {
26 // Create initial config
27 config_ = Config();
28
29 // Declare parameters
30 config_.spin_rate_hz = declare_parameter<double>("spin_rate_hz", config_.spin_rate_hz);
31 }
GuidanceStateMachine gsm_

References config_, and guidance::Config::spin_rate_hz.

Member Function Documentation

◆ guidance_activation_cb()

bool guidance::GuidanceWorker::guidance_activation_cb ( const std::shared_ptr< rmw_request_id_t >  ,
const std::shared_ptr< carma_planning_msgs::srv::SetGuidanceActive::Request >  req,
std::shared_ptr< carma_planning_msgs::srv::SetGuidanceActive::Response >  resp 
)

Set_guidance_active service callback. User can attempt to activate the guidance system by calling this service.

Parameters
reqA carma_planning_msgs::srv::SetGuidanceActive::Request msg
respA carma_planning_msgs::srv::SetGuidanceActive::Response msg

Definition at line 102 of file guidance_worker.cpp.

105 {
106 // Translate message type from GuidanceActiveRequest to SetEnableRobotic
107 if(!req->guidance_active)
108 {
109 auto enable_robotic_request = std::make_shared<carma_driver_msgs::srv::SetEnableRobotic::Request>();
110 enable_robotic_request->set = carma_driver_msgs::srv::SetEnableRobotic::Request::DISABLE;
111 enable_client_->async_send_request(enable_robotic_request);
112 }
113
114 gsm_.onSetGuidanceActive(req->guidance_active);
115 resp->guidance_status = (gsm_.getCurrentState() == GuidanceStateMachine::ACTIVE);
116 return true;
117 }
uint8_t getCurrentState()
Get current state machine status.
void onSetGuidanceActive(bool msg)
Handle set_guidance_active service call from ROS network.
carma_ros2_utils::ClientPtr< carma_driver_msgs::srv::SetEnableRobotic > enable_client_

References guidance::GuidanceStateMachine::ACTIVE, enable_client_, guidance::GuidanceStateMachine::getCurrentState(), gsm_, and guidance::GuidanceStateMachine::onSetGuidanceActive().

Referenced by handle_on_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_on_activate()

carma_ros2_utils::CallbackReturn guidance::GuidanceWorker::handle_on_activate ( const rclcpp_lifecycle::State &  prev_state)

Definition at line 81 of file guidance_worker.cpp.

82 {
83 // Setup timer
84 auto guidance_spin_period_ms = int ((1 / config_.spin_rate_hz) * 1000); // Conversion rom frequency (Hz) to milliseconds time period
85 spin_timer_ = create_timer(
86 get_clock(),
87 std::chrono::milliseconds(guidance_spin_period_ms),
88 std::bind(&GuidanceWorker::spin_cb, this));
89
90 // Update Guidance State Machine since node activation by the lifecycle system indicates that all required drivers are ready
92
93 return CallbackReturn::SUCCESS;
94 }
void onGuidanceInitialized()
Updates Guidance State Machine with INITIALIZED signal.
bool spin_cb()
Timer callback.
rclcpp::TimerBase::SharedPtr spin_timer_

References config_, gsm_, guidance::GuidanceStateMachine::onGuidanceInitialized(), spin_cb(), guidance::Config::spin_rate_hz, and spin_timer_.

Here is the call graph for this function:

◆ handle_on_configure()

carma_ros2_utils::CallbackReturn guidance::GuidanceWorker::handle_on_configure ( const rclcpp_lifecycle::State &  prev_state)

Definition at line 44 of file guidance_worker.cpp.

45 {
46 RCLCPP_INFO_STREAM(get_logger(), "GuidanceWorker trying to configure");
47
48 // Reset config
49 config_ = Config();
50
51 // Load parameters
52 get_parameter<double>("spin_rate_hz", config_.spin_rate_hz);
53
54 RCLCPP_INFO_STREAM(get_logger(), "Loaded params: " << config_);
55
56 // Register runtime parameter update callback
57 add_on_set_parameters_callback(std::bind(&GuidanceWorker::parameter_update_callback, this, std_ph::_1));
58
59 // Setup subscribers
60 robot_status_subscriber_ = create_subscription<carma_driver_msgs::msg::RobotEnabled>("robot_status", 5,
61 std::bind(&GuidanceWorker::robot_status_cb, this, std_ph::_1));
62 route_event_subscriber_ = create_subscription<carma_planning_msgs::msg::RouteEvent>("route_event", 5,
63 std::bind(&GuidanceWorker::route_event_cb, this, std_ph::_1));
64 vehicle_status_subscriber_ = create_subscription<autoware_msgs::msg::VehicleStatus>("vehicle_status", 5,
65 std::bind(&GuidanceWorker::vehicle_status_cb, this, std_ph::_1));
66
67 // Setup publishers
68 state_publisher_ = create_publisher<carma_planning_msgs::msg::GuidanceState>("state", 5);
69
70 // Setup service clients
71 enable_client_ = create_client<carma_driver_msgs::srv::SetEnableRobotic>("enable_robotic");
72
73 // Setup service servers
74 guidance_activate_service_server_ = create_service<carma_planning_msgs::srv::SetGuidanceActive>("set_guidance_active",
75 std::bind(&GuidanceWorker::guidance_activation_cb, this, std_ph::_1, std_ph::_2, std_ph::_3));
76
77 // Return success if everything initialized successfully
78 return CallbackReturn::SUCCESS;
79 }
void route_event_cb(carma_planning_msgs::msg::RouteEvent::UniquePtr msg)
Callback for route event messages.
carma_ros2_utils::SubPtr< autoware_msgs::msg::VehicleStatus > vehicle_status_subscriber_
carma_ros2_utils::SubPtr< carma_driver_msgs::msg::RobotEnabled > robot_status_subscriber_
carma_ros2_utils::ServicePtr< carma_planning_msgs::srv::SetGuidanceActive > guidance_activate_service_server_
void robot_status_cb(carma_driver_msgs::msg::RobotEnabled::UniquePtr msg)
Callback for robot enabled messages.
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Callback for dynamic parameter updates.
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::GuidanceState > state_publisher_
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::RouteEvent > route_event_subscriber_
void vehicle_status_cb(const autoware_msgs::msg::VehicleStatus::UniquePtr msg)
Callback for vehicle status messages.
bool guidance_activation_cb(const std::shared_ptr< rmw_request_id_t >, const std::shared_ptr< carma_planning_msgs::srv::SetGuidanceActive::Request > req, std::shared_ptr< carma_planning_msgs::srv::SetGuidanceActive::Response > resp)
Set_guidance_active service callback. User can attempt to activate the guidance system by calling thi...

References config_, enable_client_, guidance_activate_service_server_, guidance_activation_cb(), parameter_update_callback(), robot_status_cb(), robot_status_subscriber_, route_event_cb(), route_event_subscriber_, guidance::Config::spin_rate_hz, state_publisher_, vehicle_status_cb(), and vehicle_status_subscriber_.

Here is the call graph for this function:

◆ handle_on_shutdown()

carma_ros2_utils::CallbackReturn guidance::GuidanceWorker::handle_on_shutdown ( const rclcpp_lifecycle::State &  prev_state)

Definition at line 96 of file guidance_worker.cpp.

97 {
98 // Update Guidance State Machine with SHUTDOWN signal
100 }
void onGuidanceShutdown()
Updates Guidance State Machine with SHUTDOWN signal.

References gsm_, and guidance::GuidanceStateMachine::onGuidanceShutdown().

Here is the call graph for this function:

◆ parameter_update_callback()

rcl_interfaces::msg::SetParametersResult guidance::GuidanceWorker::parameter_update_callback ( const std::vector< rclcpp::Parameter > &  parameters)

Callback for dynamic parameter updates.

Definition at line 33 of file guidance_worker.cpp.

34 {
35 auto error = update_params<double>({{"spin_rate_hz", config_.spin_rate_hz}}, parameters);
36
37 rcl_interfaces::msg::SetParametersResult result;
38
39 result.successful = !error;
40
41 return result;
42 }

References config_, and guidance::Config::spin_rate_hz.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ robot_status_cb()

void guidance::GuidanceWorker::robot_status_cb ( carma_driver_msgs::msg::RobotEnabled::UniquePtr  msg)

Callback for robot enabled messages.

Parameters
msgLatest robot enabled message

Definition at line 138 of file guidance_worker.cpp.

139 {
140 gsm_.onRoboticStatus(move(msg));
141 }
void onRoboticStatus(carma_driver_msgs::msg::RobotEnabled::UniquePtr msg)
Handle robotic_status message from ROS network.

References gsm_, and guidance::GuidanceStateMachine::onRoboticStatus().

Referenced by handle_on_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ route_event_cb()

void guidance::GuidanceWorker::route_event_cb ( carma_planning_msgs::msg::RouteEvent::UniquePtr  msg)

Callback for route event messages.

Parameters
msgLatest route event message

Definition at line 133 of file guidance_worker.cpp.

134 {
135 gsm_.onRouteEvent(move(msg));
136 }
void onRouteEvent(carma_planning_msgs::msg::RouteEvent::UniquePtr msg)
Handle route event message.

References gsm_, and guidance::GuidanceStateMachine::onRouteEvent().

Referenced by handle_on_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spin_cb()

bool guidance::GuidanceWorker::spin_cb ( )

Timer callback.

Definition at line 119 of file guidance_worker.cpp.

120 {
122 auto req = std::make_shared<carma_driver_msgs::srv::SetEnableRobotic::Request>();
123 req->set = carma_driver_msgs::srv::SetEnableRobotic::Request::ENABLE;
124 enable_client_->async_send_request(req);
125 }
126
127 carma_planning_msgs::msg::GuidanceState state;
128 state.state = gsm_.getCurrentState();
129 state_publisher_->publish(state);
130 return true;
131 }
bool shouldCallSetEnableRobotic()
Indicate if SetEnableRobotic needs to be called in ACTIVE state.

References enable_client_, guidance::GuidanceStateMachine::getCurrentState(), gsm_, guidance::GuidanceStateMachine::shouldCallSetEnableRobotic(), and state_publisher_.

Referenced by handle_on_activate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vehicle_status_cb()

void guidance::GuidanceWorker::vehicle_status_cb ( const autoware_msgs::msg::VehicleStatus::UniquePtr  msg)

Callback for vehicle status messages.

Parameters
msgLatest vehicle status message

Definition at line 143 of file guidance_worker.cpp.

144 {
145 gsm_.onVehicleStatus(move(msg));
146 }
void onVehicleStatus(autoware_msgs::msg::VehicleStatus::UniquePtr msg)
Handle vehicle status message from ROS network.

References gsm_, and guidance::GuidanceStateMachine::onVehicleStatus().

Referenced by handle_on_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ config_

Config guidance::GuidanceWorker::config_
private

◆ enable_client_

carma_ros2_utils::ClientPtr<carma_driver_msgs::srv::SetEnableRobotic> guidance::GuidanceWorker::enable_client_
private

Definition at line 52 of file guidance_worker.hpp.

Referenced by guidance_activation_cb(), handle_on_configure(), and spin_cb().

◆ gsm_

◆ guidance_activate_service_server_

carma_ros2_utils::ServicePtr<carma_planning_msgs::srv::SetGuidanceActive> guidance::GuidanceWorker::guidance_activate_service_server_
private

Definition at line 55 of file guidance_worker.hpp.

Referenced by handle_on_configure().

◆ robot_status_subscriber_

carma_ros2_utils::SubPtr<carma_driver_msgs::msg::RobotEnabled> guidance::GuidanceWorker::robot_status_subscriber_
private

Definition at line 44 of file guidance_worker.hpp.

Referenced by handle_on_configure().

◆ route_event_subscriber_

carma_ros2_utils::SubPtr<carma_planning_msgs::msg::RouteEvent> guidance::GuidanceWorker::route_event_subscriber_
private

Definition at line 45 of file guidance_worker.hpp.

Referenced by handle_on_configure().

◆ spin_timer_

rclcpp::TimerBase::SharedPtr guidance::GuidanceWorker::spin_timer_
private

Definition at line 58 of file guidance_worker.hpp.

Referenced by handle_on_activate().

◆ state_publisher_

carma_ros2_utils::PubPtr<carma_planning_msgs::msg::GuidanceState> guidance::GuidanceWorker::state_publisher_
private

Definition at line 49 of file guidance_worker.hpp.

Referenced by handle_on_configure(), and spin_cb().

◆ vehicle_status_subscriber_

carma_ros2_utils::SubPtr<autoware_msgs::msg::VehicleStatus> guidance::GuidanceWorker::vehicle_status_subscriber_
private

Definition at line 46 of file guidance_worker.hpp.

Referenced by handle_on_configure().


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