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.
ssc_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
18
19#include <boost/algorithm/string.hpp>
20#include <rclcpp/logger.hpp>
21#include <rclcpp/logging.hpp>
22
23#include <lifecycle_msgs/msg/state.hpp>
24
25using std_msec = std::chrono::milliseconds;
26
28{
30
31SSCDriverManager::SSCDriverManager(const std::string & ssc_driver_name, const long driver_timeout)
32: ssc_driver_name_(ssc_driver_name), driver_timeout_(driver_timeout)
33{
34}
35
36carma_msgs::msg::SystemAlert SSCDriverManager::get_latest_system_alert(
37 long time_now, long start_up_timestamp, long startup_duration)
38{
39 carma_msgs::msg::SystemAlert alert;
40
41 bool ssc_is_operational = is_ssc_driver_operational(time_now);
42 if (ssc_is_operational) {
43 starting_up_ = false;
44 alert.description = "All essential drivers are ready";
45 alert.type = carma_msgs::msg::SystemAlert::DRIVERS_READY;
46 return alert;
47 } else if (starting_up_ && (time_now - start_up_timestamp <= startup_duration)) {
48 alert.description = "System is starting up...";
49 alert.type = carma_msgs::msg::SystemAlert::NOT_READY;
50 return alert;
51 } else if (!ssc_is_operational) {
52 alert.description = "SSC Failed";
54 return alert;
55 } else {
56 alert.description = "Unknown problem assessing SSC driver availability";
57 alert.type = carma_msgs::msg::SystemAlert::FATAL;
58 return alert;
59 }
60}
61
63 const carma_driver_msgs::msg::DriverStatus::SharedPtr msg, long current_time)
64{
65 // update driver status is only called in response to a message received on driver_discovery.
66 // This topic is only being published in ros1. Check only SSC
67
68 if (ssc_driver_name_ == msg->name) {
69 Entry driver_status(
70 msg->status == carma_driver_msgs::msg::DriverStatus::OPERATIONAL ||
71 msg->status == carma_driver_msgs::msg::DriverStatus::DEGRADED,
72 msg->name, current_time);
73
74 latest_ssc_status_entry_ = std::make_shared<Entry>(driver_status);
75 }
76}
77
79{
80 // Manual disable of ssc entry in case ssc wrapper is in ros2
81 if (ssc_driver_name_.empty()) {
82 return true;
83 }
84
85 // No entry recorded, then return false
87 return false;
88 }
89
90 RCLCPP_DEBUG_STREAM(
91 rclcpp::get_logger("subsystem_controller"),
92 "latest_ssc_status_entry_->name_: "
93 << latest_ssc_status_entry_->name_ << ", current_time: " << current_time
94 << ", latest_ssc_status_entry_->timestamp_: " << latest_ssc_status_entry_->timestamp_
95 << ", difference: " << current_time - (latest_ssc_status_entry_->timestamp_));
96
97 // Detect whether if available or timed out
98 if (
99 (!latest_ssc_status_entry_->available_) ||
100 (current_time - latest_ssc_status_entry_->timestamp_ > driver_timeout_)) {
101 return false;
102 } else {
103 return true;
104 }
105}
106
107} // namespace subsystem_controllers
std::chrono::milliseconds std_msec
bool is_ssc_driver_operational(long current_time)
Check if all critical drivers are operational.
SSCDriverManager()
Default constructor for SSCDriverManager with driver_timeout_ = 1000ms.
std::shared_ptr< Entry > latest_ssc_status_entry_
Latest SSC Status entry to keep track.
void update_driver_status(const carma_driver_msgs::msg::DriverStatus::SharedPtr msg, long current_time)
Update driver status.
carma_msgs::msg::SystemAlert get_latest_system_alert(long time_now, long start_up_timestamp, long startup_duration)
Handle the spin and publisher.
An entry represents a driver details for the purposes of tracking.
Definition: entry.hpp:27