LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
chassisControllerPid.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
13#include <atomic>
14#include <memory>
15#include <tuple>
16
17namespace okapi {
19 public:
35 TimeUtil itimeUtil,
36 std::shared_ptr<ChassisModel> imodel,
37 std::unique_ptr<IterativePosPIDController> idistanceController,
38 std::unique_ptr<IterativePosPIDController> iturnController,
39 std::unique_ptr<IterativePosPIDController> iangleController,
41 const ChassisScales &iscales = ChassisScales({1, 1}, imev5GreenTPR),
42 std::shared_ptr<Logger> ilogger = Logger::getDefaultLogger());
43
48
50
64 void moveDistance(QLength itarget) override;
65
76 void moveRaw(double itarget) override;
77
83 void moveDistanceAsync(QLength itarget) override;
84
90 void moveRawAsync(double itarget) override;
91
102 void turnAngle(QAngle idegTarget) override;
103
114 void turnRaw(double idegTarget) override;
115
121 void turnAngleAsync(QAngle idegTarget) override;
122
128 void turnRawAsync(double idegTarget) override;
129
135 void setTurnsMirrored(bool ishouldMirror) override;
136
142 bool isSettled() override;
143
147 void waitUntilSettled() override;
148
153
158
167 void setVelocityMode(bool ivelocityMode);
168
176 void setGains(const IterativePosPIDController::Gains &idistanceGains,
177 const IterativePosPIDController::Gains &iturnGains,
178 const IterativePosPIDController::Gains &iangleGains);
179
188 getGains() const;
189
195
202
206 void stop() override;
207
214 void setMaxVelocity(double imaxVelocity) override;
215
219 double getMaxVelocity() const override;
220
224 std::shared_ptr<ChassisModel> getModel() override;
225
229 ChassisModel &model() override;
230
231 protected:
232 std::shared_ptr<Logger> logger;
233 bool normalTurns{true};
234 std::shared_ptr<ChassisModel> chassisModel;
236 std::unique_ptr<IterativePosPIDController> distancePid;
237 std::unique_ptr<IterativePosPIDController> turnPid;
238 std::unique_ptr<IterativePosPIDController> anglePid;
241 bool velocityMode{true};
242 std::atomic_bool doneLooping{true};
243 std::atomic_bool doneLoopingSeen{true};
244 std::atomic_bool newMovement{false};
245 std::atomic_bool dtorCalled{false};
246 QTime threadSleepTime{10_ms};
247
248 static void trampoline(void *context);
249 void loop();
250
257
264
269
270 typedef enum { distance, angle, none } modeType;
272
274};
275} // namespace okapi
@ green
18:1, 200 RPM, Green gear set
void turnRawAsync(double idegTarget) override
Sets the target angle for the robot to turn clockwise in place (using closed-loop control).
void setGains(const IterativePosPIDController::Gains &idistanceGains, const IterativePosPIDController::Gains &iturnGains, const IterativePosPIDController::Gains &iangleGains)
Sets the gains for all controllers.
std::unique_ptr< IterativePosPIDController > distancePid
std::shared_ptr< Logger > logger
void setTurnsMirrored(bool ishouldMirror) override
Sets whether turns should be mirrored.
CrossplatformThread * getThread() const
Returns the underlying thread handle.
ChassisModel & model() override
std::unique_ptr< IterativePosPIDController > anglePid
void setVelocityMode(bool ivelocityMode)
Sets the velocity mode flag.
ChassisControllerPID(const ChassisControllerPID &)=delete
double getMaxVelocity() const override
ChassisControllerPID & operator=(ChassisControllerPID &&other)=delete
void turnAngleAsync(QAngle idegTarget) override
Sets the target angle for the robot to turn clockwise in place (using closed-loop control).
std::shared_ptr< ChassisModel > chassisModel
void setMaxVelocity(double imaxVelocity) override
Sets a new maximum velocity in RPM [0-600].
AbstractMotor::GearsetRatioPair getGearsetRatioPair() const override
Gets the GearsetRatioPair.
bool isSettled() override
Checks whether the internal controllers are currently settled.
void turnAngle(QAngle idegTarget) override
Turns the robot clockwise in place (using closed-loop control).
bool waitForAngleSettled()
Wait for the angle setup (anglePid) to settle.
ChassisScales getChassisScales() const override
Gets the ChassisScales.
std::unique_ptr< IterativePosPIDController > turnPid
void stop() override
Interrupts the current movement to stop the robot.
void waitUntilSettled() override
Delays until the currently executing movement completes.
bool waitForDistanceSettled()
Wait for the distance setup (distancePid and anglePid) to settle.
AbstractMotor::GearsetRatioPair gearsetRatioPair
void startThread()
Starts the internal thread.
ChassisControllerPID(TimeUtil itimeUtil, std::shared_ptr< ChassisModel > imodel, std::unique_ptr< IterativePosPIDController > idistanceController, std::unique_ptr< IterativePosPIDController > iturnController, std::unique_ptr< IterativePosPIDController > iangleController, const AbstractMotor::GearsetRatioPair &igearset=AbstractMotor::gearset::green, const ChassisScales &iscales=ChassisScales({1, 1}, imev5GreenTPR), std::shared_ptr< Logger > ilogger=Logger::getDefaultLogger())
ChassisController using PID control.
void moveDistance(QLength itarget) override
Drives the robot straight for a distance (using closed-loop control).
static void trampoline(void *context)
void stopAfterSettled()
Stops all the controllers and the ChassisModel.
void moveRaw(double itarget) override
Drives the robot straight for a distance (using closed-loop control).
std::shared_ptr< ChassisModel > getModel() override
std::tuple< IterativePosPIDController::Gains, IterativePosPIDController::Gains, IterativePosPIDController::Gains > getGains() const
Gets the current controller gains.
void moveRawAsync(double itarget) override
Sets the target distance for the robot to drive straight (using closed-loop control).
ChassisControllerPID(ChassisControllerPID &&other)=delete
void turnRaw(double idegTarget) override
Turns the robot clockwise in place (using closed-loop control).
ChassisControllerPID & operator=(const ChassisControllerPID &other)=delete
void moveDistanceAsync(QLength itarget) override
Sets the target distance for the robot to drive straight (using closed-loop control).
A version of the ReadOnlyChassisModel that also supports write methods, such as setting motor speed.
static std::shared_ptr< Logger > getDefaultLogger()
Utility class for holding an AbstractTimer, AbstractRate, and SettledUtil together in one class since...
Definition timeUtil.hpp:18
static constexpr std::int32_t imev5GreenTPR
The ticks per rotation of the V5 motor with a green gearset.
Definition mathUtil.hpp:63
A simple structure representing the full ratio between motor and wheel.