Apollo 11.0
自动驾驶开放平台
control_task_extend.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 *****************************************************************************/
16
23
24#include <memory>
25#include <string>
26
27#include "absl/strings/str_cat.h"
28
29#include <cxxabi.h>
30
31#include "cyber/common/log.h"
32#include "cyber/time/clock.h"
34
39namespace apollo {
40namespace control {
41
45
46ControlTaskExtend::ControlTaskExtend() : name_("Control Task Base Extend") {
47 AINFO << "Using " << name_ << ".";
48}
49
51 const std::string &calibration_table_path,
52 calibration_table *calibration_table_conf) {
53 std::string calibration_table_path_absolute
54 = absl::StrCat("/apollo/modules/control/control_component/conf/", calibration_table_path);
55 if (!apollo::cyber::common::GetProtoFromFile(calibration_table_path_absolute, calibration_table_conf)) {
56 AERROR << "Load calibration table failed!";
57 return false;
58 }
59 AINFO << "Load the calibraiton table file successfully, file path: " << calibration_table_path_absolute;
60 return true;
61}
62
64 const localization::LocalizationEstimate *localization,
65 const canbus::Chassis *chassis,
66 const planning::ADCTrajectory *trajectory) {
67 localization_ = localization;
68 chassis_ = chassis;
69 trajectory_message_ = trajectory;
70 ACHECK(localization_ != nullptr) << "Fail to get localization msg!";
71 ACHECK(chassis_ != nullptr) << "Fail to get chassis msg!";
72 ACHECK(trajectory_message_ != nullptr) << "Fail to get trajectory msg!";
73
76
77 return true;
78}
79
81 bool is_forward = false;
82 if (chassis_->gear_location() != trajectory_message_->gear()) {
84 is_forward = true;
85 } else {
86 is_forward = false;
87 }
88 } else {
89 if (trajectory_message_->gear() != canbus::Chassis::GEAR_REVERSE) {
90 is_forward = true;
91 } else {
92 is_forward = false;
93 }
94 }
95 return is_forward;
96}
97
99 bool is_in_edge_follow = false;
100 if (trajectory_message_->trajectory_type() == ADCTrajectory::EDGE_FOLLOW) {
101 is_in_edge_follow = true;
102 }
103 return is_in_edge_follow;
104}
105
107 double pit_replan_check_time,
108 double pit_replan_check_count,
109 double vehicle_speed,
110 bool replan) {
111 static std::pair<double, int> replan_count(0, 0);
112
114
115 if (now - replan_count.first > pit_replan_check_time) {
116 replan_count.first = 0;
117 replan_count.second = 0;
118 }
119
120 if (replan) {
121 if (now - replan_count.first > pit_replan_check_time) {
122 replan_count.first = now;
123 replan_count.second = 1;
124 } else {
125 replan_count.first = now;
126 replan_count.second++;
127 }
128 }
129
130 const auto &vehicle_param = common::VehicleConfigHelper::GetConfig().vehicle_param();
131 if (replan_count.second >= pit_replan_check_count
132 && abs(vehicle_speed) < vehicle_param.max_abs_speed_when_stopped()) {
133 return true;
134 } else {
135 return false;
136 }
137}
138
139std::string ControlTaskExtend::Name() const {
140 return name_;
141}
142
144 const double ref_curvature,
145 const double min_large_ref_curvature,
146 bool *is_in_large_curvature) {
147 ADEBUG << "Into IsLargeCurvature. " << "ref_curvature is " << ref_curvature << ", min_large_ref_curvature is "
148 << min_large_ref_curvature;
149 bool is_in_large_cur = false;
150 if (ref_curvature > min_large_ref_curvature) {
151 ADEBUG << "ref_curvature is " << ref_curvature << ", in large curvature.";
152 is_in_large_cur = true;
153 *is_in_large_curvature = is_in_large_cur;
154 return true;
155 } else {
156 is_in_large_cur = false;
157 *is_in_large_curvature = is_in_large_cur;
158 return false;
159 }
160}
161
162bool ControlTaskExtend::IsLeftCurvature(const double ref_curvature) {
163 bool is_left_cur = false;
164 if (ref_curvature > 0) {
165 is_left_cur = true;
166 }
167 return is_left_cur;
168}
169
171 std::shared_ptr<DependencyInjector> injector,
172 const bool &use_filter,
173 const double &filter_coeff) {
174 double vehicle_speed = injector->vehicle_state()->linear_velocity();
175 if (use_filter) {
176 // vehicle move direction changed, then reset filter
177 if (vehicle_speed * vehicle_speed_last_ < 0) {
178 vehicle_speed_last_ = 0.0;
179 }
180 vehicle_speed = ExponentialSmoothing::exponential_smoothing(vehicle_speed, vehicle_speed_last_, filter_coeff);
181 }
182 vehicle_speed_last_ = vehicle_speed;
183 return vehicle_speed;
184}
185
187 const bool &use_filter,
188 const double &filter_coeff,
189 const double &throttle) {
190 double throttle_filtered = throttle;
191 if (use_filter) {
192 throttle_filtered = ExponentialSmoothing::exponential_smoothing(throttle, throttle_last_, filter_coeff);
193 throttle_last_ = throttle_filtered;
194 }
195
196 return throttle_filtered;
197}
198
199
200} // namespace control
201} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
bool IsLargeCurvature(const double ref_curvature, const double min_large_ref_curvature, bool *is_in_large_curvature)
double ThrottleCmdFilter(const bool &use_filter, const double &filter_coeff, const double &throttle)
bool VehicleStatusIdentificationUpdate(const localization::LocalizationEstimate *localization, const canbus::Chassis *chassis, const planning::ADCTrajectory *trajectory)
bool IsLeftCurvature(const double ref_curvature)
std::string Name() const
reset ControlTaskAgent
bool LoadCalibrationTable(const std::string &calibration_table_path, calibration_table *calibration_table_conf)
bool CheckInPit(double pit_replan_check_time, double pit_replan_check_count, double vehicle_speed, bool replan)
double GetVehicleSpeed(std::shared_ptr< DependencyInjector > injector, const bool &use_filter, const double &filter_coeff)
static double exponential_smoothing(const double &current_value, const double &last_value, const double &alpha)
static double NowInSeconds()
gets the current time in second.
Definition clock.cc:56
Defines the Controller base class.
#define ACHECK(cond)
Definition log.h:80
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
class register implement
Definition arena_queue.h:37
optional GearPosition gear_location
optional VehicleParam vehicle_param
optional TrajectoryType trajectory_type
optional apollo::canbus::Chassis::GearPosition gear