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.
LocalizationTransitionTable.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
18
20{
21
23
25 {
26 return state_;
27 }
28
30 {
31 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("localization_manager"), "LocalizationTransitionTable received unsupported signal of " << signal << "while in state" << state_);
32 }
33
35 {
36 if (new_state == state_)
37 {
38 return; // State was unchanged no need to log or trigger callbacks
39 }
40 RCLCPP_INFO_STREAM(rclcpp::get_logger("localization_manager"), "LocalizationTransitionTable changed localization state from " << state_ << " to " << new_state << " because of signal " << source_signal << " while in mode " << mode_);
41
42 LocalizationState prev_state = state_;
43 state_ = new_state;
45 {
46 transition_callback_(prev_state, state_, source_signal);
47 }
48 }
49
51 {
52 switch (signal)
53 {
55 if (mode_ == LocalizerMode::GNSS || mode_ == LocalizerMode::GNSS_WITH_FIXED_OFFSET)
56 {
58 }
59 else
60 {
62 }
63 break;
64 default:
66 break;
67 }
68 }
69
71 {
72 switch (signal)
73 {
74 // How to handle the combined conditions?
77 break;
80 break;
83 {
85 }
86 else
87 {
89 }
90 break;
93 break;
94 default:
96 break;
97 }
98 }
99
101 {
102 switch (signal)
103 {
106 break;
109 break;
110 case LocalizationSignal::LIDAR_SENSOR_FAILURE: // Allowing fallthrough for duplicated behavior
113 {
115 }
116 else
117 {
119 }
120 break;
123 {
125 }
126 break;
127 default:
129 break;
130 }
131 }
132
134 {
135 switch (signal)
136 {
139 break;
142 break;
145 {
147 }
148 else
149 {
151 }
152 break;
155 {
157 }
158 else
159 {
161 }
162 break;
163 default:
165 break;
166 }
167 }
168
170 {
171 switch (signal)
172 {
174 if (mode_ != LocalizerMode::GNSS && mode_ != LocalizerMode::GNSS_WITH_FIXED_OFFSET)
175 {
177 }
178 break;
180 if (mode_ != LocalizerMode::GNSS && mode_ != LocalizerMode::GNSS_WITH_FIXED_OFFSET)
181 {
183 }
184 break;
187 {
189 }
190 break;
192 throw std::runtime_error("GNSS_DATA_TIMEOUT occurred while in DEGRADED_NO_LIDAR_FIX state. Localization cannot recover");
193 default:
195 break;
196 }
197 }
198
200 {
201 switch (signal)
202 {
204 if (mode_ == LocalizerMode::GNSS || mode_ == LocalizerMode::GNSS_WITH_FIXED_OFFSET)
205 {
207 }
208 else
209 {
211 }
212 break;
213 default:
215 break;
216 }
217 }
218
220 {
221 switch (state_)
222 {
225 break;
228 break;
231 break;
234 break;
237 break;
240 break;
241 default:
242 throw std::invalid_argument("Invalid signal passed to LocalizationTransitionTable::signal");
243 break;
244 }
245 }
246
248 {
250 }
251
252} // namespace localization_manager
void signal(LocalizationSignal signal)
Trigger signal for the transition table.
void setAndLogState(LocalizationState new_state, LocalizationSignal source_signal)
Function to change the current state and log the details of the transition.
LocalizationState state_
Current state. This state should only ever be set using the setAndLogState() function.
void logDebugSignal(LocalizationSignal signal) const
Helper function for logging the provide signal.
std::function< void(LocalizationState prev_state, LocalizationState new_state, LocalizationSignal signal)> TransitionCallback
LocalizationState getState() const
Returns the current state.
void setTransitionCallback(TransitionCallback cb)
Callback setting function. The provided callback will be triggered any time the current state changes...
LocalizationState
Enum describing the possible states of the localization system.
LocalizerMode
Enum describing the possible operational modes of the LocalizationManager.
LocalizationSignal
Enum describing the possible signals to change the current LocalizationState.