CARLA
Loading...
Searching...
No Matches
agents/navigation/PIDController.h
Go to the documentation of this file.
1// Copyright (c) 2018-2020 CVC.
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "carla/Memory.h"
10
11#include <deque>
12
13namespace carla {
14
15namespace client {
16 class Vehicle;
17 class Waypoint;
18} // namespace client
19
20namespace agents {
21namespace navigation {
22
23 /// Longitudinal PID controller. Mirrors
24 /// `agents.navigation.controller.PIDLongitudinalController`.
26 public:
29 float K_P = 1.0f,
30 float K_I = 0.0f,
31 float K_D = 0.0f,
32 float dt = 0.03f);
33
34 /// Returns the throttle/brake command (clamped to [-1, 1]).
35 float RunStep(float target_speed_kmh, bool debug = false);
36
37 void ChangeParameters(float K_P, float K_I, float K_D, float dt);
38
39 private:
40 float PidControl(float target_speed_kmh, float current_speed_kmh);
41
43 float _k_p;
44 float _k_i;
45 float _k_d;
46 float _dt;
47 std::deque<float> _error_buffer; // mirrors deque(maxlen=10)
48 };
49
50 /// Lateral PID controller. Mirrors
51 /// `agents.navigation.controller.PIDLateralController`.
53 public:
56 float offset = 0.0f,
57 float K_P = 1.0f,
58 float K_I = 0.0f,
59 float K_D = 0.0f,
60 float dt = 0.03f);
61
62 /// Returns a steering command in the range [-1, 1].
64
65 void SetOffset(float offset);
66 void ChangeParameters(float K_P, float K_I, float K_D, float dt);
67
68 private:
70 float _k_p;
71 float _k_i;
72 float _k_d;
73 float _dt;
74 float _offset;
75 std::deque<float> _e_buffer; // mirrors deque(maxlen=10)
76 };
77
78 /// Combined longitudinal + lateral PID controller. Mirrors
79 /// `agents.navigation.controller.VehiclePIDController`.
81 public:
82 struct LateralArgs {
83 float K_P = 1.95f;
84 float K_I = 0.05f;
85 float K_D = 0.20f;
86 float dt = 0.05f;
87 };
88
90 float K_P = 1.50f;
91 float K_I = 0.05f;
92 float K_D = 0.20f;
93 float dt = 0.05f;
94 };
95
98 const LateralArgs &lateral,
99 const LongitudinalArgs &longitudinal,
100 float offset = 0.0f,
101 float max_throttle = 0.75f,
102 float max_brake = 0.30f,
103 float max_steering = 0.80f);
104
105 /// Drives towards @a wp at @a target_speed_kmh and returns the resulting
106 /// VehicleControl. Steering rate is rate-limited the same way as the
107 /// Python original (delta clamped to +-0.1 per step).
109 float target_speed_kmh,
111
112 void ChangeLongitudinalPID(const LongitudinalArgs &args);
113 void ChangeLateralPID(const LateralArgs &args);
114 void SetOffset(float offset);
115
116 private:
124 };
125
126} // namespace navigation
127} // namespace agents
128} // namespace carla
void ChangeParameters(float K_P, float K_I, float K_D, float dt)
float RunStep(SharedPtr< client::Waypoint > waypoint)
Returns a steering command in the range [-1, 1].
float PidControl(float target_speed_kmh, float current_speed_kmh)
void ChangeParameters(float K_P, float K_I, float K_D, float dt)
float RunStep(float target_speed_kmh, bool debug=false)
Returns the throttle/brake command (clamped to [-1, 1]).
Combined longitudinal + lateral PID controller.
void ChangeLongitudinalPID(const LongitudinalArgs &args)
rpc::VehicleControl RunStep(float target_speed_kmh, SharedPtr< client::Waypoint > wp)
Drives towards wp at target_speed_kmh and returns the resulting VehicleControl.
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15