Apollo 11.0
自动驾驶开放平台
control_checker.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
18
19#include <algorithm>
20
21#include "cyber/common/log.h"
22
23namespace apollo {
24namespace control {
25
27 // if (!ControlUtil::is_need_safety_check()) {
28 // return NONE;
29 // }
30 double max_lateral_error_E = conf.check_threshold().max_lateral_error_e();
31 double max_lateral_error_W = conf.check_threshold().max_lateral_error_w();
32 // lateral error e check
33 if (conf.use_lateral_error_e_check()) {
34 if (std::fabs(*lateral_error) > max_lateral_error_E) {
35 ADEBUG << "[Error] lateral error is not reliable due to: |" << *lateral_error << "| > "
36 << max_lateral_error_E;
37 *lateral_error = common::math::Clamp(*lateral_error, -max_lateral_error_E, max_lateral_error_E);
38 ADEBUG << "[Error] control lateral e failed.";
39 return ERROR;
40 }
41 } else {
42 ADEBUG << "control lateral error e check turn off.";
43 }
44 // lateral error warning check
45 if (conf.use_lateral_error_w_check()) {
46 if (std::fabs(*lateral_error) > max_lateral_error_W) {
47 ADEBUG << "[Warning] lateral error is not reliable due to: |" << *lateral_error << "| > "
48 << max_lateral_error_W;
49 ADEBUG << "[Warning] control lateral w failed.";
50 return WARNING;
51 }
52 } else {
53 ADEBUG << "control lateral error w check turn off.";
54 }
55
56 return NONE;
57}
58
60 // if (!ControlUtil::is_need_safety_check()) {
61 // return NONE;
62 // }
63 double max_heading_error_E = conf.check_threshold().max_heading_error_e();
64 double max_heading_error_W = conf.check_threshold().max_heading_error_w();
65 // heading error error check
66 if (conf.use_heading_error_e_check()) {
67 if (std::fabs(*heading_error) > max_heading_error_E) {
68 ADEBUG << "[Error] heading error is not reliable due to: |" << *heading_error << "| > "
69 << max_heading_error_E;
70 *heading_error = common::math::Clamp(*heading_error, -max_heading_error_E, max_heading_error_E);
71 ADEBUG << "[Error] control heading e failed.";
72 return ERROR;
73 }
74 } else {
75 ADEBUG << "control heading error e check turn off.";
76 }
77 // heading error warning check
78 if (conf.use_heading_error_w_check()) {
79 if (std::fabs(*heading_error) > max_heading_error_W) {
80 ADEBUG << "[Warning] heading error is not reliable due to: |" << *heading_error << "| > "
81 << max_heading_error_W;
82 ADEBUG << "[Warning] control heading w failed.";
83 return WARNING;
84 }
85 } else {
86 ADEBUG << "control heading error w check turn off.";
87 }
88
89 return NONE;
90}
91
93 // if (!ControlUtil::is_need_safety_check()) {
94 // return NONE;
95 // }
96 double max_station_error_E = conf.check_threshold().max_station_error_e();
97 double max_station_error_W = conf.check_threshold().max_station_error_w();
98 // station error error check
99 if (conf.use_station_error_e_check()) {
100 if (std::fabs(*station_error) > max_station_error_E) {
101 ADEBUG << "[Error] station error is not reliable due to: |" << *station_error << "| > "
102 << max_station_error_E;
103 *station_error = common::math::Clamp(*station_error, -max_station_error_E, max_station_error_E);
104 ADEBUG << "[Error] control station e failed.";
105 return ERROR;
106 }
107 } else {
108 ADEBUG << "control station error e check turn off.";
109 }
110 // station error warning check
111 if (conf.use_station_error_w_check()) {
112 if (std::fabs(*station_error) > max_station_error_W) {
113 ADEBUG << "[Warning] station error is not reliable due to: |" << *station_error << "| > "
114 << max_station_error_W;
115 ADEBUG << "[Warning] control station w failed.";
116 return WARNING;
117 }
118 } else {
119 ADEBUG << "control station error w check turn off.";
120 }
121
122 return NONE;
123}
124
126 // if (!ControlUtil::is_need_safety_check()) {
127 // return NONE;
128 // }
129 double max_speed_error_E = conf.check_threshold().max_speed_error_e();
130 double max_speed_error_W = conf.check_threshold().max_speed_error_w();
131 // speed error error check
132 if (conf.use_speed_error_e_check()) {
133 if (fabs(*speed_error) > max_speed_error_E) {
134 ADEBUG << "[Error] speed error is not reliable due to: |" << *speed_error << "| > " << max_speed_error_E;
135 *speed_error = common::math::Clamp(*speed_error, -max_speed_error_E, max_speed_error_E);
136 ADEBUG << "[Error] control speed e failed.";
137 return ERROR;
138 }
139 } else {
140 ADEBUG << "control speed error e check turn off.";
141 }
142 // speed error warning check
143 if (conf.use_speed_error_w_check()) {
144 if (fabs(*speed_error) > max_speed_error_W) {
145 ADEBUG << "[Warning] speed error is not reliable due to: |" << *speed_error << "| > " << max_speed_error_W;
146 ADEBUG << "[Warning] control speed w failed.";
147 return WARNING;
148 }
149 } else {
150 ADEBUG << "control speed error w check turn off.";
151 }
152
153 return NONE;
154}
155
156} // namespace control
157} // namespace apollo
static ControlCheckStatus check_station_error(const SafetyCheckConf &conf, double *station_error)
static ControlCheckStatus check_heading_error(const SafetyCheckConf &conf, double *heading_error)
static ControlCheckStatus check_speed_error(const SafetyCheckConf &conf, double *speed_error)
static ControlCheckStatus check_lateral_error(const SafetyCheckConf &conf, double *lateral_error)
Math-related util functions.
Defines the ControlChecker class.
#define ADEBUG
Definition log.h:41
T Clamp(const T value, T bound1, T bound2)
Clamp a value between two bounds.
Definition math_utils.h:155
class register implement
Definition arena_queue.h:37
optional SafetyCheckThreshold check_threshold