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.
lightbar_manager_worker.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 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
17#pragma once
18#include <gtest/gtest.h>
19#include <string>
20#include <rclcpp/rclcpp.hpp>
21#include <carma_ros2_utils/carma_lifecycle_node.hpp>
22
23#include <vector>
24#include <map>
25
26#include <carma_msgs/msg/light_bar_cda_type.hpp>
27#include <carma_msgs/msg/light_bar_indicator.hpp>
28#include <carma_msgs/msg/light_bar_indicator_controllers.hpp>
29#include <carma_driver_msgs/msg/light_bar_status.hpp>
30#include <carma_planning_msgs/msg/guidance_state.hpp>
31#include <automotive_platform_msgs/msg/turn_signal_command.hpp>
32
33#include <carma_msgs/srv/request_indicator_control.hpp>
34#include <carma_msgs/srv/release_indicator_control.hpp>
35#include <carma_driver_msgs/srv/set_light_bar_indicator.hpp>
36#include <carma_driver_msgs/srv/set_lights.hpp>
37
39#define INDICATOR_COUNT 8
40#define CDA_MSG_TYPE_COUNT 4
41
42namespace lightbar_manager
43{
44
45// forward declaration
46class LightBarManagerStateMachine;
47
49{
50 public:
51
56
62
67 void next(const LightBarEvent& event);
68
73 void handleStateChange(const carma_planning_msgs::msg::GuidanceState& msg);
74
79 std::vector<lightbar_manager::LightBarIndicator> handleTurnSignal(const automotive_platform_msgs::msg::TurnSignalCommand& msg);
80
85 void releaseControl(std::vector<LightBarIndicator> ind_list, std::string owner_name);
86
92 std::vector<LightBarIndicator> requestControl(std::vector<LightBarIndicator> ind_list, std::string requester_name);
93
98 std::vector<IndicatorStatus> setIndicator(LightBarIndicator ind, IndicatorStatus ind_status, std::string requester_name);
99
106
113
118 std::map<LightBarCDAType, LightBarIndicator> setIndicatorCDAMap(const std::vector<std::string>& lightbar_cda_table, const std::vector<std::string>& lightbar_ind_table);
119
124 std::map<LightBarIndicator,std::string> getIndicatorControllers();
125
130
134 void setIndicatorControllers(std::map<LightBarIndicator, std::string> ind_ctrl_map);
135
140 bool hasHigherPriority(std::string requester, std::string controller);
141
147 void handleControlChange(LightBarIndicator indicator, std::string controller, IndicatorControlEvent event);
148
153 carma_driver_msgs::msg::LightBarStatus getLightBarStatusMsg(std::vector<IndicatorStatus> indicators);
154
159 std::vector<carma_msgs::msg::LightBarIndicator> getMsg(std::vector<LightBarIndicator> indicators);
160
165 std::vector<carma_msgs::msg::LightBarCDAType> getMsg(std::vector<LightBarCDAType> cda_types);
166
171 carma_msgs::msg::LightBarIndicatorControllers getMsg(std::map<LightBarIndicator, std::string> ind_ctrl_map);
172
173 // Priorities of components/plugins read from ROSParamter
174 std::vector<std::string> control_priorities;
175
176 // LightBarStatus local copy in LightBarIndicator representation
177 std::vector<IndicatorStatus> light_status;
178
179 private:
180
181
182 // LightBarManager state machine
184
185 // Indicators and their owners' mapping
186 std::map<LightBarIndicator, std::string> ind_ctrl_map_;
187
188 // Indicators and their corresponding CDA msg type mapping
189 std::map<LightBarCDAType, LightBarIndicator> cda_ind_map_;
190
191 // Current turn signal
192 uint8_t current_turn_signal_ = automotive_platform_msgs::msg::TurnSignalCommand::NONE;
193
194 // Helper maps that convert string into enum representations when reading from ROSParameter
195 std::map<std::string, LightBarCDAType> cda_type_dict_ = {
196 {"TypeA",TYPE_A},
197 {"TypeB",TYPE_B},
198 {"TypeC",TYPE_C},
199 {"TypeD",TYPE_D}};
200
201 std::map<std::string, LightBarIndicator> ind_dict = {
202 {"GREEN_SOLID", GREEN_SOLID},
203 {"GREEN_FLASH", GREEN_FLASH},
204 {"YELLOW_SIDES", YELLOW_SIDES},
205 {"YELLOW_DIM", YELLOW_DIM},
206 {"YELLOW_FLASH", YELLOW_FLASH},
207 {"YELLOW_ARROW_LEFT", YELLOW_ARROW_LEFT},
208 {"YELLOW_ARROW_RIGHT", YELLOW_ARROW_RIGHT},
209 {"YELLOW_ARROW_OUT", YELLOW_ARROW_OUT}};
210
211 FRIEND_TEST(LightBarManagerNodeTest, testSetIndicator);
212 FRIEND_TEST(LightBarManagerNodeTest, testTurnOffAll);
213 FRIEND_TEST(LightBarManagerNodeTest, testTurnSignalCallback);
214}; //class LightBarManagerWorker
215} // namespace lightbar_manager
void handleControlChange(LightBarIndicator indicator, std::string controller, IndicatorControlEvent event)
Helper function that handles control lost/gained event of a component. This function registers/remove...
std::map< LightBarCDAType, LightBarIndicator > cda_ind_map_
LightBarCDAType getCDATypeFromIndicator(LightBarIndicator indicator)
Helper functions that translates a CDA msg type to its corresponding indicator The mapping between ...
carma_driver_msgs::msg::LightBarStatus getLightBarStatusMsg(std::vector< IndicatorStatus > indicators)
Helper function that translates IndicatorStatus vector into LightBarStatus.msg, a lightbar driver com...
FRIEND_TEST(LightBarManagerNodeTest, testSetIndicator)
std::vector< IndicatorStatus > setIndicator(LightBarIndicator ind, IndicatorStatus ind_status, std::string requester_name)
Try to turn the given indicator ON or OFF (locally) upon the given component's request.
std::map< std::string, LightBarIndicator > ind_dict
std::map< LightBarCDAType, LightBarIndicator > setIndicatorCDAMap(const std::vector< std::string > &lightbar_cda_table, const std::vector< std::string > &lightbar_ind_table)
Helper function that initializes CDAType to Indicator Mapping (updates internal copy)
void setIndicatorControllers()
Helper function that initializes supporting Indicators and their owner mapping as empty strings.
std::vector< lightbar_manager::LightBarIndicator > handleTurnSignal(const automotive_platform_msgs::msg::TurnSignalCommand &msg)
This function checks if the turn signal should be changed on the lightbar.
std::vector< carma_msgs::msg::LightBarIndicator > getMsg(std::vector< LightBarIndicator > indicators)
Helper function that translates LightBarIndicator vector into LightBarIndicator.msg vector.
LightBarIndicator getIndicatorFromCDAType(LightBarCDAType cda_type)
Helper functions that translates an indicator to its corresponding CDA msg type The mapping between...
FRIEND_TEST(LightBarManagerNodeTest, testTurnOffAll)
void next(const LightBarEvent &event)
Transition to the next state of the LightBarStateMachine Not used at the moment as state machine full...
FRIEND_TEST(LightBarManagerNodeTest, testTurnSignalCallback)
void releaseControl(std::vector< LightBarIndicator > ind_list, std::string owner_name)
Releases the specified owner plugin or component's control of the given indicator list....
std::map< LightBarIndicator, std::string > ind_ctrl_map_
LightBarState getCurrentState()
Get current state of the LightBarStateMachine.
LightBarManagerWorker()
Default constructor for LightBarManager.
std::map< LightBarIndicator, std::string > getIndicatorControllers()
Helper function that gets all current owners of the indicator.
void handleStateChange(const carma_planning_msgs::msg::GuidanceState &msg)
This function relays the state change msg to the state maching. It triggers the transitioning to the ...
std::map< std::string, LightBarCDAType > cda_type_dict_
std::vector< LightBarIndicator > requestControl(std::vector< LightBarIndicator > ind_list, std::string requester_name)
Requests the control of the given list of indicators to the requester. This function handles successf...
bool hasHigherPriority(std::string requester, std::string controller)
Helper function that checks if the first input component has higher priority than the second.