LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
pidTuner.hpp
Go to the documentation of this file.
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 */
6#pragma once
7
14#include <memory>
15#include <vector>
16
17namespace okapi {
18class PIDTuner {
19 public:
20 struct Output {
21 double kP, kI, kD;
22 };
23
24 PIDTuner(const std::shared_ptr<ControllerInput<double>> &iinput,
25 const std::shared_ptr<ControllerOutput<double>> &ioutput,
26 const TimeUtil &itimeUtil,
27 QTime itimeout,
28 std::int32_t igoal,
29 double ikPMin,
30 double ikPMax,
31 double ikIMin,
32 double ikIMax,
33 double ikDMin,
34 double ikDMax,
35 std::size_t inumIterations = 5,
36 std::size_t inumParticles = 16,
37 double ikSettle = 1,
38 double ikITAE = 2,
39 const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
40
41 virtual ~PIDTuner();
42
43 virtual Output autotune();
44
45 protected:
46 static constexpr double inertia = 0.5; // Particle inertia
47 static constexpr double confSelf = 1.1; // Self confidence
48 static constexpr double confSwarm = 1.2; // Particle swarm confidence
49 static constexpr int increment = 5;
50 static constexpr int divisor = 5;
51 static constexpr QTime loopDelta = 10_ms; // NOLINT
52
53 struct Particle {
54 double pos, vel, best;
55 };
56
57 struct ParticleSet {
59 double bestError;
60 };
61
62 std::shared_ptr<Logger> logger;
64 std::shared_ptr<ControllerInput<double>> input;
65 std::shared_ptr<ControllerOutput<double>> output;
66
67 const QTime timeout;
68 const std::int32_t goal;
69 const double kPMin;
70 const double kPMax;
71 const double kIMin;
72 const double kIMax;
73 const double kDMin;
74 const double kDMax;
75 const std::size_t numIterations;
76 const std::size_t numParticles;
77 const double kSettle;
78 const double kITAE;
79};
80} // namespace okapi
static std::shared_ptr< Logger > getDefaultLogger()
static constexpr int increment
Definition pidTuner.hpp:49
const double kPMax
Definition pidTuner.hpp:70
std::shared_ptr< ControllerInput< double > > input
Definition pidTuner.hpp:64
static constexpr int divisor
Definition pidTuner.hpp:50
TimeUtil timeUtil
Definition pidTuner.hpp:63
static constexpr double confSwarm
Definition pidTuner.hpp:48
const double kSettle
Definition pidTuner.hpp:77
const double kDMax
Definition pidTuner.hpp:74
static constexpr double confSelf
Definition pidTuner.hpp:47
const double kIMax
Definition pidTuner.hpp:72
const double kPMin
Definition pidTuner.hpp:69
std::shared_ptr< Logger > logger
Definition pidTuner.hpp:62
const QTime timeout
Definition pidTuner.hpp:67
const double kITAE
Definition pidTuner.hpp:78
const double kIMin
Definition pidTuner.hpp:71
const double kDMin
Definition pidTuner.hpp:73
const std::int32_t goal
Definition pidTuner.hpp:68
virtual ~PIDTuner()
virtual Output autotune()
const std::size_t numIterations
Definition pidTuner.hpp:75
const std::size_t numParticles
Definition pidTuner.hpp:76
std::shared_ptr< ControllerOutput< double > > output
Definition pidTuner.hpp:65
static constexpr QTime loopDelta
Definition pidTuner.hpp:51
PIDTuner(const std::shared_ptr< ControllerInput< double > > &iinput, const std::shared_ptr< ControllerOutput< double > > &ioutput, const TimeUtil &itimeUtil, QTime itimeout, std::int32_t igoal, double ikPMin, double ikPMax, double ikIMin, double ikIMax, double ikDMin, double ikDMax, std::size_t inumIterations=5, std::size_t inumParticles=16, double ikSettle=1, double ikITAE=2, const std::shared_ptr< Logger > &ilogger=Logger::getDefaultLogger())
static constexpr double inertia
Definition pidTuner.hpp:46
Utility class for holding an AbstractTimer, AbstractRate, and SettledUtil together in one class since...
Definition timeUtil.hpp:18