Apollo 10.0
自动驾驶开放平台
pid_BC_controller.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
18
19#include <cmath>
20
21#include "cyber/common/log.h"
23
24namespace apollo {
25namespace control {
26
27double PIDBCController::Control(const double error, const double dt) {
28 if (dt <= 0) {
29 AWARN << "dt <= 0, will use the last output";
30 return previous_output_;
31 }
32 double diff = 0;
33 double output = 0;
34
35 if (first_hit_) {
36 first_hit_ = false;
37 } else {
38 diff = (error - previous_error_) / dt;
39 }
40
41 // backward calculation
43 integral_ = 0;
44 } else {
45 double u = error * kp_ + integral_ + error * dt * ki_ + diff * kd_;
48 u;
49 if (aw_term > 1e-6) {
51 } else if (aw_term < -1e-6) {
53 } else {
55 }
56 integral_ += kaw_ * aw_term + error * dt;
57 }
58
59 previous_error_ = error;
60 output = common::math::Clamp(error * kp_ + integral_ + diff * kd_,
62 output_saturation_low_); // Ki already applied
63 previous_output_ = output;
64 return output;
65}
66
70
71} // namespace control
72} // namespace apollo
virtual double Control(const double error, const double dt)
compute control value based on the error, with backward-calculation-anti-windup
#define AWARN
Definition log.h:43
Math-related util functions.
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