36 std::vector<carma_msgs::msg::LightBarIndicator> return_msg;
37 for (
auto indicator : indicators)
40 msg.indicator = indicator;
41 return_msg.push_back(msg);
48 std::vector<carma_msgs::msg::LightBarCDAType> return_msg;
49 for (
auto cda_type : cda_types)
53 return_msg.push_back(msg);
59 carma_msgs::msg::LightBarIndicatorControllers curr;
63 curr.yellow_dim_owner = ind_ctrl_map[
YELLOW_DIM];
80 std::vector<lightbar_manager::LightBarIndicator> turn_signal;
85 if (msg.turn_signal == automotive_platform_msgs::msg::TurnSignalCommand::LEFT)
89 else if (msg.turn_signal == automotive_platform_msgs::msg::TurnSignalCommand::RIGHT)
93 else if (msg.turn_signal == automotive_platform_msgs::msg::TurnSignalCommand::NONE)
115 std::map<std::string, std::string> raw_map;
116 for (
size_t i = 0;
i < lightbar_cda_table.size();
i ++)
118 raw_map[lightbar_cda_table[
i]] = lightbar_ind_table[
i];
121 std::map<LightBarCDAType, LightBarIndicator> default_map;
128 if (raw_map.size() < 4)
130 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"lightbar_manager"),
"In function: " << __FUNCTION__ <<
": LightBarManager's CDAType to Indicator table is not configured correctly. Using default mapping...");
136 for (std::pair<std::string, std::string> element : raw_map)
144 catch(
const std::exception& e)
146 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"lightbar_manager"),
"In function: " << __FUNCTION__ <<
147 ": LightBarManager Received unknown CDA Msg Type. Using default mapping for cda-indicators...");
153 indicator =
ind_dict.at(element.second);
155 catch(
const std::exception& e)
157 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"lightbar_manager"),
"In function: " << __FUNCTION__ <<
158 ": LightBarManager Received unknown indicator type. Using default mapping for cda-indicators...");
172 auto requesterPriority = std::find(start, end, requester);
173 auto controllerPriority = std::find(start, end, controller);
176 if (requesterPriority == end)
178 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"lightbar_manager"),requester <<
" is referenced in lightbar_manager, but is not in the priority list");
181 else if (controllerPriority == end)
183 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"lightbar_manager"),controller <<
" is referenced in lightbar_manager and is controlling an indicator, but is not in the priority list");
186 return (requesterPriority - end) <= (controllerPriority - end);
191 std::vector<LightBarIndicator> denied_list;
192 std::string indicator_owner;
201 catch(
const std::exception& e)
203 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"lightbar_manager"),
"In function: " << __FUNCTION__ <<
", the component, " << requester_name
204 <<
", requested a control of invalid indicator. Skipping with WARNING:" << e.what() <<
"\n");
208 if (indicator_owner ==
"")
213 else if (indicator_owner != requester_name)
226 denied_list.push_back(indicator);
235 std::string current_owner;
245 catch(
const std::exception& e)
247 RCLCPP_WARN_STREAM(rclcpp::get_logger(
"lightbar_manager"),
"In function: " << __FUNCTION__ <<
", the component, " << owner_name
248 <<
", requested a release of an invalid indicator. Skipping with WARNING:" << e.what() <<
"\n");
253 if (current_owner == owner_name)
265 std::string new_owner;
267 new_owner = controller;
313 std::vector<IndicatorStatus> light_status_copy =
light_status;
317 if (ind_status != light_status_copy[ind])
344 light_status_copy[ind] = ind_status;
345 return light_status_copy;
352 carma_driver_msgs::msg::LightBarStatus msg;
392 for (std::pair<LightBarCDAType,LightBarIndicator> element :
cda_ind_map_)
394 if (element.second == indicator)
395 return element.first;
398 throw INDICATOR_NOT_MAPPED(std::string(
"Specified indicator does not have a mapped CDA Msg Type. Skipping..."));
LightBarState getCurrentState()
Get current state machine status.
void next(const LightBarEvent &event)
Transition to the next state of the LightBarStateMachine.
void handleStateChange(const carma_planning_msgs::msg::GuidanceState &msg)
This function triggers the transitioning to the next state in LightBarStateMachine based on the guida...
std::vector< IndicatorStatus > light_status
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...
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)
std::vector< std::string > control_priorities
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...
void next(const LightBarEvent &event)
Transition to the next state of the LightBarStateMachine Not used at the moment as state machine full...
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....
uint8_t current_turn_signal_
std::map< LightBarIndicator, std::string > ind_ctrl_map_
LightBarManagerStateMachine lbsm_
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.