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.
lci_state_transition_table.cpp
Go to the documentation of this file.
1
2/*
3 * Copyright (C) 2023 LEIDOS.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy of
7 * the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
18#include <rclcpp/rclcpp.hpp>
19
21{
22
23// THERE SHOULD BE FOUR OPERATIONAL MODES FOR THIS PLUGIN
24// UNAVAILABLE { On In Intersection Range Event -> APPROACH }
25// APPROACHING { On Stopped Event -> WAITING, On Crossed Stop Bar -> DEPARTURE}
26// WAITING { On Green Light Event -> DEPARTURE}
27// DEPARTING { On exit intersection -> UNAVAILABLE}
28
30{
31 return state_;
32}
33
35{
36 switch (state_)
37 {
40 break;
41
44 break;
45
48 break;
49
52 break;
53
54 default:
55 throw std::invalid_argument("Transition table in unsupported state");
56 }
57}
58
60{
62}
63
65{
67 {
69 }
70 else
71 {
73 }
74}
75
77{
78 switch (signal)
79 {
82 break;
83
86 break;
87
88 default:
90 break;
91 }
92}
93
95{
97 {
99 }
100 else
101 {
103 }
104}
105
107{
109 {
111 }
112 else
113 {
115 }
116}
117
119{
120 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("lci_strategic_plugin"), "LCIStrategicStateTransitionTable received unsupported signal of " << signal << " while in state "
121 << state_);
122}
123
125{
126 if (new_state == state_)
127 {
128 return; // State was unchanged no need to log or trigger callbacks
129 }
130
131 RCLCPP_INFO_STREAM(rclcpp::get_logger("lci_strategic_plugin"), "LCIStrategicStateTransitionTable changed LCIStrategic Strategic Plugin state from "
132 << state_ << " to " << new_state << " because of signal " << source_signal);
133
134 TransitState prev_state = state_;
135 state_ = new_state; // Set new state
136
137 if (transition_callback_) // Trigger callback if available
138 {
139 transition_callback_(prev_state, state_, source_signal);
140 }
141}
142
143} // namespace lci_strategic_plugin
void setTransitionCallback(TransitionCallback cb)
Callback setting function. The provided callback will be triggered any time the current state changes...
void logDebugSignal(TransitEvent signal) const
Helper function for logging the provide signal.
TransitState getState() const
Returns the current state.
void setAndLogState(TransitState new_state, TransitEvent source_signal)
Function to change the current state and log the details of the transition.
void signal(TransitEvent signal)
Trigger signal for the transition table.
std::function< void(TransitState prev_state, TransitState new_state, TransitEvent signal)> TransitionCallback
TransitState state_
Current state. This state should only ever be set using the setAndLogState() function.
TransitEvent
Enum describing the possible signals to change the current TransitState.
Definition: lci_states.hpp:39
TransitState
Enum describing the possible states of the LCIStrategic Strategic Plugin.
Definition: lci_states.hpp:25