Apollo 10.0
自动驾驶开放平台
pid_IC_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#include <iostream>
21
22#include "cyber/common/log.h"
24
25namespace apollo {
26namespace control {
27
28double PIDICController::Control(const double error, const double dt) {
29 if (dt <= 0) {
30 AWARN << "dt <= 0, will use the last output";
31 return previous_output_;
32 }
33 double diff = 0;
34 double output = 0;
35
36 if (first_hit_) {
37 first_hit_ = false;
38 } else {
39 diff = (error - previous_error_) / dt;
40 }
41 // integral clamping
43 integral_ = 0;
44 } else {
45 double u = error * kp_ + integral_ + error * dt * ki_ + diff * kd_;
46 if (((error * u) > 0) &&
48 } else {
49 // Only update integral then
50 integral_ += error * dt * ki_;
51 }
52 }
53
54 previous_error_ = error;
55 output = error * kp_ + integral_ + diff * kd_;
56
57 if (output >= output_saturation_high_) {
59 } else if (output <= output_saturation_low_) {
61 } else {
63 }
64
65 output = common::math::Clamp(error * kp_ + integral_ + diff * kd_,
67 output_saturation_low_); // Ki already applied
68 previous_output_ = output;
69 return output;
70}
71
75
76} // namespace control
77} // namespace apollo
virtual double Control(const double error, const double dt)
compute control value based on the error, with integral-clamping-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