LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
chassisControllerBuilder.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
22
23namespace okapi {
25 public:
32 const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
33
41 ChassisControllerBuilder &withMotors(const Motor &ileft, const Motor &iright);
42
51
59 ChassisControllerBuilder &withMotors(const std::shared_ptr<AbstractMotor> &ileft,
60 const std::shared_ptr<AbstractMotor> &iright);
61
72 const Motor &itopRight,
73 const Motor &ibottomRight,
74 const Motor &ibottomLeft);
75
86 const MotorGroup &itopRight,
87 const MotorGroup &ibottomRight,
88 const MotorGroup &ibottomLeft);
89
99 ChassisControllerBuilder &withMotors(const std::shared_ptr<AbstractMotor> &itopLeft,
100 const std::shared_ptr<AbstractMotor> &itopRight,
101 const std::shared_ptr<AbstractMotor> &ibottomRight,
102 const std::shared_ptr<AbstractMotor> &ibottomLeft);
103
113 withMotors(const Motor &ileft, const Motor &iright, const Motor &imiddle);
114
124 withMotors(const MotorGroup &ileft, const MotorGroup &iright, const MotorGroup &imiddle);
125
135 withMotors(const MotorGroup &ileft, const MotorGroup &iright, const Motor &imiddle);
136
145 ChassisControllerBuilder &withMotors(const std::shared_ptr<AbstractMotor> &ileft,
146 const std::shared_ptr<AbstractMotor> &iright,
147 const std::shared_ptr<AbstractMotor> &imiddle);
148
157
167 withSensors(const ADIEncoder &ileft, const ADIEncoder &iright, const ADIEncoder &imiddle);
168
177
187 const RotationSensor &iright,
188 const RotationSensor &imiddle);
189
198 const IntegratedEncoder &iright);
199
209 const IntegratedEncoder &iright,
210 const ADIEncoder &imiddle);
211
219 ChassisControllerBuilder &withSensors(const std::shared_ptr<ContinuousRotarySensor> &ileft,
220 const std::shared_ptr<ContinuousRotarySensor> &iright);
221
230 ChassisControllerBuilder &withSensors(const std::shared_ptr<ContinuousRotarySensor> &ileft,
231 const std::shared_ptr<ContinuousRotarySensor> &iright,
232 const std::shared_ptr<ContinuousRotarySensor> &imiddle);
233
243 const IterativePosPIDController::Gains &iturnGains);
244
254 const IterativePosPIDController::Gains &iturnGains,
255 const IterativePosPIDController::Gains &iangleGains);
256
267 const QLength &imoveThreshold = 0_mm,
268 const QAngle &iturnThreshold = 0_deg);
269
283 const QLength &imoveThreshold = 0_mm,
284 const QAngle &iturnThreshold = 0_deg);
285
296 ChassisControllerBuilder &withOdometry(std::shared_ptr<Odometry> iodometry,
298 const QLength &imoveThreshold = 0_mm,
299 const QAngle &iturnThreshold = 0_deg);
300
310 std::unique_ptr<Filter> idistanceFilter,
311 std::unique_ptr<Filter> iturnFilter = std::make_unique<PassthroughFilter>(),
312 std::unique_ptr<Filter> iangleFilter = std::make_unique<PassthroughFilter>());
313
322 const ChassisScales &iscales);
323
331
339
350
360
371 double iatTargetDerivative = 5,
372 const QTime &iatTargetTime = 250_ms);
373
382
389 ChassisControllerBuilder &withLogger(const std::shared_ptr<Logger> &ilogger);
390
402
415
422 std::shared_ptr<ChassisController> build();
423
430 std::shared_ptr<OdomChassisController> buildOdometry();
431
432 private:
433 std::shared_ptr<Logger> logger;
434
435 struct SkidSteerMotors {
436 std::shared_ptr<AbstractMotor> left;
437 std::shared_ptr<AbstractMotor> right;
438 };
439
440 struct XDriveMotors {
441 std::shared_ptr<AbstractMotor> topLeft;
442 std::shared_ptr<AbstractMotor> topRight;
443 std::shared_ptr<AbstractMotor> bottomRight;
444 std::shared_ptr<AbstractMotor> bottomLeft;
445 };
446
447 struct HDriveMotors {
448 std::shared_ptr<AbstractMotor> left;
449 std::shared_ptr<AbstractMotor> right;
450 std::shared_ptr<AbstractMotor> middle;
451 };
452
453 enum class DriveMode { SkidSteer, XDrive, HDrive };
454
455 bool hasMotors{false}; // Used to verify motors were passed
456 DriveMode driveMode{DriveMode::SkidSteer};
457 SkidSteerMotors skidSteerMotors;
458 XDriveMotors xDriveMotors;
459 HDriveMotors hDriveMotors;
460
461 bool sensorsSetByUser{false}; // Used so motors don't overwrite sensors set manually
462 std::shared_ptr<ContinuousRotarySensor> leftSensor{nullptr};
463 std::shared_ptr<ContinuousRotarySensor> rightSensor{nullptr};
464 std::shared_ptr<ContinuousRotarySensor> middleSensor{nullptr};
465
466 bool hasGains{false}; // Whether gains were passed, no gains means CCI
467 IterativePosPIDController::Gains distanceGains;
468 std::unique_ptr<Filter> distanceFilter = std::make_unique<PassthroughFilter>();
469 IterativePosPIDController::Gains angleGains;
470 std::unique_ptr<Filter> angleFilter = std::make_unique<PassthroughFilter>();
471 IterativePosPIDController::Gains turnGains;
472 std::unique_ptr<Filter> turnFilter = std::make_unique<PassthroughFilter>();
473 TimeUtilFactory chassisControllerTimeUtilFactory = TimeUtilFactory();
474 TimeUtilFactory closedLoopControllerTimeUtilFactory = TimeUtilFactory();
475 TimeUtilFactory odometryTimeUtilFactory = TimeUtilFactory();
476
477 AbstractMotor::GearsetRatioPair gearset{AbstractMotor::gearset::invalid, 1.0};
478 ChassisScales driveScales{{1, 1}, imev5GreenTPR};
479 bool differentOdomScales{false};
480 ChassisScales odomScales{{1, 1}, imev5GreenTPR};
481 std::shared_ptr<Logger> controllerLogger = Logger::getDefaultLogger();
482
483 bool hasOdom{false}; // Whether odometry was passed
484 std::shared_ptr<Odometry> odometry;
485 StateMode stateMode;
486 QLength moveThreshold;
487 QAngle turnThreshold;
488
489 bool maxVelSetByUser{false}; // Used so motors don't overwrite maxVelocity
490 double maxVelocity{600};
491
492 double maxVoltage{12000};
493
494 bool isParentedToCurrentTask{true};
495
496 std::shared_ptr<ChassisControllerPID> buildCCPID();
497 std::shared_ptr<ChassisControllerIntegrated> buildCCI();
498 std::shared_ptr<DefaultOdomChassisController>
499 buildDOCC(std::shared_ptr<ChassisController> chassisController);
500
501 std::shared_ptr<ChassisModel> makeChassisModel();
502 std::shared_ptr<SkidSteerModel> makeSkidSteerModel();
503 std::shared_ptr<XDriveModel> makeXDriveModel();
504 std::shared_ptr<HDriveModel> makeHDriveModel();
505};
506} // namespace okapi
ChassisControllerBuilder & withSensors(const ADIEncoder &ileft, const ADIEncoder &iright)
Sets the sensors.
ChassisControllerBuilder & withMotors(const Motor &itopLeft, const Motor &itopRight, const Motor &ibottomRight, const Motor &ibottomLeft)
Sets the motors using an x-drive layout.
ChassisControllerBuilder & withSensors(const std::shared_ptr< ContinuousRotarySensor > &ileft, const std::shared_ptr< ContinuousRotarySensor > &iright)
Sets the sensors.
ChassisControllerBuilder & withSensors(const RotationSensor &ileft, const RotationSensor &iright, const RotationSensor &imiddle)
Sets the sensors.
ChassisControllerBuilder & withChassisControllerTimeUtilFactory(const TimeUtilFactory &itimeUtilFactory)
Sets the TimeUtilFactory used when building a ChassisController.
ChassisControllerBuilder & withMotors(const Motor &ileft, const Motor &iright)
Sets the motors using a skid-steer layout.
ChassisControllerBuilder & notParentedToCurrentTask()
Prevents parenting the internal tasks started by this builder to the current task,...
ChassisControllerBuilder & withDimensions(const AbstractMotor::GearsetRatioPair &igearset, const ChassisScales &iscales)
Sets the chassis dimensions.
ChassisControllerBuilder & withMotors(const std::shared_ptr< AbstractMotor > &itopLeft, const std::shared_ptr< AbstractMotor > &itopRight, const std::shared_ptr< AbstractMotor > &ibottomRight, const std::shared_ptr< AbstractMotor > &ibottomLeft)
Sets the motors using an x-drive layout.
ChassisControllerBuilder & withMotors(const std::shared_ptr< AbstractMotor > &ileft, const std::shared_ptr< AbstractMotor > &iright)
Sets the motors using a skid-steer layout.
ChassisControllerBuilder(const std::shared_ptr< Logger > &ilogger=Logger::getDefaultLogger())
A builder that creates ChassisControllers.
ChassisControllerBuilder & withDerivativeFilters(std::unique_ptr< Filter > idistanceFilter, std::unique_ptr< Filter > iturnFilter=std::make_unique< PassthroughFilter >(), std::unique_ptr< Filter > iangleFilter=std::make_unique< PassthroughFilter >())
Sets the derivative filters.
ChassisControllerBuilder & withGains(const IterativePosPIDController::Gains &idistanceGains, const IterativePosPIDController::Gains &iturnGains, const IterativePosPIDController::Gains &iangleGains)
Sets the PID controller gains, causing the builder to generate a ChassisControllerPID.
ChassisControllerBuilder & withSensors(const ADIEncoder &ileft, const ADIEncoder &iright, const ADIEncoder &imiddle)
Sets the sensors.
ChassisControllerBuilder & withClosedLoopControllerTimeUtilFactory(const TimeUtilFactory &itimeUtilFactory)
Sets the TimeUtilFactory used when building a ClosedLoopController.
std::shared_ptr< ChassisController > build()
Builds the ChassisController.
ChassisControllerBuilder & withMotors(const MotorGroup &itopLeft, const MotorGroup &itopRight, const MotorGroup &ibottomRight, const MotorGroup &ibottomLeft)
Sets the motors using an x-drive layout.
ChassisControllerBuilder & withMotors(const MotorGroup &ileft, const MotorGroup &iright, const Motor &imiddle)
Sets the motors using an h-drive layout.
ChassisControllerBuilder & withOdometry(const ChassisScales &iodomScales, const StateMode &imode=StateMode::FRAME_TRANSFORMATION, const QLength &imoveThreshold=0_mm, const QAngle &iturnThreshold=0_deg)
Sets the odometry information, causing the builder to generate an Odometry variant.
ChassisControllerBuilder & withMaxVoltage(double imaxVoltage)
Sets the max voltage.
ChassisControllerBuilder & withClosedLoopControllerTimeUtil(double iatTargetError=50, double iatTargetDerivative=5, const QTime &iatTargetTime=250_ms)
Creates a new ConfigurableTimeUtilFactory with the given parameters.
ChassisControllerBuilder & withSensors(const std::shared_ptr< ContinuousRotarySensor > &ileft, const std::shared_ptr< ContinuousRotarySensor > &iright, const std::shared_ptr< ContinuousRotarySensor > &imiddle)
Sets the sensors.
ChassisControllerBuilder & withMotors(const MotorGroup &ileft, const MotorGroup &iright)
Sets the motors using a skid-steer layout.
ChassisControllerBuilder & withSensors(const IntegratedEncoder &ileft, const IntegratedEncoder &iright, const ADIEncoder &imiddle)
Sets the sensors.
std::shared_ptr< OdomChassisController > buildOdometry()
Builds the OdomChassisController.
ChassisControllerBuilder & withMotors(const std::shared_ptr< AbstractMotor > &ileft, const std::shared_ptr< AbstractMotor > &iright, const std::shared_ptr< AbstractMotor > &imiddle)
Sets the motors using an h-drive layout.
ChassisControllerBuilder & withMotors(const MotorGroup &ileft, const MotorGroup &iright, const MotorGroup &imiddle)
Sets the motors using an h-drive layout.
ChassisControllerBuilder & withMotors(const Motor &ileft, const Motor &iright, const Motor &imiddle)
Sets the motors using an h-drive layout.
ChassisControllerBuilder & withOdometryTimeUtilFactory(const TimeUtilFactory &itimeUtilFactory)
Sets the TimeUtilFactory used when building an Odometry.
ChassisControllerBuilder & withLogger(const std::shared_ptr< Logger > &ilogger)
Sets the logger used for the ChassisController and ClosedLoopControllers.
ChassisControllerBuilder & withGains(const IterativePosPIDController::Gains &idistanceGains, const IterativePosPIDController::Gains &iturnGains)
Sets the PID controller gains, causing the builder to generate a ChassisControllerPID.
ChassisControllerBuilder & withSensors(const RotationSensor &ileft, const RotationSensor &iright)
Sets the sensors.
ChassisControllerBuilder & parentedToCurrentTask()
Parents the internal tasks started by this builder to the current task, meaning they will be deleted ...
ChassisControllerBuilder & withSensors(const IntegratedEncoder &ileft, const IntegratedEncoder &iright)
Sets the sensors.
ChassisControllerBuilder & withOdometry(std::shared_ptr< Odometry > iodometry, const StateMode &imode=StateMode::FRAME_TRANSFORMATION, const QLength &imoveThreshold=0_mm, const QAngle &iturnThreshold=0_deg)
Sets the odometry information, causing the builder to generate an Odometry variant.
ChassisControllerBuilder & withOdometry(const StateMode &imode=StateMode::FRAME_TRANSFORMATION, const QLength &imoveThreshold=0_mm, const QAngle &iturnThreshold=0_deg)
Sets the odometry information, causing the builder to generate an Odometry variant.
ChassisControllerBuilder & withMaxVelocity(double imaxVelocity)
Sets the max velocity.
static std::shared_ptr< Logger > getDefaultLogger()
static constexpr std::int32_t imev5GreenTPR
The ticks per rotation of the V5 motor with a green gearset.
Definition mathUtil.hpp:63
StateMode
The mode for the OdomState calculated by Odometry.
Definition stateMode.hpp:12
@ FRAME_TRANSFORMATION
+x is forward, +y is right, 0 degrees is along +x
A simple structure representing the full ratio between motor and wheel.