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.
LocalizationTypes.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 std::ostream &operator<<(std::ostream &os, LocalizerMode m)
22 {
23 switch (m)
24 { // clang-format off
25 case LocalizerMode::NDT : os << "NDT"; break;
26 case LocalizerMode::GNSS: os << "GNSS"; break;
27 case LocalizerMode::GNSS_WITH_NDT_INIT: os << "GNSS_WITH_NDT_INIT"; break;
28 case LocalizerMode::GNSS_WITH_FIXED_OFFSET: os << "GNSS_WITH_FIXED_OFFSET"; break;
29 case LocalizerMode::AUTO_WITH_TIMEOUT : os << "AUTO_WITH_TIMEOUT"; break;
30 case LocalizerMode::AUTO_WITHOUT_TIMEOUT : os << "AUTO_WITHOUT_TIMEOUT"; break;
31 default: os.setstate(std::ios_base::failbit);
32 } // clang-format on
33 return os;
34 }
35
36 std::ostream &operator<<(std::ostream &os, LocalizationState s)
37 {
38 switch (s)
39 { // clang-format off
40 case LocalizationState::UNINITIALIZED : os << "UNINITIALIZED"; break;
41 case LocalizationState::INITIALIZING: os << "INITIALIZING"; break;
42 case LocalizationState::OPERATIONAL : os << "OPERATIONAL"; break;
43 case LocalizationState::DEGRADED : os << "DEGRADED"; break;
44 case LocalizationState::DEGRADED_NO_LIDAR_FIX : os << "DEGRADED_NO_LIDAR_FIX"; break;
45 case LocalizationState::AWAIT_MANUAL_INITIALIZATION : os << "AWAIT_MANUAL_INITIALIZATION"; break;
46 default: os.setstate(std::ios_base::failbit);
47 } // clang-format on
48 return os;
49 }
50
51 std::ostream &operator<<(std::ostream &os, LocalizationSignal s)
52 {
53 switch (s)
54 { // clang-format off
55 case LocalizationSignal::INITIAL_POSE : os << "INITIAL_POSE"; break;
56 case LocalizationSignal::GOOD_NDT_FREQ_AND_FITNESS_SCORE: os << "GOOD_NDT_FREQ_AND_FITNESS_SCORE"; break;
57 case LocalizationSignal::POOR_NDT_FREQ_OR_FITNESS_SCORE : os << "POOR_NDT_FREQ_OR_FITNESS_SCORE"; break;
58 case LocalizationSignal::UNUSABLE_NDT_FREQ_OR_FITNESS_SCORE : os << "UNUSABLE_NDT_FREQ_OR_FITNESS_SCORE"; break;
59 case LocalizationSignal::TIMEOUT : os << "TIMEOUT"; break;
60 case LocalizationSignal::LIDAR_SENSOR_FAILURE : os << "LIDAR_SENSOR_FAILURE"; break;
61 case LocalizationSignal::LIDAR_INITIALIZED_SWITCH_TO_GPS : os << "LIDAR_INITIALIZED_SWITCH_TO_GPS"; break;
62 case LocalizationSignal::GNSS_DATA_TIMEOUT : os << "GNSS_DATA_TIMEOUT"; break;
63 default: os.setstate(std::ios_base::failbit);
64 } // clang-format on
65 return os;
66 }
67
68 carma_localization_msgs::msg::LocalizationStatusReport stateToMsg(LocalizationState state, const rclcpp::Time &stamp)
69 {
70 carma_localization_msgs::msg::LocalizationStatusReport msg;
71 switch (state)
72 {
74 msg.status = carma_localization_msgs::msg::LocalizationStatusReport::UNINITIALIZED;
75 break;
77 msg.status = carma_localization_msgs::msg::LocalizationStatusReport::INITIALIZING;
78 break;
80 msg.status = carma_localization_msgs::msg::LocalizationStatusReport::OPERATIONAL;
81 break;
83 msg.status = carma_localization_msgs::msg::LocalizationStatusReport::DEGRADED;
84 break;
86 msg.status = carma_localization_msgs::msg::LocalizationStatusReport::DEGRADED_NO_LIDAR_FIX;
87 break;
89 msg.status = carma_localization_msgs::msg::LocalizationStatusReport::AWAIT_MANUAL_INITIALIZATION;
90 break;
91 default:
92 throw std::invalid_argument("LocalizationStates do not match carma_localization_msgs::msg::LocalizationStatusReport "
93 "states");
94 break;
95 }
96 msg.header.stamp = stamp;
97
98 return msg;
99 }
100
101} // namespace localization_manager
carma_localization_msgs::msg::LocalizationStatusReport stateToMsg(LocalizationState state, const rclcpp::Time &stamp)
Helper function to convert LocalizationState objects into LocalizationStatusReport ROS messages.
LocalizationState
Enum describing the possible states of the localization system.
std::ostream & operator<<(std::ostream &os, LocalizerMode m)
Stream operator for LocalizerMode enum.
LocalizerMode
Enum describing the possible operational modes of the LocalizationManager.
LocalizationSignal
Enum describing the possible signals to change the current LocalizationState.