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::LightBarManager Class Reference

#include <lightbar_manager_node.hpp>

Inheritance diagram for lightbar_manager::LightBarManager:
Inheritance graph
Collaboration diagram for lightbar_manager::LightBarManager:
Collaboration graph

Public Member Functions

 LightBarManager (const rclcpp::NodeOptions &)
 
std::shared_ptr< LightBarManagerWorkergetWorker ()
 Get ptr to lightbar_manager_worker (for ease of unit testing) More...
 
void turnOffAll ()
 Miscellaneous function that forces the state to disengaged and turn off all indicators. Used in special demo cases as well as when carma is disengaged. More...
 
int setIndicator (LightBarIndicator ind, IndicatorStatus ind_status, const std::string &requester_name)
 Try to turn the given indicator ON or OFF (comm with hardware) upon the given component's request. More...
 
void turnSignalCallback (automotive_platform_msgs::msg::TurnSignalCommand::UniquePtr msg_ptr)
 Callback function for turning signal. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &)
 
carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &)
 

Private Member Functions

void processTurnSignal (const automotive_platform_msgs::msg::TurnSignalCommand &msg)
 Turn signal callback function helper. More...
 
bool spinCallBack ()
 
bool requestControlCallBack (const std::shared_ptr< rmw_request_id_t >, const std::shared_ptr< carma_msgs::srv::RequestIndicatorControl::Request > req, std::shared_ptr< carma_msgs::srv::RequestIndicatorControl::Response > resp)
 
bool releaseControlCallBack (const std::shared_ptr< rmw_request_id_t >, const std::shared_ptr< carma_msgs::srv::ReleaseIndicatorControl::Request > req, std::shared_ptr< carma_msgs::srv::ReleaseIndicatorControl::Response > resp)
 
bool setIndicatorCallBack (const std::shared_ptr< rmw_request_id_t >, const std::shared_ptr< carma_driver_msgs::srv::SetLightBarIndicator::Request > req, std::shared_ptr< carma_driver_msgs::srv::SetLightBarIndicator::Response > resp)
 
void stateChangeCallBack (carma_planning_msgs::msg::GuidanceState::UniquePtr msg_ptr)
 
 FRIEND_TEST (LightBarManagerNodeTest, testSetIndicator)
 
 FRIEND_TEST (LightBarManagerNodeTest, testTurnOffAll)
 
 FRIEND_TEST (LightBarManagerNodeTest, testTurnSignalCallback)
 

Private Attributes

Config config_
 
std::string node_name_ = "lightbar_manager"
 
double spin_rate_ = 10.0
 
std::map< lightbar_manager::LightBarIndicator, std::string > prev_owners_before_turn_
 
carma_ros2_utils::ServicePtr< carma_msgs::srv::RequestIndicatorControl > request_control_server_
 
carma_ros2_utils::ServicePtr< carma_msgs::srv::ReleaseIndicatorControl > release_control_server_
 
carma_ros2_utils::ServicePtr< carma_driver_msgs::srv::SetLightBarIndicator > set_indicator_server_
 
carma_ros2_utils::ClientPtr< carma_driver_msgs::srv::SetLights > lightbar_driver_client_
 
carma_ros2_utils::PubPtr< carma_msgs::msg::LightBarIndicatorControllers > indicator_control_publisher_
 
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::GuidanceState > guidance_state_subscriber_
 
carma_ros2_utils::SubPtr< automotive_platform_msgs::msg::TurnSignalCommand > turn_signal_subscriber_
 
std::shared_ptr< LightBarManagerWorkerlbm_
 
rclcpp::TimerBase::SharedPtr pub_timer_
 

Detailed Description

Definition at line 68 of file lightbar_manager_node.hpp.

Constructor & Destructor Documentation

◆ LightBarManager()

LightBarManager::LightBarManager ( const rclcpp::NodeOptions &  options)
explicit

Definition at line 26 of file lightbar_manager_node.cpp.

26 : carma_ros2_utils::CarmaLifecycleNode(options)
27{
28 // Create initial config
29 config_ = Config();
30 config_.spin_rate_hz = declare_parameter<double>("spin_rate_hz", config_.spin_rate_hz);
31 config_.normal_operation = declare_parameter<bool>("normal_operation", config_.normal_operation);
32 declare_parameter("lightbar_cda_table");
33 declare_parameter("lightbar_ind_table");
34 declare_parameter("lightbar_priorities");
35 lbm_ = std::make_shared<LightBarManagerWorker>();
36}
std::shared_ptr< LightBarManagerWorker > lbm_

References config_, lbm_, lightbar_manager::Config::normal_operation, and lightbar_manager::Config::spin_rate_hz.

Member Function Documentation

◆ FRIEND_TEST() [1/3]

lightbar_manager::LightBarManager::FRIEND_TEST ( LightBarManagerNodeTest  ,
testSetIndicator   
)
private

◆ FRIEND_TEST() [2/3]

lightbar_manager::LightBarManager::FRIEND_TEST ( LightBarManagerNodeTest  ,
testTurnOffAll   
)
private

◆ FRIEND_TEST() [3/3]

lightbar_manager::LightBarManager::FRIEND_TEST ( LightBarManagerNodeTest  ,
testTurnSignalCallback   
)
private

◆ getWorker()

std::shared_ptr< LightBarManagerWorker > LightBarManager::getWorker ( )

Get ptr to lightbar_manager_worker (for ease of unit testing)

Returns
LightBarManagerWorker

Definition at line 329 of file lightbar_manager_node.cpp.

330{
331 return lbm_;
332}

References lbm_.

◆ handle_on_activate()

carma_ros2_utils::CallbackReturn LightBarManager::handle_on_activate ( const rclcpp_lifecycle::State &  )

Definition at line 114 of file lightbar_manager_node.cpp.

115{
116 pub_timer_ = create_timer(get_clock(),
117 std::chrono::milliseconds((int)(1 / config_.spin_rate_hz * 1000)),
118 std::bind(&LightBarManager::spinCallBack, this));
119 return CallbackReturn::SUCCESS;
120}
rclcpp::TimerBase::SharedPtr pub_timer_

References config_, pub_timer_, lightbar_manager::Config::spin_rate_hz, and spinCallBack().

Here is the call graph for this function:

◆ handle_on_configure()

carma_ros2_utils::CallbackReturn LightBarManager::handle_on_configure ( const rclcpp_lifecycle::State &  )

Definition at line 38 of file lightbar_manager_node.cpp.

39{
40 // Reset config
41 config_ = Config();
42
43 RCLCPP_INFO_STREAM(rclcpp::get_logger("lightbar_manager"),"Initalizing lightbar manager node...");
44
45 // Load the spin rate param to determine how fast to process messages
46 // Default rate 10.0 Hz
47 get_parameter<double>("spin_rate_hz", config_.spin_rate_hz);
48
49 request_control_server_= create_service<carma_msgs::srv::RequestIndicatorControl>("request_control", std::bind(&LightBarManager::requestControlCallBack, this, std_ph::_1, std_ph::_2, std_ph::_3));
50 release_control_server_= create_service<carma_msgs::srv::ReleaseIndicatorControl>("release_control", std::bind(&LightBarManager::releaseControlCallBack, this, std_ph::_1, std_ph::_2, std_ph::_3));
51 set_indicator_server_= create_service<carma_driver_msgs::srv::SetLightBarIndicator>("set_indicator", std::bind(&LightBarManager::setIndicatorCallBack, this, std_ph::_1, std_ph::_2, std_ph::_3));
52 indicator_control_publisher_ = create_publisher<carma_msgs::msg::LightBarIndicatorControllers>("indicator_control", 5);
53 guidance_state_subscriber_ = create_subscription<carma_planning_msgs::msg::GuidanceState>("state", 5, std::bind(&LightBarManager::stateChangeCallBack, this, std_ph::_1));
54 turn_signal_subscriber_ = create_subscription<automotive_platform_msgs::msg::TurnSignalCommand>("turn_signal_command", 5, std::bind(&LightBarManager::turnSignalCallback, this, std_ph::_1));
55 lightbar_driver_client_ = create_client<carma_driver_msgs::srv::SetLights>("set_lights");
56
57 // Load Conversion table, CDAType to Indicator mapping
58
59 rclcpp::Parameter lightbar_cda_table_param = get_parameter("lightbar_cda_table");
60 if (lightbar_cda_table_param.get_type() != rclcpp::ParameterType::PARAMETER_NOT_SET)
61 config_.lightbar_cda_table = lightbar_cda_table_param.as_string_array();
62
63 rclcpp::Parameter lightbar_ind_table_param = get_parameter("lightbar_ind_table");
64 if (lightbar_ind_table_param.get_type() != rclcpp::ParameterType::PARAMETER_NOT_SET)
65 config_.lightbar_ind_table = lightbar_ind_table_param.as_string_array();
66
68 {
69 throw std::invalid_argument("Size of lightbar_cda_table is not same as that of lightbar_ind_table");
70 }
71
73
74 // Initialize indicator control map. Fills with supporting indicators with empty string name as owners.
75 lbm_->setIndicatorControllers();
76
77 // Initialize indicator representation of lightbar status to all OFF
78 for (int i =0; i < INDICATOR_COUNT; i++)
79 lbm_->light_status.push_back(OFF);
80
81 rclcpp::Parameter lightbar_priorities_param = get_parameter("lightbar_priorities");
82 if (lightbar_priorities_param.get_type() != rclcpp::ParameterType::PARAMETER_NOT_SET)
83 {
84 config_.lightbar_priorities = lightbar_priorities_param.as_string_array();
85 lbm_->control_priorities = config_.lightbar_priorities;
86 }
87
88 // Take control of green light
89 get_parameter<bool>("normal_operation", config_.normal_operation);
90
91 RCLCPP_INFO_STREAM(rclcpp::get_logger("lightbar_manager"), "Loaded params: " << config_);
92
93 std::vector<LightBarIndicator> denied_list, greens = {GREEN_SOLID, GREEN_FLASH};
94
95 denied_list = lbm_->requestControl(greens, node_name_);
96 if (denied_list.size() != 0)
97 {
99 {
100 RCLCPP_WARN_STREAM(rclcpp::get_logger("lightbar_manager"),"In fuction " << __FUNCTION__ << ", LightBarManager was not able to take control of all green indicators."
101 << ".\n Please check priority list rosparameter, and ensure " << node_name_ << " has the highest priority."
102 << ".\n If this is intended, pass false to normal_operation argument. Exiting...");
103 throw INVALID_LIGHTBAR_MANAGER_PRIORITY();
104 }
105 else
106 {
107 RCLCPP_WARN_STREAM(rclcpp::get_logger("lightbar_manager"),"In fuction " << __FUNCTION__ << ", LightBarManager was not able to take control of all green indicators."
108 << ".\n Resuming...");
109 }
110 }
111 return CallbackReturn::SUCCESS;
112}
carma_ros2_utils::PubPtr< carma_msgs::msg::LightBarIndicatorControllers > indicator_control_publisher_
void turnSignalCallback(automotive_platform_msgs::msg::TurnSignalCommand::UniquePtr msg_ptr)
Callback function for turning signal.
carma_ros2_utils::SubPtr< automotive_platform_msgs::msg::TurnSignalCommand > turn_signal_subscriber_
carma_ros2_utils::ClientPtr< carma_driver_msgs::srv::SetLights > lightbar_driver_client_
bool requestControlCallBack(const std::shared_ptr< rmw_request_id_t >, const std::shared_ptr< carma_msgs::srv::RequestIndicatorControl::Request > req, std::shared_ptr< carma_msgs::srv::RequestIndicatorControl::Response > resp)
carma_ros2_utils::ServicePtr< carma_msgs::srv::ReleaseIndicatorControl > release_control_server_
bool releaseControlCallBack(const std::shared_ptr< rmw_request_id_t >, const std::shared_ptr< carma_msgs::srv::ReleaseIndicatorControl::Request > req, std::shared_ptr< carma_msgs::srv::ReleaseIndicatorControl::Response > resp)
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::GuidanceState > guidance_state_subscriber_
void stateChangeCallBack(carma_planning_msgs::msg::GuidanceState::UniquePtr msg_ptr)
carma_ros2_utils::ServicePtr< carma_driver_msgs::srv::SetLightBarIndicator > set_indicator_server_
carma_ros2_utils::ServicePtr< carma_msgs::srv::RequestIndicatorControl > request_control_server_
bool setIndicatorCallBack(const std::shared_ptr< rmw_request_id_t >, const std::shared_ptr< carma_driver_msgs::srv::SetLightBarIndicator::Request > req, std::shared_ptr< carma_driver_msgs::srv::SetLightBarIndicator::Response > resp)
#define INDICATOR_COUNT
std::vector< std::string > lightbar_priorities
std::vector< std::string > lightbar_cda_table
std::vector< std::string > lightbar_ind_table

References config_, lightbar_manager::GREEN_FLASH, lightbar_manager::GREEN_SOLID, guidance_state_subscriber_, process_bag::i, indicator_control_publisher_, INDICATOR_COUNT, lbm_, lightbar_manager::Config::lightbar_cda_table, lightbar_driver_client_, lightbar_manager::Config::lightbar_ind_table, lightbar_manager::Config::lightbar_priorities, node_name_, lightbar_manager::Config::normal_operation, lightbar_manager::OFF, release_control_server_, releaseControlCallBack(), request_control_server_, requestControlCallBack(), set_indicator_server_, setIndicatorCallBack(), lightbar_manager::Config::spin_rate_hz, stateChangeCallBack(), turn_signal_subscriber_, and turnSignalCallback().

Here is the call graph for this function:

◆ processTurnSignal()

void LightBarManager::processTurnSignal ( const automotive_platform_msgs::msg::TurnSignalCommand &  msg)
private

Turn signal callback function helper.

Returns

Definition at line 273 of file lightbar_manager_node.cpp.

274{
275 // if not automated
276 if (msg.mode != 1)
277 {
278 return;
279 }
280
281 // check if left or right signal should be controlled, or none at all
282 std::vector<lightbar_manager::LightBarIndicator> changed_turn_signal = lbm_->handleTurnSignal(msg);
283
284
285 if (changed_turn_signal.empty())
286 {
287 return; //no need to do anything if it is same turn signal changed
288 }
289
290 lightbar_manager::IndicatorStatus indicator_status;
291 // check if we should turn off or on given any indicator
292 if (msg.turn_signal == automotive_platform_msgs::msg::TurnSignalCommand::NONE)
293 {
295 }
296 else
297 {
298 indicator_status = lightbar_manager::IndicatorStatus::ON;
299 prev_owners_before_turn_ = lbm_->getIndicatorControllers(); // save the owner if new turn is starting
300
301 }
302 if (lbm_->requestControl(changed_turn_signal, node_name_).empty())
303 {
304 int response_code = 0;
305 response_code = setIndicator(changed_turn_signal[0], indicator_status, node_name_);
306 if (response_code != 0)
307 RCLCPP_ERROR_STREAM(rclcpp::get_logger("lightbar_manager"),"In Function " << __FUNCTION__ << ": LightBarManager was not able to set light of indicator ID:"
308 << changed_turn_signal[0] << ". Response code: " << response_code);
309 }
310 else
311 {
312 std::string turn_string = msg.turn_signal == automotive_platform_msgs::msg::TurnSignalCommand::LEFT ? "left" : "right";
313 RCLCPP_WARN_STREAM(rclcpp::get_logger("lightbar_manager"),"Lightbar was not able to take control of lightbar to indicate " << turn_string << "turn!");
314 return;
315 }
316
317 // release control if it is turning off and put back the previous owners
318 if (indicator_status == lightbar_manager::IndicatorStatus::OFF)
319 {
320 lbm_->releaseControl(changed_turn_signal, node_name_);
321 // we need to force set the <indicator, owner> mapping
322 // as series of requestControl may not be able to exactly achieve previous combination
323 lbm_->setIndicatorControllers(prev_owners_before_turn_);
324 // reset as the turn is finished
326 }
327}
int setIndicator(LightBarIndicator ind, IndicatorStatus ind_status, const std::string &requester_name)
Try to turn the given indicator ON or OFF (comm with hardware) upon the given component's request.
std::map< lightbar_manager::LightBarIndicator, std::string > prev_owners_before_turn_

References lbm_, node_name_, lightbar_manager::OFF, lightbar_manager::ON, prev_owners_before_turn_, and setIndicator().

Referenced by turnSignalCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ releaseControlCallBack()

bool LightBarManager::releaseControlCallBack ( const std::shared_ptr< rmw_request_id_t >  ,
const std::shared_ptr< carma_msgs::srv::ReleaseIndicatorControl::Request >  req,
std::shared_ptr< carma_msgs::srv::ReleaseIndicatorControl::Response >  resp 
)
private

Definition at line 204 of file lightbar_manager_node.cpp.

207{
208 std::vector<LightBarIndicator> ind_list;
209
210 // Use CDAType if the field is not empty in the request
211 if (req->cda_list.size() != 0)
212 {
213 for (auto cda_type : req->cda_list)
214 {
215 // return false if invalid indicator number
216 if (static_cast<uint8_t>(cda_type.type) >= INDICATOR_COUNT)
217 return false;
218 ind_list.push_back(lbm_->getIndicatorFromCDAType(static_cast<LightBarCDAType>(cda_type.type)));
219 }
220 }
221 else
222 {
223 for (auto indicator : req->ind_list)
224 {
225 // return false if invalid cda_type number
226 if (static_cast<uint8_t>(indicator.indicator) >= INDICATOR_COUNT)
227 return false;
228 ind_list.push_back(static_cast<LightBarIndicator>(indicator.indicator));
229 }
230 }
231 lbm_->releaseControl(ind_list, req->requester_name);
232 return true;
233}

References INDICATOR_COUNT, and lbm_.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ requestControlCallBack()

bool LightBarManager::requestControlCallBack ( const std::shared_ptr< rmw_request_id_t >  ,
const std::shared_ptr< carma_msgs::srv::RequestIndicatorControl::Request >  req,
std::shared_ptr< carma_msgs::srv::RequestIndicatorControl::Response >  resp 
)
private

Definition at line 152 of file lightbar_manager_node.cpp.

155{
156 std::vector<LightBarIndicator> ind_list, controlled_ind_list;
157 std::vector<LightBarCDAType> controlled_cda_type_list;
158
159 // Use CDAType if the field is not empty in the request
160 if (req->cda_list.size() != 0)
161 {
162 for (auto cda_type : req->cda_list)
163 {
164 // return false if invalid cda_type number
165 if (static_cast<uint8_t>(cda_type.type) >= INDICATOR_COUNT)
166 return false;
167 ind_list.push_back(lbm_->getIndicatorFromCDAType(static_cast<LightBarCDAType>(cda_type.type)));
168 }
169 }
170 else
171 {
172 for (auto indicator : req->ind_list)
173 {
174 // return false if invalid indicator number
175 if (static_cast<uint8_t>(indicator.indicator) >= INDICATOR_COUNT)
176 return false;
177 ind_list.push_back(static_cast<LightBarIndicator>(indicator.indicator));
178 }
179
180 }
181
182 controlled_ind_list = lbm_->requestControl(ind_list, req->requester_name);
183
184 for (auto indicator : controlled_ind_list)
185 {
186 try
187 {
188 // Some indicators do not have mapped CDAType
189 controlled_cda_type_list.push_back(lbm_->getCDATypeFromIndicator(indicator));
190 }
191 catch(INDICATOR_NOT_MAPPED)
192 {
193 // 4 out of 8 does not have mapping, so skip
194 continue;
195 }
196 }
197
198 // Modify the response
199 resp->cda_list = lbm_->getMsg(controlled_cda_type_list);
200 resp->ind_list = lbm_->getMsg(controlled_ind_list);
201 return true;
202}

References INDICATOR_COUNT, and lbm_.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ setIndicator()

int LightBarManager::setIndicator ( LightBarIndicator  ind,
IndicatorStatus  ind_status,
const std::string &  requester_name 
)

Try to turn the given indicator ON or OFF (comm with hardware) upon the given component's request.

Returns
Returns the status code whether if the request was successful or not

Definition at line 334 of file lightbar_manager_node.cpp.

335{
336 // Handle the msg/service translation
337 int response_code = 0;
338 if (static_cast<uint8_t>(ind) >= INDICATOR_COUNT || static_cast<uint8_t>(ind_status) > 1)
339 {
340 // Invalid indicator ID or ind_status
341 response_code = 1;
342 return response_code;
343 }
344
345 // Check if the requester has control of this light
346 std::string current_controller = lbm_->getIndicatorControllers()[ind];
347 if (requester_name == "" || current_controller != requester_name)
348 {
349 RCLCPP_WARN_STREAM(rclcpp::get_logger("lightbar_manager"),requester_name << " failed to set the LightBarIndicator ID" << ind
350 << " as this was already controlled by " << current_controller);
351 response_code = 1;
352 return response_code;
353 }
354
355 std::vector<IndicatorStatus> light_status_proposed = lbm_->setIndicator(ind, ind_status, requester_name);
356 carma_driver_msgs::msg::LightBarStatus msg = lbm_->getLightBarStatusMsg(light_status_proposed);
357 auto srv = std::make_shared<carma_driver_msgs::srv::SetLights::Request>();
358 srv->set_state = msg;
359
360 auto resp = lightbar_driver_client_->async_send_request(srv);
361
362 auto future_status = resp.wait_for(std::chrono::milliseconds(100));
363 // Try to send the request
364 if (future_status == std::future_status::ready)
365 {
366 // if successful, update the local copy.
367 lbm_->light_status = light_status_proposed;
368 response_code = 0;
369 }
370 else
371 {
372 RCLCPP_WARN_STREAM(rclcpp::get_logger("lightbar_manager"),"In function: " << __FUNCTION__ << ": Failed to set lights. ROSservice call to the driver failed. ");
373 response_code = 2;
374 }
375 return response_code;
376
377}

References INDICATOR_COUNT, lbm_, lightbar_driver_client_, and srv.

Referenced by processTurnSignal(), setIndicatorCallBack(), stateChangeCallBack(), and turnOffAll().

Here is the caller graph for this function:

◆ setIndicatorCallBack()

bool LightBarManager::setIndicatorCallBack ( const std::shared_ptr< rmw_request_id_t >  ,
const std::shared_ptr< carma_driver_msgs::srv::SetLightBarIndicator::Request >  req,
std::shared_ptr< carma_driver_msgs::srv::SetLightBarIndicator::Response >  resp 
)
private

Definition at line 379 of file lightbar_manager_node.cpp.

382{
383 LightBarIndicator indicator;
384 int response_code = 0;
385 if (req->cda_type.type != NULL)
386 indicator = lbm_->getIndicatorFromCDAType(static_cast<LightBarCDAType>(req->cda_type.type));
387 else
388 indicator = static_cast<LightBarIndicator>(req->indicator.indicator);
389
390 response_code = setIndicator(indicator, static_cast<IndicatorStatus>(req->state), req->requester_name);
391 resp->status_code = response_code;
392 if (response_code != 0)
393 return false;
394
395 return true;
396}

References lbm_, and setIndicator().

Referenced by handle_on_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spinCallBack()

bool LightBarManager::spinCallBack ( )
private

Definition at line 235 of file lightbar_manager_node.cpp.

236{
237 indicator_control_publisher_->publish(lbm_->getMsg(lbm_->getIndicatorControllers()));
238 return true;
239}

References indicator_control_publisher_, and lbm_.

Referenced by handle_on_activate().

Here is the caller graph for this function:

◆ stateChangeCallBack()

void LightBarManager::stateChangeCallBack ( carma_planning_msgs::msg::GuidanceState::UniquePtr  msg_ptr)
private

Definition at line 241 of file lightbar_manager_node.cpp.

242{
243 // Relay the msg to state machine
244 LightBarState prev_lightbar_state = lbm_->getCurrentState();
245 lbm_->handleStateChange(*msg_ptr);
246
247 // Change green lights depending on states, no need to check if its current owner, as it will always be for green lights
248 LightBarState curr_lightbar_state = lbm_->getCurrentState();
249 if (curr_lightbar_state != prev_lightbar_state)
250 {
251 switch(curr_lightbar_state)
252 {
253 case DISENGAGED:
254 turnOffAll();
255 break;
256 case ACTIVE:
258 break;
259 case ENGAGED:
261 break;
262 default:
263 break;
264 }
265 }
266}
void turnOffAll()
Miscellaneous function that forces the state to disengaged and turn off all indicators....

References lightbar_manager::ACTIVE, lightbar_manager::DISENGAGED, lightbar_manager::ENGAGED, lightbar_manager::GREEN_FLASH, lightbar_manager::GREEN_SOLID, lbm_, node_name_, lightbar_manager::ON, setIndicator(), and turnOffAll().

Referenced by handle_on_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ turnOffAll()

void LightBarManager::turnOffAll ( )

Miscellaneous function that forces the state to disengaged and turn off all indicators. Used in special demo cases as well as when carma is disengaged.

Definition at line 122 of file lightbar_manager_node.cpp.

123{
124 // All components lose controls and turn the indicators off by giving lightbarmanar the control
125 std::vector<LightBarIndicator> all_indicators;
126
127 RCLCPP_INFO_STREAM(rclcpp::get_logger("lightbar_manager"),"LightBarManager was commanded to turn off all indicators!");
128
129 for (std::pair <LightBarIndicator, std::string> element : lbm_->getIndicatorControllers())
130 all_indicators.push_back(element.first);
131
132 // Reset all controls
133 lbm_->setIndicatorControllers();
134
135 // Give lightbar manager the control which is guaranteed to succeed
136 lbm_->requestControl(all_indicators, node_name_);
137 int response_code = 0;
138 for (auto indicator : all_indicators)
139 {
140 response_code = setIndicator(indicator, OFF, node_name_);
141 if (response_code != 0)
142 RCLCPP_WARN_STREAM(rclcpp::get_logger("lightbar_manager"),"In Function " << __FUNCTION__ << ": LightBarManager was not able to turn off indicator ID:"
143 << indicator << ". Response code: " << response_code);
144 }
145
146 // Once forced them off, release controls in case carma is still running so that lightbar_manager does not hog the control
147 all_indicators.erase(std::remove(all_indicators.begin(), all_indicators.end(), GREEN_FLASH), all_indicators.end());
148 all_indicators.erase(std::remove(all_indicators.begin(), all_indicators.end(), GREEN_SOLID), all_indicators.end());
149 lbm_->releaseControl(all_indicators, node_name_);
150}

References lightbar_manager::GREEN_FLASH, lightbar_manager::GREEN_SOLID, lbm_, node_name_, lightbar_manager::OFF, and setIndicator().

Referenced by stateChangeCallBack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ turnSignalCallback()

void LightBarManager::turnSignalCallback ( automotive_platform_msgs::msg::TurnSignalCommand::UniquePtr  msg_ptr)

Callback function for turning signal.

Returns

Definition at line 268 of file lightbar_manager_node.cpp.

269{
270 return processTurnSignal(*msg_ptr);
271}
void processTurnSignal(const automotive_platform_msgs::msg::TurnSignalCommand &msg)
Turn signal callback function helper.

References processTurnSignal().

Referenced by handle_on_configure().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ config_

Config lightbar_manager::LightBarManager::config_
private

◆ guidance_state_subscriber_

carma_ros2_utils::SubPtr<carma_planning_msgs::msg::GuidanceState> lightbar_manager::LightBarManager::guidance_state_subscriber_
private

Definition at line 149 of file lightbar_manager_node.hpp.

Referenced by handle_on_configure().

◆ indicator_control_publisher_

carma_ros2_utils::PubPtr<carma_msgs::msg::LightBarIndicatorControllers> lightbar_manager::LightBarManager::indicator_control_publisher_
private

Definition at line 146 of file lightbar_manager_node.hpp.

Referenced by handle_on_configure(), and spinCallBack().

◆ lbm_

◆ lightbar_driver_client_

carma_ros2_utils::ClientPtr<carma_driver_msgs::srv::SetLights> lightbar_manager::LightBarManager::lightbar_driver_client_
private

Definition at line 143 of file lightbar_manager_node.hpp.

Referenced by handle_on_configure(), and setIndicator().

◆ node_name_

std::string lightbar_manager::LightBarManager::node_name_ = "lightbar_manager"
private

◆ prev_owners_before_turn_

std::map<lightbar_manager::LightBarIndicator, std::string> lightbar_manager::LightBarManager::prev_owners_before_turn_
private

Definition at line 122 of file lightbar_manager_node.hpp.

Referenced by processTurnSignal().

◆ pub_timer_

rclcpp::TimerBase::SharedPtr lightbar_manager::LightBarManager::pub_timer_
private

Definition at line 155 of file lightbar_manager_node.hpp.

Referenced by handle_on_activate().

◆ release_control_server_

carma_ros2_utils::ServicePtr<carma_msgs::srv::ReleaseIndicatorControl> lightbar_manager::LightBarManager::release_control_server_
private

Definition at line 141 of file lightbar_manager_node.hpp.

Referenced by handle_on_configure().

◆ request_control_server_

carma_ros2_utils::ServicePtr<carma_msgs::srv::RequestIndicatorControl> lightbar_manager::LightBarManager::request_control_server_
private

Definition at line 140 of file lightbar_manager_node.hpp.

Referenced by handle_on_configure().

◆ set_indicator_server_

carma_ros2_utils::ServicePtr<carma_driver_msgs::srv::SetLightBarIndicator> lightbar_manager::LightBarManager::set_indicator_server_
private

Definition at line 142 of file lightbar_manager_node.hpp.

Referenced by handle_on_configure().

◆ spin_rate_

double lightbar_manager::LightBarManager::spin_rate_ = 10.0
private

Definition at line 121 of file lightbar_manager_node.hpp.

◆ turn_signal_subscriber_

carma_ros2_utils::SubPtr<automotive_platform_msgs::msg::TurnSignalCommand> lightbar_manager::LightBarManager::turn_signal_subscriber_
private

Definition at line 150 of file lightbar_manager_node.hpp.

Referenced by handle_on_configure().


The documentation for this class was generated from the following files: