bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
pid_controller.h
Go to the documentation of this file.
1#ifndef BITSIM_CONTROL_PID_CONTROLLER_H
2#define BITSIM_CONTROL_PID_CONTROLLER_H
3
5
6#include <stdexcept>
7#include <utility>
8
9namespace bitsim
10{
11namespace control
12{
24{
25 public:
27
34
35 real_t get_kp() const noexcept { return kp_; }
36 real_t get_ki() const noexcept { return ki_; }
37 real_t get_kd() const noexcept { return kd_; }
38
41 bool is_limited() const noexcept { return is_limited_; }
42
46 void set_control_limits(std::pair<real_t, real_t> limits);
47
55
59 void reset() noexcept
60 {
61 integral_ = 0.0;
62 has_err_old_ = false;
63 }
64
65 real_t integral() const noexcept { return integral_; }
66
67 private:
68 bool is_limited_{false};
69 real_t kp_;
70 real_t ki_;
71 real_t kd_;
72
73 real_t integral_{0.0};
74 real_t err_old_{0.0};
75 bool has_err_old_{false};
76 // min = limits.first, max = limits.second
77 std::pair<real_t, real_t> limits_;
78};
79
80inline PIDController::PIDController(real_t kp, real_t ki, real_t kd) : kp_(kp), ki_(ki), kd_(kd) {}
81
82inline void PIDController::set_control_limits(std::pair<real_t, real_t> limits)
83{
84 if (!(limits.first < limits.second))
85 {
86 throw std::invalid_argument("PIDController: the lower limit must be below the upper one");
87 }
88 is_limited_ = true;
89 limits_ = limits;
90}
91} // namespace control
92
93} // namespace bitsim
94
95#endif // BITSIM_CONTROL_PID_CONTROLLER_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
bool is_limited() const noexcept
Definition pid_controller.h:41
real_t get_kp() const noexcept
Definition pid_controller.h:35
real_t get_kd() const noexcept
Definition pid_controller.h:37
real_t ctrl_signal_type
Definition pid_controller.h:26
PIDController(real_t Kp, real_t Ki, real_t Kd)
Definition pid_controller.h:80
void reset() noexcept
Forget the integral and the last error.
Definition pid_controller.h:59
ctrl_signal_type compute_ctrl_signal(real_t current, real_t target, real_t dt)
Definition pid_controller.cpp:11
real_t integral() const noexcept
Definition pid_controller.h:65
void set_control_limits(std::pair< real_t, real_t > limits)
Limit the output to [limits.first, limits.second].
Definition pid_controller.h:82
real_t get_ki() const noexcept
Definition pid_controller.h:36
Controllers: PID controllers, line following, a quadrotor flight controller, a fixed wing autopilot,...
Definition control_module.h:18
Definition dc_motor_backend_base.h:9
double real_t
real_t
Definition bitsim_types.h:20