CARLA
 
载入中...
搜索中...
未找到
AckermannController.h
浏览该文件的文档.
1// Copyright (c) 2022 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
12
13// Forward declaration
15
16class PID
17{
18 public:
19 PID() = default;
20 PID(float Kp, float Ki, float Kd): Kp(Kp), Ki(Ki), Kd(Kd) {}
21 ~PID() = default;
22
23 void SetTargetPoint(float Point)
24 {
25 SetPoint = Point;
26 }
27
28 float Run(float Input, float DeltaTime)
29 {
30 float Error = SetPoint - Input;
31
32 Proportional = Kp * Error;
33 Integral += Ki * Error * DeltaTime;
34 // Avoid integral windup
35 Integral = FMath::Clamp(Integral, MinOutput, MaxOutput);
36 Derivative = (-Kd * (Input - LastInput)) / DeltaTime;
37
38 float Out = Proportional + Integral + Derivative;
39 Out = FMath::Clamp(Out, MinOutput, MaxOutput);
40
41 // Keep track of the state
42 LastError = Out;
43 LastInput = Input;
44
45 return Out;
46 }
47
48 void Reset()
49 {
50 Proportional = 0.0f;
51 Integral = 0.0f;
52 Integral = FMath::Clamp(Integral, MinOutput, MaxOutput);
53 Derivative = 0.0f;
54
55 LastError = 0.0f;
56 LastInput = 0.0f;
57 }
58
59 public:
60 float Kp = 0.0f;
61 float Ki = 0.0f;
62 float Kd = 0.0f;
63
64 private:
65 float SetPoint;
66
67 // Out Limits
68 float MinOutput = -1.0f;
69 float MaxOutput = 1.0f;
70
71 // Internal state.
72 float Proportional = 0.0f;
73 float Integral = 0.0f;
74 float Derivative = 0.0f;
75
76 float LastError = 0.0f;
77 float LastInput = 0.0f;
78};
79
80
82{
83public:
84
87
88public:
89
91 void ApplySettings(const FAckermannControllerSettings& Settings);
92
95
96 void SetTargetPoint(const FVehicleAckermannControl& AckermannControl);
97 void Reset();
98
99 void RunLoop(FVehicleControl& Control);
100
101private:
102
103 // Lateral Control
104 void RunControlSteering();
105
106 // Longitudinal Control
107 bool RunControlFullStop();
108 void RunControlReverse();
109 void RunControlSpeed();
112
113private:
114
115 PID SpeedController = PID(0.15f, 0.0f, 0.25f);
116 PID AccelerationController = PID(0.01f, 0.0f, 0.01f);
117
119
120 // Target point after aplying restrictions
121 float TargetSteer = 0.0;
122 float TargetSteerSpeed = 0.0;
123 float TargetSpeed = 0.0;
125 float TargetJerk = 0.0;
126
127 // Restricitions parameters
128 float MaxAccel = 3.0f; // [m/s2]
129 float MaxDecel = 8.0f; // [m/s2]
130
131 // Control parameters
132 float Steer = 0.0f;
133 float Throttle = 0.0f;
134 float Brake = 0.0f;
135 bool bReverse = false;
136
137 // Internal control parameters
140
143
144 // Simulation state
145 float DeltaTime = 0.0f; // [s]
146
147 // Vehicle state
148 float VehicleMaxSteering = 0.0f; // [rad]
149
150 float VehicleSteer = 0.0f; // [rad]
151 float VehicleSpeed = 0.0f; // [m/s]
152 float VehicleAcceleration = 0.0f; // [m/s2]
153
154 float LastVehicleSpeed = 0.0f; // [m/s]
155 float LastVehicleAcceleration = 0.0f; // [m/s2]
156};
Base class for CARLA wheeled vehicles.
FAckermannController()=default
FVehicleAckermannControl UserTargetPoint
void UpdateVehicleState(const ACarlaWheeledVehicle *Vehicle)
void ApplySettings(const FAckermannControllerSettings &Settings)
void RunLoop(FVehicleControl &Control)
void SetTargetPoint(const FVehicleAckermannControl &AckermannControl)
void UpdateVehiclePhysics(const ACarlaWheeledVehicle *Vehicle)
FAckermannControllerSettings GetSettings() const
PID()=default
float SetPoint
PID(float Kp, float Ki, float Kd)
float Integral
float MinOutput
float MaxOutput
float Proportional
float Derivative
void Reset()
float LastInput
void SetTargetPoint(float Point)
~PID()=default
float LastError
float Run(float Input, float DeltaTime)