29using apollo::monitor::SystemStatus;
38 FLAGS_chassis_topic, [
this](
const std::shared_ptr<Chassis>& chassis) {
39 ADEBUG <<
"Received chassis data: run chassis callback.";
40 std::lock_guard<std::mutex> lock(mutex_);
41 chassis_.CopyFrom(*chassis);
45 FLAGS_control_command_topic,
46 [
this](
const std::shared_ptr<ControlCommand>& cmd) {
47 ADEBUG <<
"Received control data: run control callback.";
48 std::lock_guard<std::mutex> lock(mutex_);
49 control_cmd_.CopyFrom(*cmd);
52 system_status_reader_ =
node_->CreateReader<SystemStatus>(
53 FLAGS_system_status_topic,
54 [
this](
const std::shared_ptr<SystemStatus>& status) {
55 ADEBUG <<
"Received system status data: run system status callback.";
56 std::lock_guard<std::mutex> lock(mutex_);
58 system_status_.CopyFrom(*status);
67 constexpr double kSecondsTillTimeout(2.5);
69 bool safety_mode_triggered =
false;
71 std::lock_guard<std::mutex> lock(mutex_);
72 if (
Time::Now().ToSecond() - last_status_received_s_ >
73 kSecondsTillTimeout) {
74 safety_mode_triggered =
true;
76 safety_mode_triggered =
77 safety_mode_triggered || system_status_.has_safety_mode_trigger_time();
80 if (safety_mode_triggered) {
81 ADEBUG <<
"Safety mode triggered, enable safety mode";
84 ADEBUG <<
"Safety mode not triggered, bypass control command";
85 PassThroughControlCommand();
88 common::util::FillHeader(
node_->Name(), &guardian_cmd_);
89 guardian_writer_->Write(guardian_cmd_);
93void GuardianComponent::PassThroughControlCommand() {
94 std::lock_guard<std::mutex> lock(mutex_);
95 guardian_cmd_.mutable_control_command()->CopyFrom(control_cmd_);
98void GuardianComponent::TriggerSafetyMode() {
99 AINFO <<
"Safety state triggered, with system safety mode trigger time : "
100 << system_status_.safety_mode_trigger_time();
101 std::lock_guard<std::mutex> lock(mutex_);
102 bool sensor_malfunction =
false, obstacle_detected =
false;
105 AINFO <<
"Ultrasonic sensor not enabled for faulted, will do emergency "
107 sensor_malfunction =
true;
110 for (
int i = 0; i < chassis_.
surround().sonar_range_size(); ++i) {
114 AINFO <<
"Object detected or ultrasonic sensor fault output, will do "
116 obstacle_detected =
true;
121 guardian_cmd_.mutable_control_command()->set_throttle(0.0);
122 guardian_cmd_.mutable_control_command()->set_steering_target(0.0);
123 guardian_cmd_.mutable_control_command()->set_steering_rate(25.0);
124 guardian_cmd_.mutable_control_command()->set_is_in_safe_mode(
true);
127 sensor_malfunction =
false;
128 obstacle_detected =
false;
129 AINFO <<
"Temporarily ignore the ultrasonic sensor output during hardware "
132 if (system_status_.require_emergency_stop() || sensor_malfunction ||
134 AINFO <<
"Emergency stop triggered! with system status from monitor as : "
135 << system_status_.require_emergency_stop();
136 guardian_cmd_.mutable_control_command()->set_brake(
139 AINFO <<
"Soft stop triggered! with system status from monitor as : "
140 << system_status_.require_emergency_stop();
141 guardian_cmd_.mutable_control_command()->set_brake(
bool GetProtoConfig(T *config) const
const std::string & ConfigFilePath() const
std::shared_ptr< Node > node_
Cyber has builtin time type Time.
static Time Now()
get the current time.
double ToSecond() const
convert time to second.
bool Proc() override
The Proc logic of the component, which called by the CyberRT frame.
Some string util functions.
optional Surround surround
optional bool sonar_fault
optional bool sonar_enabled
repeated double sonar_range
optional bool guardian_enable
optional double guardian_cmd_emergency_stop_percentage
optional double guardian_cmd_soft_stop_percentage