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

#include <guidance_state_machine.hpp>

Collaboration diagram for guidance::GuidanceStateMachine:
Collaboration graph

Public Types

enum  Signal {
  INITIALIZED = 0 , ACTIVATED = 1 , ENGAGE = 2 , DISENGAGED = 3 ,
  SHUTDOWN = 4 , OVERRIDE = 5 , PARK = 6
}
 
enum  State {
  OFF = 0 , STARTUP = 1 , DRIVERS_READY = 2 , ACTIVE = 3 ,
  ENGAGED = 4 , INACTIVE = 5 , ENTER_PARK = 6
}
 

Public Member Functions

 GuidanceStateMachine (rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger)
 constructor for GuidanceStateMachine More...
 
void onVehicleStatus (autoware_msgs::msg::VehicleStatus::UniquePtr msg)
 Handle vehicle status message from ROS network. More...
 
void onGuidanceInitialized ()
 Updates Guidance State Machine with INITIALIZED signal. More...
 
void onGuidanceShutdown ()
 Updates Guidance State Machine with SHUTDOWN signal. More...
 
void onSetGuidanceActive (bool msg)
 Handle set_guidance_active service call from ROS network. More...
 
void onRoboticStatus (carma_driver_msgs::msg::RobotEnabled::UniquePtr msg)
 Handle robotic_status message from ROS network. More...
 
void onRouteEvent (carma_planning_msgs::msg::RouteEvent::UniquePtr msg)
 Handle route event message. More...
 
bool shouldCallSetEnableRobotic ()
 Indicate if SetEnableRobotic needs to be called in ACTIVE state. More...
 
uint8_t getCurrentState ()
 Get current state machine status. More...
 

Private Member Functions

void onGuidanceSignal (Signal signal)
 Actual state machine logic driven by signal enum. More...
 

Private Attributes

State current_guidance_state_ {State::STARTUP}
 
bool robotic_active_status_ {false}
 
bool called_robotic_engage_in_active_ {false}
 
double current_velocity_ = 0.0
 
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_
 

Detailed Description

Definition at line 28 of file guidance_state_machine.hpp.

Member Enumeration Documentation

◆ Signal

◆ State

Constructor & Destructor Documentation

◆ GuidanceStateMachine()

guidance::GuidanceStateMachine::GuidanceStateMachine ( rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr  logger)

constructor for GuidanceStateMachine

Parameters
loggerThe logger interface that will be used by this object

Definition at line 21 of file guidance_state_machine.cpp.

22 : logger_(logger) {}
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_

Member Function Documentation

◆ getCurrentState()

uint8_t guidance::GuidanceStateMachine::getCurrentState ( )

Get current state machine status.

Definition at line 157 of file guidance_state_machine.cpp.

158 {
159 return static_cast<uint8_t>(current_guidance_state_);
160 }

References current_guidance_state_.

Referenced by guidance::GuidanceWorker::guidance_activation_cb(), and guidance::GuidanceWorker::spin_cb().

Here is the caller graph for this function:

◆ onGuidanceInitialized()

void guidance::GuidanceStateMachine::onGuidanceInitialized ( )

Updates Guidance State Machine with INITIALIZED signal.

Definition at line 103 of file guidance_state_machine.cpp.

104 {
105 onGuidanceSignal(Signal::INITIALIZED);
106 }
void onGuidanceSignal(Signal signal)
Actual state machine logic driven by signal enum.

References onGuidanceSignal().

Referenced by guidance::GuidanceWorker::handle_on_activate().

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

◆ onGuidanceShutdown()

void guidance::GuidanceStateMachine::onGuidanceShutdown ( )

Updates Guidance State Machine with SHUTDOWN signal.

Definition at line 108 of file guidance_state_machine.cpp.

References onGuidanceSignal(), and arbitrator::SHUTDOWN.

Referenced by guidance::GuidanceWorker::handle_on_shutdown().

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

◆ onGuidanceSignal()

void guidance::GuidanceStateMachine::onGuidanceSignal ( Signal  signal)
private

Actual state machine logic driven by signal enum.

Definition at line 24 of file guidance_state_machine.cpp.

25 {
26 // Set to OFF state of SHUTDOWN signal received
27 if(signal == Signal::SHUTDOWN) {
29 return;
30 }
32 {
33 case State::STARTUP:
34 if(signal == Signal::INITIALIZED) {
35 current_guidance_state_ = State::DRIVERS_READY;
36 }
37 break;
38 case State::DRIVERS_READY:
39 if(signal == Signal::ACTIVATED)
40 {
42 }
43 break;
44 case State::ACTIVE:
45 if(signal == Signal::ENGAGE)
46 {
48 } else if(signal == Signal::DISENGAGED)
49 {
50 current_guidance_state_ = State::DRIVERS_READY;
51 }
52 break;
53 case State::ENGAGED:
54 if(signal == Signal::DISENGAGED)
55 {
56 current_guidance_state_ = State::DRIVERS_READY;
57 } else if(signal == Signal::OVERRIDE)
58 {
60 } else if(signal == Signal::PARK)
61 {
62 current_guidance_state_ = State::ENTER_PARK;
63 }
64 break;
65 case State::INACTIVE:
66 if(signal == Signal::ACTIVATED)
67 {
69 }else if(signal == Signal::INITIALIZED){
70 current_guidance_state_ = State::DRIVERS_READY;
71 }
72 break;
73 case State::ENTER_PARK:
74 if(signal == Signal::OVERRIDE)
75 {
77 }
78 else if(signal == Signal::DISENGAGED)
79 {
80 current_guidance_state_ = State::DRIVERS_READY;
81 }
82 break;
83 default:
84 break;
85 }
86 }

References lightbar_manager::ACTIVE, current_guidance_state_, lightbar_manager::DISENGAGED, lightbar_manager::ENGAGED, port_drayage_plugin::INACTIVE, lightbar_manager::OFF, and arbitrator::SHUTDOWN.

Referenced by onGuidanceInitialized(), onGuidanceShutdown(), onRoboticStatus(), onRouteEvent(), onSetGuidanceActive(), and onVehicleStatus().

Here is the caller graph for this function:

◆ onRoboticStatus()

void guidance::GuidanceStateMachine::onRoboticStatus ( carma_driver_msgs::msg::RobotEnabled::UniquePtr  msg)

Handle robotic_status message from ROS network.

Definition at line 125 of file guidance_state_machine.cpp.

126 {
127 // robotic status changes from false to true
128 if(!robotic_active_status_ && msg->robot_active)
129 {
131 onGuidanceSignal(Signal::ENGAGE);
132 }
133 // robotic status changes from true to false
134 else if(robotic_active_status_ && !msg->robot_active)
135 {
137 onGuidanceSignal(Signal::OVERRIDE);
138 }
139 }

References onGuidanceSignal(), and robotic_active_status_.

Referenced by guidance::GuidanceWorker::robot_status_cb().

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

◆ onRouteEvent()

void guidance::GuidanceStateMachine::onRouteEvent ( carma_planning_msgs::msg::RouteEvent::UniquePtr  msg)

Handle route event message.

Definition at line 141 of file guidance_state_machine.cpp.

142 {
143 if(msg->event == carma_planning_msgs::msg::RouteEvent::ROUTE_DEPARTED ||
144 msg->event == carma_planning_msgs::msg::RouteEvent::ROUTE_ABORTED) {
146 }
147 else if(msg->event == carma_planning_msgs::msg::RouteEvent::ROUTE_COMPLETED){
148 if (fabs(current_velocity_) < 0.001) { // Check we have successfully stopped
149 onGuidanceSignal(Signal::PARK); // ENGAGED -> ENTER_PARK this state restricts transitioning out of ENTER_PARK until vehicle is shifted to PARK
150 } else { // Vehicle was not able to stop transition to inactive
151 RCLCPP_WARN_STREAM(logger_->get_logger(), "Vehicle failed to park on route completion because current velocity was " << current_velocity_);
152 onGuidanceSignal(Signal::OVERRIDE);
153 }
154 }
155 }

References current_velocity_, lightbar_manager::DISENGAGED, logger_, and onGuidanceSignal().

Referenced by guidance::GuidanceWorker::route_event_cb().

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

◆ onSetGuidanceActive()

void guidance::GuidanceStateMachine::onSetGuidanceActive ( bool  msg)

Handle set_guidance_active service call from ROS network.

Definition at line 113 of file guidance_state_machine.cpp.

114 {
115 if(msg)
116 {
117 onGuidanceSignal(Signal::ACTIVATED);
118 } else
119 {
121 }
122
123 }

References lightbar_manager::DISENGAGED, and onGuidanceSignal().

Referenced by guidance::GuidanceWorker::guidance_activation_cb().

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

◆ onVehicleStatus()

void guidance::GuidanceStateMachine::onVehicleStatus ( autoware_msgs::msg::VehicleStatus::UniquePtr  msg)

Handle vehicle status message from ROS network.

Definition at line 88 of file guidance_state_machine.cpp.

89 {
90 current_velocity_ = msg->speed * 0.277777; // Convert kilometers per hour to meters per second. Rounded down so that it comes under epsilon for parking check
91 if (current_guidance_state_ == State::ENTER_PARK)
92 {
93 // '3' indicates vehicle gearshift is currently set to PARK
94 if(msg->current_gear.gear== autoware_msgs::msg::Gear::PARK)
95 {
96 onGuidanceSignal(Signal::OVERRIDE); // Required for ENTER_PARK -> INACTIVE
97
98 onGuidanceSignal(Signal::INITIALIZED); // Required for INACTIVE -> DRIVERS_READY
99 }
100 }
101 }

References current_guidance_state_, current_velocity_, and onGuidanceSignal().

Referenced by guidance::GuidanceWorker::vehicle_status_cb().

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

◆ shouldCallSetEnableRobotic()

bool guidance::GuidanceStateMachine::shouldCallSetEnableRobotic ( )

Indicate if SetEnableRobotic needs to be called in ACTIVE state.

Definition at line 162 of file guidance_state_machine.cpp.

163 {
164 // call SetEnableRobotic service once when we enter ACTIVE state
166 {
168 {
170 return true;
171 }
172 } else {
173 // Reset when we leave ACTIVE state
175 }
176 return false;
177 }

References ACTIVE, called_robotic_engage_in_active_, and current_guidance_state_.

Referenced by guidance::GuidanceWorker::spin_cb().

Here is the caller graph for this function:

Member Data Documentation

◆ called_robotic_engage_in_active_

bool guidance::GuidanceStateMachine::called_robotic_engage_in_active_ {false}
private

Definition at line 114 of file guidance_state_machine.hpp.

Referenced by shouldCallSetEnableRobotic().

◆ current_guidance_state_

State guidance::GuidanceStateMachine::current_guidance_state_ {State::STARTUP}
private

◆ current_velocity_

double guidance::GuidanceStateMachine::current_velocity_ = 0.0
private

Definition at line 117 of file guidance_state_machine.hpp.

Referenced by onRouteEvent(), and onVehicleStatus().

◆ logger_

rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr guidance::GuidanceStateMachine::logger_
private

Definition at line 120 of file guidance_state_machine.hpp.

Referenced by onRouteEvent().

◆ robotic_active_status_

bool guidance::GuidanceStateMachine::robotic_active_status_ {false}
private

Definition at line 111 of file guidance_state_machine.hpp.

Referenced by onRoboticStatus().


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