LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
asyncVelControllerBuilder.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
17
18namespace okapi {
20 public:
28 const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
29
37
45
52 AsyncVelControllerBuilder &withMotor(const std::shared_ptr<AbstractMotor> &imotor);
53
61
69
76 AsyncVelControllerBuilder &withSensor(const std::shared_ptr<RotarySensor> &isensor);
77
86
94 AsyncVelControllerBuilder &withVelMath(std::unique_ptr<VelMath> ivelMath);
95
104 AsyncVelControllerBuilder &withDerivativeFilter(std::unique_ptr<Filter> iderivativeFilter);
105
113
122
131
138 AsyncVelControllerBuilder &withLogger(const std::shared_ptr<Logger> &ilogger);
139
151
164
170 std::shared_ptr<AsyncVelocityController<double, double>> build();
171
172 private:
173 std::shared_ptr<Logger> logger;
174
175 bool hasMotors{false}; // Used to verify motors were passed
176 std::shared_ptr<AbstractMotor> motor;
177
178 bool sensorsSetByUser{false}; // Used so motors don't overwrite sensors set manually
179 std::shared_ptr<RotarySensor> sensor;
180
181 bool hasGains{false}; // Whether gains were passed, no gains means integrated control
182 IterativeVelPIDController::Gains gains;
183
184 bool hasVelMath{false}; // Used to verify velMath was passed
185 std::unique_ptr<VelMath> velMath;
186
187 std::unique_ptr<Filter> derivativeFilter = std::make_unique<PassthroughFilter>();
188
189 bool gearsetSetByUser{false}; // Used so motor's don't overwrite a gearset set manually
190 AbstractMotor::GearsetRatioPair pair{AbstractMotor::gearset::invalid};
191
192 bool maxVelSetByUser{false}; // Used so motors don't overwrite maxVelocity
193 double maxVelocity{600};
194
195 TimeUtilFactory timeUtilFactory = TimeUtilFactory();
196 std::shared_ptr<Logger> controllerLogger = Logger::getDefaultLogger();
197
198 bool isParentedToCurrentTask{true};
199
200 std::shared_ptr<AsyncVelIntegratedController> buildAVIC();
201 std::shared_ptr<AsyncVelPIDController> buildAVPC();
202};
203} // namespace okapi
AsyncVelControllerBuilder & withGearset(const AbstractMotor::GearsetRatioPair &igearset)
Sets the gearset.
AsyncVelControllerBuilder(const std::shared_ptr< Logger > &ilogger=Logger::getDefaultLogger())
A builder that creates async velocity controllers.
std::shared_ptr< AsyncVelocityController< double, double > > build()
Builds the AsyncVelocityController.
AsyncVelControllerBuilder & withLogger(const std::shared_ptr< Logger > &ilogger)
Sets the logger.
AsyncVelControllerBuilder & withSensor(const IntegratedEncoder &isensor)
Sets the sensor.
AsyncVelControllerBuilder & notParentedToCurrentTask()
Prevents parenting the internal tasks started by this builder to the current task,...
AsyncVelControllerBuilder & withTimeUtilFactory(const TimeUtilFactory &itimeUtilFactory)
Sets the TimeUtilFactory used when building the controller.
AsyncVelControllerBuilder & withSensor(const std::shared_ptr< RotarySensor > &isensor)
Sets the sensor.
AsyncVelControllerBuilder & withSensor(const ADIEncoder &isensor)
Sets the sensor.
AsyncVelControllerBuilder & withMotor(const Motor &imotor)
Sets the motor.
AsyncVelControllerBuilder & withMaxVelocity(double imaxVelocity)
Sets the maximum velocity.
AsyncVelControllerBuilder & withMotor(const MotorGroup &imotor)
Sets the motor.
AsyncVelControllerBuilder & withVelMath(std::unique_ptr< VelMath > ivelMath)
Sets the VelMath which calculates and filters velocity.
AsyncVelControllerBuilder & withMotor(const std::shared_ptr< AbstractMotor > &imotor)
Sets the motor.
AsyncVelControllerBuilder & withDerivativeFilter(std::unique_ptr< Filter > iderivativeFilter)
Sets the derivative filter which filters the derivative term before it is scaled by kD.
AsyncVelControllerBuilder & withGains(const IterativeVelPIDController::Gains &igains)
Sets the controller gains, causing the builder to generate an AsyncVelPIDController.
AsyncVelControllerBuilder & parentedToCurrentTask()
Parents the internal tasks started by this builder to the current task, meaning they will be deleted ...
static std::shared_ptr< Logger > getDefaultLogger()
A simple structure representing the full ratio between motor and wheel.