Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
smooth_pid.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_SMOOTH_PID_HPP_
25#define TAPROOT_SMOOTH_PID_HPP_
26
27#include <cstdint>
28
30
31namespace tap
32{
33namespace algorithms
34{
36{
37 float kp = 0.0f;
38 float ki = 0.0f;
39 float kd = 0.0f;
40 float maxICumulative = 0.0f;
41 float maxOutput = 0.0f;
42 float tQDerivativeKalman = 1.0f;
44 float tRDerivativeKalman = 0.0f;
46 float tQProportionalKalman = 1.0f;
48 float tRProportionalKalman = 0.0f;
50 float errDeadzone = 0.0f;
52 float errorDerivativeFloor = 0.0f;
54};
55
57{
58public:
59 SmoothPid(const SmoothPidConfig &pidConfig);
60
70 virtual float runController(float error, float errorDerivative, float dt);
71
72 float runControllerDerivateError(float error, float dt);
73
74 float getOutput();
75
76 void reset();
77
78 inline void setP(float p) { config.kp = p; }
79 inline void setI(float i) { config.ki = i; }
80 inline void setD(float d) { config.kd = d; }
81 inline void setMaxICumulative(float maxICumulative) { config.maxICumulative = maxICumulative; }
82 inline void setMaxOutput(float maxOutput) { config.maxOutput = maxOutput; }
83 inline void setErrDeadzone(float errDeadzone) { config.errDeadzone = errDeadzone; }
84
85private:
86 // gains and constants, to be set by the user
88
89 // while these could be local, debugging pid is much easier if they are not
90 float currErrorP = 0.0f;
91 float currErrorI = 0.0f;
92 float currErrorD = 0.0f;
93 float output = 0.0f;
94 float prevError = 0.0f;
95
96 tap::algorithms::ExtendedKalman proportionalKalman;
97 tap::algorithms::ExtendedKalman derivativeKalman;
98};
99
100} // namespace algorithms
101
102} // namespace tap
103
104#endif // TAPROOT_SMOOTH_PID_HPP_
Definition extended_kalman.hpp:53
Definition smooth_pid.hpp:57
void setErrDeadzone(float errDeadzone)
Definition smooth_pid.hpp:83
float getOutput()
Definition smooth_pid.cpp:80
void setP(float p)
Definition smooth_pid.hpp:78
virtual float runController(float error, float errorDerivative, float dt)
Definition smooth_pid.cpp:41
void setD(float d)
Definition smooth_pid.hpp:80
float runControllerDerivateError(float error, float dt)
Definition smooth_pid.cpp:69
void reset()
Definition smooth_pid.cpp:82
void setI(float i)
Definition smooth_pid.hpp:79
void setMaxICumulative(float maxICumulative)
Definition smooth_pid.hpp:81
void setMaxOutput(float maxOutput)
Definition smooth_pid.hpp:82
DUnit d
Definition dimensional_smooth_pid.hpp:3
IUnit i
Definition dimensional_smooth_pid.hpp:2
ControlUnit maxOutput
Definition dimensional_smooth_pid.hpp:5
PUnit p
Definition dimensional_smooth_pid.hpp:1
Definition pwm_info.hpp:4
Definition ballistics.cpp:29
Definition smooth_pid.hpp:36
float errDeadzone
Definition smooth_pid.hpp:50
float errorDerivativeFloor
Definition smooth_pid.hpp:52
float maxICumulative
Definition smooth_pid.hpp:40
float tRProportionalKalman
Definition smooth_pid.hpp:48
float tQProportionalKalman
Definition smooth_pid.hpp:46
float maxOutput
Definition smooth_pid.hpp:41
float kd
Definition smooth_pid.hpp:39
float tQDerivativeKalman
Definition smooth_pid.hpp:42
float ki
Definition smooth_pid.hpp:38
float kp
Definition smooth_pid.hpp:37
float tRDerivativeKalman
Definition smooth_pid.hpp:44