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.
driver_manager.cpp
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
18#include <boost/algorithm/string.hpp>
19#include <lifecycle_msgs/msg/state.hpp>
20#include <rclcpp/logger.hpp>
21#include <rclcpp/logging.hpp>
23
24
25using std_msec = std::chrono::milliseconds;
26
28{
30
31 DriverManager::DriverManager(const std::vector<std::string>& critical_driver_names,
32 const std::vector<std::string>& camera_entries,
33 const long driver_timeout)
34 : critical_drivers_(critical_driver_names.begin(), critical_driver_names.end()),
35 camera_entries_(camera_entries.begin(), camera_entries.end()),
36 driver_timeout_(driver_timeout)
37 {
38 // Intialize entry manager
39 em_ = std::make_shared<EntryManager>(critical_driver_names, camera_entries);
40
41 }
42
43
44 carma_msgs::msg::SystemAlert DriverManager::handle_spin(long time_now,long start_up_timestamp,long startup_duration)
45 {
46 carma_msgs::msg::SystemAlert alert;
47
48 std::string status = are_critical_drivers_operational(time_now);
49 if(status.compare("s_1_c_1") == 0)
50 {
51 starting_up_ = false;
52 alert.description = "All essential drivers are ready";
53 alert.type = carma_msgs::msg::SystemAlert::DRIVERS_READY;
54 return alert;
55 }
56 else if(starting_up_ && (time_now - start_up_timestamp <= startup_duration))
57 {
58 alert.description = "System is starting up...";
59 alert.type = carma_msgs::msg::SystemAlert::NOT_READY;
60 return alert;
61 }
62 else if(status.compare("s_1_c_0")==0)
63 {
64 alert.description = "Camera Failed";
66 return alert;
67 }
68 else if(status.compare("s_0") == 0)
69 {
70 alert.description = "SSC Failed";
72 return alert;
73 }
74 else
75 {
76 alert.description = "Unknown problem assessing essential driver availability";
77 alert.type = carma_msgs::msg::SystemAlert::FATAL;
78 return alert;
79 }
80
81 }
82
83
84 void DriverManager::update_driver_status(const carma_driver_msgs::msg::DriverStatus::SharedPtr msg, long current_time)
85 {
86 // update driver status is only called in response to a message received on driver_discovery. This topic is only being published in ros1
87 Entry driver_status(msg->status == carma_driver_msgs::msg::DriverStatus::OPERATIONAL || msg->status == carma_driver_msgs::msg::DriverStatus::DEGRADED,
88 msg->name,current_time);
89
90 em_->update_entry(driver_status);
91 }
92
93
94 void DriverManager::evaluate_sensor(int &sensor_input,bool available,long current_time,long timestamp,long driver_timeout)
95 {
96
97 if((!available) || (current_time-timestamp > driver_timeout))
98 {
99 sensor_input=0;
100 }
101 else
102 {
103 sensor_input=1;
104 }
105
106 }
107
109 {
110 int ssc=0;
111 int camera=0;
112
113 std::vector<Entry> driver_list = em_->get_entries(); //Real time driver list from driver status
114 for(auto i = driver_list.begin(); i < driver_list.end(); ++i)
115 {
116 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("subsystem_controller"), "i->name_: " << i->name_
117 << ", current_time: " << current_time
118 << ", i->timestamp_: " << i->timestamp_
119 << ", difference: " << current_time-(i->timestamp_) );
120 if(em_->is_entry_required(i->name_))
121 {
122 evaluate_sensor(ssc,i->available_,current_time,i->timestamp_,driver_timeout_);
123 }
124 else if(em_->is_camera_entry_required(i->name_)==0)
125 {
126 evaluate_sensor(camera,i->available_,current_time,i->timestamp_,driver_timeout_);
127 }
128 }
129
130 // Manual disable of ssc entry in case ssc wrapper is in ros2
131 if (critical_drivers_.empty())
132 {
133 ssc = 1;
134 }
135
137 //Decision making
138 if (ssc == 1 && camera == 1)
139 {
140 return "s_1_c_1";
141 }
142 else if (ssc == 1 && camera == 0)
143 {
144 return "s_1_c_0";
145 }
146 else{
147 return "s_0";
148 }
149
150
151 }
152
153
154}
std::chrono::milliseconds std_msec
void update_driver_status(const carma_driver_msgs::msg::DriverStatus::SharedPtr msg, long current_time)
Update driver status.
std::string are_critical_drivers_operational(long current_time)
Check if all critical drivers are operational.
carma_msgs::msg::SystemAlert handle_spin(long time_now, long start_up_timestamp, long startup_duration)
Handle the spin and publisher.
std::shared_ptr< EntryManager > em_
Entry manager to keep track of detected plugins.
std::vector< std::string > critical_drivers_
void evaluate_sensor(int &sensor_input, bool available, long current_time, long timestamp, long driver_timeout)
Evaluate if the sensor is available.
DriverManager()
Default constructor for DriverManager with driver_timeout_ = 1000ms.
An entry represents a driver details for the purposes of tracking.
Definition: entry.hpp:27