Apollo 10.0
自动驾驶开放平台
leadlag_controller.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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"
22
23namespace apollo {
24namespace control {
25
26double LeadlagController::Control(const double error, const double dt) {
27 // check if the c2d transform passed during the initilization
29 TransformC2d(dt);
31 AWARN << "C2d transform failed; will work as a unity compensator, dt: "
32 << dt;
33 return error; // treat the Lead/Lag as a unity proportional controller
34 }
35 }
36 // check if the current sampling time is valid
37 if (dt <= 0.0) {
38 AWARN << "dt <= 0, will use the last output, dt: " << dt;
39 return previous_output_;
40 }
41 double output = 0.0;
42
43 innerstate_ = (error - previous_innerstate_ * kd0_) / kd1_; // calculate
44 // the inner (intermedia) state under the Direct form II for the Lead / Lag
45 // compensator factorization
52 } else {
54 }
55
58 previous_output_ = output;
59 return output;
60}
61
68
69void LeadlagController::Init(const LeadlagConf &leadlag_conf, const double dt) {
70 previous_output_ = 0.0;
72 innerstate_ = 0.0;
74 std::fabs(leadlag_conf.innerstate_saturation_level());
76 -std::fabs(leadlag_conf.innerstate_saturation_level());
78 SetLeadlag(leadlag_conf);
79 TransformC2d(dt);
80}
81
82void LeadlagController::SetLeadlag(const LeadlagConf &leadlag_conf) {
83 alpha_ = leadlag_conf.alpha();
84 beta_ = leadlag_conf.beta();
85 tau_ = leadlag_conf.tau();
86}
87
88void LeadlagController::TransformC2d(const double dt) {
89 if (dt <= 0.0) {
90 AWARN << "dt <= 0, continuous-discrete transformation failed, dt: " << dt;
92 } else {
93 double a1 = alpha_ * tau_;
94 double a0 = 1.00;
95 double b1 = beta_ * tau_;
96 double b0 = beta_;
97 Ts_ = dt;
98 kn1_ = 2 * b1 + Ts_ * b0;
99 kn0_ = Ts_ * b0 - 2 * b1;
100 kd1_ = 2 * a1 + Ts_ * a0;
101 kd0_ = Ts_ * a0 - 2 * a1;
102 if (kd1_ <= 0.0) {
103 AWARN << "kd1 <= 0, continuous-discrete transformation failed, kd1: "
104 << kd1_;
105 transfromc2d_enabled_ = false;
106 } else {
108 }
109 }
110}
111
115
116} // namespace control
117} // namespace apollo
void Reset()
reset variables for lead/leg controller
void SetLeadlag(const LeadlagConf &leadlag_conf)
alpha, beta and tau
void TransformC2d(const double dt)
transfer lead/lag controller coefficients to the discrete-time form, with the bilinear transform (tra...
int InnerstateSaturationStatus() const
get saturation status
void Init(const LeadlagConf &leadlag_conf, const double dt)
initialize lead/lag controller
virtual double Control(const double error, const double dt)
compute control value based on the error
#define AWARN
Definition log.h:43
class register implement
Definition arena_queue.h:37
optional double innerstate_saturation_level