YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
SmartMotorControllerConfig.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Yet Another Software Suite
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
6#include <any>
7#include <memory>
8#include <optional>
9#include <set>
10#include <string>
11#include <string_view>
12#include <utility>
13#include <vector>
14#include <wpi/commands2/SubsystemBase.hpp>
15#include <wpi/math/controller/ArmFeedforward.hpp>
16#include <wpi/math/controller/ElevatorFeedforward.hpp>
17#include <wpi/math/controller/SimpleMotorFeedforward.hpp>
18#include <wpi/math/system/DCMotor.hpp>
19#include <wpi/math/trajectory/ExponentialProfile.hpp>
20#include <wpi/math/trajectory/TrapezoidProfile.hpp>
21#include <wpi/units/acceleration.hpp>
22#include <wpi/units/angle.hpp>
23#include <wpi/units/angular_acceleration.hpp>
24#include <wpi/units/angular_jerk.hpp>
25#include <wpi/units/angular_velocity.hpp>
26#include <wpi/units/current.hpp>
27#include <wpi/units/force.hpp>
28#include <wpi/units/length.hpp>
29#include <wpi/units/mass.hpp>
30#include <wpi/units/moment_of_inertia.hpp>
31#include <wpi/units/temperature.hpp>
32#include <wpi/units/time.hpp>
33#include <wpi/units/velocity.hpp>
34#include <wpi/units/voltage.hpp>
35
38
39namespace yams::motorcontrollers {
40
41// Forward declaration to avoid circular dependency (SmartMotorController.hpp
42// includes this header, so we cannot include it here).
43class SmartMotorController;
44
45} // namespace yams::motorcontrollers
46
47namespace yams::telemetry {
48// Forward declaration; SmartMotorControllerTelemetryConfig.hpp includes this header.
49class SmartMotorControllerTelemetryConfig;
50} // namespace yams::telemetry
51
52namespace yams::motorcontrollers {
53
55using meters_per_second_cubed_t = wpi::units::unit_t<wpi::units::compound_unit<
56 wpi::units::meters, wpi::units::inverse<wpi::units::cubed<wpi::units::seconds>>>>;
57
66 public:
70 enum class MotorMode { COAST, BRAKE };
75
76 // ---- Feedback -------------------------------------------------------
77
88 double kP, double kI, double kD,
90
91 // ---- Feedforward -------------------------------------------------------
92
101 const wpi::math::ArmFeedforward& ff,
103
112 const wpi::math::ElevatorFeedforward& ff,
114
123 const wpi::math::SimpleMotorFeedforward<wpi::units::turns>& ff,
125
126 // ---- Motion profiles ---------------------------------------------------
127
136 wpi::units::turns_per_second_t maxVelocity,
137 wpi::units::turns_per_second_squared_t maxAcceleration);
138
147 wpi::units::meters_per_second_t maxVelocity,
148 wpi::units::meters_per_second_squared_t maxAcceleration);
149
161 wpi::units::turns_per_second_squared_t maxAcceleration,
162 wpi::units::angular_jerk::turns_per_second_cubed_t maxJerk);
163
174 wpi::units::meters_per_second_squared_t maxAcceleration, meters_per_second_cubed_t maxJerk);
175
185 wpi::units::volt_t maxInput);
186
200 wpi::math::DCMotor motor,
201 wpi::units::kilogram_square_meter_t moi);
202
217 wpi::math::DCMotor motor,
218 wpi::units::kilogram_t mass,
219 wpi::units::meter_t drumRadius);
220
230 wpi::units::volt_t maxVolts, wpi::units::turns_per_second_t maxVelocity,
231 wpi::units::turns_per_second_squared_t maxAcceleration);
232
240 wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>::Constraints constraints);
241
254 wpi::units::volt_t maxInput);
255
256 // ---- LQR ---------------------------------------------------------------
257
266 const math::LQRConfig& lqrConfig,
268
280
290
301
302 // ---- Gearing / linear --------------------------------------------------
303
311
319
329
336 SmartMotorControllerConfig& WithMechanismCircumference(wpi::units::meter_t circumference);
337
347 SmartMotorControllerConfig& WithMechanismCircumference(wpi::units::meter_t gearPitch, int teeth);
348
357 SmartMotorControllerConfig& WithMechanismDiameter(wpi::units::meter_t diameter);
358
368
369 // ---- Limits ------------------------------------------------------------
370
381 wpi::units::turn_t upper);
382
396 wpi::units::meter_t upper);
397
405
413
420 SmartMotorControllerConfig& WithTemperatureCutoff(wpi::units::celsius_t temperature);
421
429
437
449
450 // ---- Control behaviour -------------------------------------------------
451
459
466
473
481
490
491 // ---- Ramp rates --------------------------------------------------------
492
499 SmartMotorControllerConfig& WithOpenLoopRampRate(wpi::units::second_t rampRate);
500
507 SmartMotorControllerConfig& WithClosedLoopRampRate(wpi::units::second_t rampRate);
508
509 // ---- Inversion ---------------------------------------------------------
510
518
526
527 // ---- External encoder --------------------------------------------------
528
549
558
566
577
585
596
607
615
626 wpi::units::turn_t discontinuityPoint);
627
639 wpi::units::turn_t max);
640
641 // ---- Telemetry ----------------------------------------------------------
642
651 const std::string& name, TelemetryVerbosity verbosity = TelemetryVerbosity::HIGH);
652
660
673 const std::string& name, telemetry::SmartMotorControllerTelemetryConfig telemetryConfig);
674
675 // ---- Subsystem ---------------------------------------------------------
676
686 SmartMotorControllerConfig& WithSubsystem(wpi::cmd::SubsystemBase* subsystem);
687
688 // ---- Simulation --------------------------------------------------------
689
696 SmartMotorControllerConfig& WithSimMotor(wpi::math::DCMotor motor);
697
707
708 // ---- Simulation overrides -----------------------------------------------
709
719 SmartMotorControllerConfig& WithSimStartingPosition(wpi::units::degree_t startingAngle);
720
729 SmartMotorControllerConfig& WithSimStartingPosition(wpi::units::meter_t startingDistance);
730
739 const wpi::math::ArmFeedforward& ff,
741
750 const wpi::math::ElevatorFeedforward& ff,
752
761 const wpi::math::SimpleMotorFeedforward<wpi::units::turns>& ff,
763
774 double kP, double kI, double kD,
776
787 const math::LQRConfig& lqrConfig,
789
798 wpi::units::turns_per_second_t maxVelocity,
799 wpi::units::turns_per_second_squared_t maxAcceleration);
800
809 wpi::units::meters_per_second_t maxVelocity,
810 wpi::units::meters_per_second_squared_t maxAcceleration);
811
819 wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>::Constraints constraints);
820
827 SmartMotorControllerConfig& WithMOI(wpi::units::kilogram_square_meter_t moi);
828
838 SmartMotorControllerConfig& WithMOI(wpi::units::meter_t length, wpi::units::kilogram_t mass);
839
848 SmartMotorControllerConfig& WithStartingPosition(wpi::units::degree_t startingAngle);
849
861 SmartMotorControllerConfig& WithStartingPosition(wpi::units::meter_t startingDistance);
862
881
882 // ---- Followers -------------------------------------------------------------
883
896 SmartMotorControllerConfig& WithFollowers(std::vector<std::pair<std::any, bool>> followers);
897
909 std::vector<SmartMotorController*> followers);
910
913
915 const std::vector<std::pair<std::any, bool>>& GetFollowers() const;
916
918 const std::vector<SmartMotorController*>& GetLooselyCoupledFollowers() const;
919
920 // ---- Clone -----------------------------------------------------------------
921
931
932 // ---- Validation ------------------------------------------------------------
933
940
948
955
967
968 // === Getters ============================================================
969
971 struct PIDGains {
972 double kP{0.0}, kI{0.0}, kD{0.0};
973 double kS{0.0}, kV{0.0}, kA{0.0}, kG{0.0};
974 std::optional<wpi::math::ArmFeedforward> armFF;
975 std::optional<wpi::math::ElevatorFeedforward> elevatorFF;
976 std::optional<wpi::math::SimpleMotorFeedforward<wpi::units::turns>> simpleFF;
977 std::optional<math::LQRConfig> lqr;
978 };
979
990
997 std::optional<wpi::math::ArmFeedforward> GetArmFeedforward(ClosedLoopControllerSlot slot) const;
998
1005 std::optional<wpi::math::ElevatorFeedforward> GetElevatorFeedforward(
1006 ClosedLoopControllerSlot slot) const;
1007
1014 std::optional<wpi::math::SimpleMotorFeedforward<wpi::units::turns>> GetSimpleFeedforward(
1015 ClosedLoopControllerSlot slot) const;
1016
1023 std::optional<math::LQRConfig> GetLQR(ClosedLoopControllerSlot slot) const;
1024
1032
1040
1048
1055
1057 std::optional<wpi::units::turn_t> GetMechanismLowerLimit() const;
1059 std::optional<wpi::units::turn_t> GetMechanismUpperLimit() const;
1061 std::optional<wpi::units::meter_t> GetMeasurementLowerLimit() const;
1063 std::optional<wpi::units::meter_t> GetMeasurementUpperLimit() const;
1064
1067 std::optional<wpi::units::turn_t> GetContinuousWrapping() const;
1069 std::optional<wpi::units::turn_t> GetContinuousWrappingMin() const;
1070
1080 wpi::units::turn_t GetContinuousWrappingSetpoint(wpi::units::turn_t setpoint,
1081 wpi::units::turn_t current) const;
1082
1084 std::optional<wpi::units::ampere_t> GetStatorCurrentLimit() const;
1086 std::optional<int> GetStatorStallCurrentLimit() const;
1088 std::optional<int> GetSupplyStallCurrentLimit() const;
1090 std::optional<wpi::units::ampere_t> GetSupplyCurrentLimit() const;
1092 std::optional<wpi::units::celsius_t> GetTemperatureCutoff() const;
1094 std::optional<wpi::units::volt_t> GetClosedLoopControllerMaximumVoltage() const;
1096 std::optional<wpi::units::volt_t> GetVoltageCompensation() const;
1098 std::optional<wpi::units::turn_t> GetFeedbackSynchronizationThreshold() const;
1100 std::optional<wpi::units::turn_t> GetClosedLoopTolerance() const;
1103
1107 std::optional<MotorMode> GetZeroPower() const;
1109 std::optional<wpi::units::second_t> GetClosedLoopControlPeriod() const;
1111 std::optional<wpi::units::second_t> GetOpenLoopRampRate() const;
1113 std::optional<wpi::units::second_t> GetClosedLoopRampRate() const;
1114
1119 std::optional<bool> GetMotorInverted() const;
1121 std::optional<bool> GetEncoderInverted() const;
1124
1126 std::optional<std::string> GetTelemetryName() const;
1128 std::optional<TelemetryVerbosity> GetVerbosity() const;
1133 wpi::cmd::SubsystemBase* GetSubsystem() const;
1135 bool HasSubsystem() const;
1140 std::shared_ptr<telemetry::SmartMotorControllerTelemetryConfig>
1143 std::optional<wpi::math::DCMotor> GetSimMotor() const;
1145 wpi::units::second_t GetSimulationPeriod() const;
1147 wpi::units::kilogram_square_meter_t GetMOI() const;
1149 std::optional<wpi::units::turn_t> GetStartingPosition() const;
1151 std::optional<std::any> GetVendorConfig() const;
1153 std::optional<std::any> GetVendorControlRequest() const;
1154
1156 const std::optional<gearing::MechanismGearing>& GetMotorGearing() const;
1158 std::optional<wpi::units::meter_t> GetMechanismCircumference() const;
1159
1161 std::optional<std::any> GetExternalEncoder() const;
1168 std::optional<bool> GetExternalEncoderInverted() const;
1170 std::optional<double> GetExternalEncoderConversionFactor() const;
1172 std::optional<wpi::units::turn_t> GetExternalEncoderZeroOffset() const;
1174 const std::optional<gearing::MechanismGearing>& GetExternalEncoderGearing() const;
1176 std::optional<wpi::units::turn_t> GetExternalEncoderDiscontinuityPoint() const;
1177
1184
1186 std::optional<wpi::math::TrapezoidProfile<wpi::units::turns>> GetTrapezoidProfile() const;
1188 std::optional<wpi::math::TrapezoidProfile<wpi::units::meters>> GetLinearTrapezoidProfile() const;
1190 std::optional<wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>>
1193 std::optional<wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>>
1195
1197 std::optional<wpi::units::turns_per_second_t> GetTrapMaxVelocityTurns() const;
1199 std::optional<wpi::units::turns_per_second_squared_t> GetTrapMaxAccelTurns() const;
1201 std::optional<wpi::units::meters_per_second_t> GetTrapMaxVelocityLinear() const;
1203 std::optional<wpi::units::meters_per_second_squared_t> GetTrapMaxAccelLinear() const;
1204
1206 std::optional<double> GetExponentialProfileKV() const;
1208 std::optional<double> GetExponentialProfileKA() const;
1210 std::optional<wpi::units::volt_t> GetExponentialProfileMaxInput() const;
1211
1221 wpi::units::meter_t ConvertFromMechanism(wpi::units::turn_t mechanismPosition) const;
1222
1229 wpi::units::meters_per_second_t ConvertFromMechanism(
1230 wpi::units::turns_per_second_t mechanismVelocity) const;
1231
1238 wpi::units::meters_per_second_squared_t ConvertFromMechanism(
1239 wpi::units::turns_per_second_squared_t mechanismAcceleration) const;
1240
1248 wpi::units::angular_jerk::turns_per_second_cubed_t mechanismJerk) const;
1249
1256 wpi::units::turn_t ConvertToMechanism(wpi::units::meter_t distance) const;
1257
1264 wpi::units::turns_per_second_t ConvertToMechanism(wpi::units::meters_per_second_t velocity) const;
1265
1272 wpi::units::turns_per_second_squared_t ConvertToMechanism(
1273 wpi::units::meters_per_second_squared_t acceleration) const;
1274
1281 wpi::units::angular_jerk::turns_per_second_cubed_t ConvertToMechanism(
1282 meters_per_second_cubed_t jerk) const;
1283
1293 wpi::units::volt_t ConvertToVoltage(const wpi::math::DCMotor& motor,
1294 wpi::units::newton_t feedforwardForce) const;
1295
1304 wpi::units::ampere_t ConvertToCurrent(const wpi::math::DCMotor& motor,
1305 wpi::units::newton_t feedforwardForce) const;
1306
1307 private:
1308 static constexpr int kNumSlots = 4;
1309
1310 PIDGains m_slots[kNumSlots];
1311 // Slots that received PID gains via WithFeedback (zero gains still count as configured).
1312 bool m_slotHasFeedback[kNumSlots]{false, false, false, false};
1313 int SlotIndex(ClosedLoopControllerSlot slot) const;
1314
1315 // Validation tracking options that every ApplyConfig implementation must access
1316 enum class BasicOptions {
1317 VendorControlRequest,
1319 ClosedLoopMaxVoltage,
1320 StartingPosition,
1321 EncoderInverted,
1322 MotorInverted,
1323 TemperatureCutoff,
1324 UpperLimit,
1325 LowerLimit,
1326 ZeroPower,
1327 StatorCurrentLimit,
1328 SupplyCurrentLimit,
1329 ClosedLoopRampRate,
1330 OpenLoopRampRate,
1331 ExternalEncoder,
1332 Gearing,
1333 SlotGains,
1334 TrapezoidProfile,
1335 ExponentialProfile,
1336 ContinuousWrapping,
1337 Followers,
1338 LooselyCoupledFollowers,
1339 VoltageCompensation,
1340 FeedbackSynchronizationThreshold,
1341 ClosedLoopTolerance,
1342 ClosedLoopControlPeriod,
1343 ResetPreviousConfig,
1344 };
1345 enum class ExternalEncoderOptions {
1346 ZeroOffset,
1347 DiscontinuityPoint,
1348 UseExternalFeedback,
1349 ExternalGearing,
1350 ExternalEncoderInverted,
1351 };
1352 static std::string_view ToString(BasicOptions opt);
1353 static std::string_view ToString(ExternalEncoderOptions opt);
1354 mutable std::set<BasicOptions> m_basicOptions;
1355 mutable std::set<ExternalEncoderOptions> m_externalEncoderOptions;
1356
1358 double ForceToRotorTorque(wpi::units::newton_t feedforwardForce) const;
1360 void RequireCircumference(const std::string& action) const;
1362 bool HasClosedLoopController() const;
1363
1364 // Per-slot simulation gain overrides
1365 struct SimGainsOverride {
1366 std::optional<double> kP, kI, kD;
1367 std::optional<math::LQRConfig> lqr;
1368 std::optional<wpi::math::ArmFeedforward> armFF;
1369 std::optional<wpi::math::ElevatorFeedforward> elevatorFF;
1370 std::optional<wpi::math::SimpleMotorFeedforward<wpi::units::turns>> simpleFF;
1371 };
1372 SimGainsOverride m_simGains[kNumSlots];
1373
1374 // Profiles
1375 std::optional<wpi::math::TrapezoidProfile<wpi::units::turns>> m_trapProfile;
1376 std::optional<wpi::math::TrapezoidProfile<wpi::units::meters>> m_linearTrapProfile;
1377 std::optional<wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>> m_expoProfile;
1378 std::optional<wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>>
1379 m_linearExpoProfile;
1380 bool m_velocityTrapProfile{false};
1381 // Stored constraint values for hardware motor controller configuration
1382 std::optional<wpi::units::turns_per_second_t> m_trapMaxVelTurns;
1383 std::optional<wpi::units::turns_per_second_squared_t> m_trapMaxAccTurns;
1384 std::optional<wpi::units::meters_per_second_t> m_trapMaxVelLinear;
1385 std::optional<wpi::units::meters_per_second_squared_t> m_trapMaxAccLinear;
1386 // kV/kA in V*s/turn and V*s²/turn for direct CTRE MotionMagicExpo assignment
1387 std::optional<double> m_expoMotionMagicKV;
1388 std::optional<double> m_expoMotionMagicKA;
1389 std::optional<wpi::units::volt_t> m_expoMaxInput;
1390
1391 // Limits
1392 std::optional<wpi::units::turn_t> m_mechLowerLimit;
1393 std::optional<wpi::units::turn_t> m_mechUpperLimit;
1394 std::optional<wpi::units::ampere_t> m_statorCurrentLimit;
1395 std::optional<wpi::units::ampere_t> m_supplyCurrentLimit;
1396 std::optional<wpi::units::celsius_t> m_temperatureCutoff;
1397 std::optional<wpi::units::volt_t> m_closedLoopMaxVoltage;
1398 std::optional<wpi::units::volt_t> m_voltageCompensation;
1399 std::optional<wpi::units::turn_t> m_feedbackSynchronizationThreshold;
1400 std::optional<wpi::units::turn_t> m_closedLoopTolerance;
1401 bool m_resetPreviousConfig{true};
1402 std::optional<wpi::units::turn_t> m_continuousWrappingMin;
1403 std::optional<wpi::units::turn_t> m_continuousWrappingMax;
1404
1405 // Control behaviour
1407 std::optional<MotorMode> m_zeroPower;
1408 std::optional<wpi::units::second_t> m_closedLoopPeriod;
1409 std::optional<wpi::units::second_t> m_openLoopRampRate;
1410 std::optional<wpi::units::second_t> m_closedLoopRampRate;
1411
1412 // Inversion empty means the user never called WithMotorInverted / WithEncoderInverted.
1413 std::optional<bool> m_motorInverted;
1414 std::optional<bool> m_encoderInverted;
1415
1416 // Gearing / linear
1417 std::optional<gearing::MechanismGearing> m_motorGearing;
1418 std::optional<wpi::units::meter_t> m_mechanismCircumference;
1419 bool m_linearClosedLoopController{false};
1420
1421 // External encoder
1422 std::optional<std::any> m_externalEncoder;
1423 bool m_useExternalFeedback{true};
1424 std::optional<bool> m_externalEncoderInverted;
1425 std::optional<double> m_externalEncoderConversionFactor;
1426 std::optional<wpi::units::turn_t> m_externalEncoderZeroOffset;
1427 std::optional<gearing::MechanismGearing> m_externalEncoderGearing;
1428 std::optional<wpi::units::turn_t> m_externalEncoderDiscontinuityPoint;
1429
1430 // Telemetry
1431 std::optional<std::string> m_telemetryName;
1432 std::optional<TelemetryVerbosity> m_verbosity;
1433 // shared_ptr so the forward-declared, non-copyable type can be held.
1434 std::shared_ptr<telemetry::SmartMotorControllerTelemetryConfig> m_telemetryConfig;
1435
1436 wpi::cmd::SubsystemBase* m_subsystem{nullptr};
1437 std::optional<wpi::math::DCMotor> m_simMotor;
1438 wpi::units::kilogram_square_meter_t m_moi{0.02_kg_sq_m};
1439 std::optional<wpi::units::second_t> m_simulationPeriod;
1440 std::optional<wpi::units::turn_t> m_startingPosition;
1441 std::optional<wpi::units::meter_t> m_startingPositionDistance;
1442
1443 // Simulation overrides
1444 std::optional<wpi::units::turn_t> m_simStartingPosition;
1445 std::optional<wpi::math::TrapezoidProfile<wpi::units::turns>> m_simTrapProfile;
1446 std::optional<wpi::math::TrapezoidProfile<wpi::units::meters>> m_simLinearTrapProfile;
1447 std::optional<wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>>
1448 m_simExpoProfile;
1449
1450 std::optional<std::any> m_vendorConfig;
1451 std::optional<std::any> m_vendorControlRequest;
1452
1453 // Followers
1454 std::vector<std::pair<std::any, bool>> m_followers;
1455 std::vector<SmartMotorController*> m_looseFollowers;
1456};
1457
1458} // namespace yams::motorcontrollers
Definition MechanismGearing.hpp:19
Definition LQRConfig.hpp:27
Definition SmartMotorControllerConfig.hpp:65
std::optional< bool > GetExternalEncoderInverted() const
SmartMotorControllerConfig & WithStartingPosition(wpi::units::meter_t startingDistance)
SmartMotorControllerConfig & WithTelemetry(const std::string &name, TelemetryVerbosity verbosity=TelemetryVerbosity::HIGH)
SmartMotorControllerConfig & WithSupplyCurrentLimit(wpi::units::ampere_t limit)
wpi::units::turn_t ConvertToMechanism(wpi::units::meter_t distance) const
std::optional< wpi::units::volt_t > GetExponentialProfileMaxInput() const
SmartMotorControllerConfig & WithTemperatureCutoff(wpi::units::celsius_t temperature)
wpi::units::turn_t GetContinuousWrappingSetpoint(wpi::units::turn_t setpoint, wpi::units::turn_t current) const
SmartMotorControllerConfig & WithTrapezoidProfile(wpi::units::turns_per_second_t maxVelocity, wpi::units::turns_per_second_squared_t maxAcceleration)
SmartMotorControllerConfig & WithMotorInverted(bool inverted)
std::optional< wpi::units::volt_t > GetVoltageCompensation() const
SmartMotorControllerConfig & WithZeroPower(MotorMode mode)
std::optional< std::any > GetExternalEncoder() const
std::optional< wpi::units::turn_t > GetMechanismLowerLimit() const
SmartMotorControllerConfig & WithExternalEncoderGearing(double reductionRatio)
SmartMotorControllerConfig & WithExternalEncoderInverted(bool inverted)
std::optional< wpi::units::turn_t > GetContinuousWrapping() const
std::optional< wpi::math::SimpleMotorFeedforward< wpi::units::turns > > GetSimpleFeedforward(ClosedLoopControllerSlot slot) const
const std::vector< std::pair< std::any, bool > > & GetFollowers() const
SmartMotorControllerConfig & WithContinuousWrapping(wpi::units::turn_t min, wpi::units::turn_t max)
wpi::units::turns_per_second_t ConvertToMechanism(wpi::units::meters_per_second_t velocity) const
std::optional< wpi::units::turn_t > GetStartingPosition() const
SmartMotorControllerConfig & WithMOI(wpi::units::meter_t length, wpi::units::kilogram_t mass)
wpi::units::kilogram_square_meter_t GetMOI() const
wpi::units::ampere_t ConvertToCurrent(const wpi::math::DCMotor &motor, wpi::units::newton_t feedforwardForce) const
SmartMotorControllerConfig & WithClosedLoopControlPeriod(wpi::units::second_t period)
std::optional< wpi::units::meter_t > GetMeasurementLowerLimit() const
SmartMotorControllerConfig & WithClosedLoopRampRate(wpi::units::second_t rampRate)
double GetKi(ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0) const
std::optional< wpi::units::turns_per_second_squared_t > GetTrapMaxAccelTurns() const
SmartMotorControllerConfig & WithClosedLoopMode()
std::optional< wpi::units::turn_t > GetExternalEncoderDiscontinuityPoint() const
SmartMotorControllerConfig & WithExponentialProfile(wpi::units::volt_t maxVolts, wpi::math::DCMotor motor, wpi::units::kilogram_t mass, wpi::units::meter_t drumRadius)
SmartMotorControllerConfig & WithStartingPosition(wpi::units::degree_t startingAngle)
std::optional< int > GetStatorStallCurrentLimit() const
TelemetryVerbosity
Definition SmartMotorControllerConfig.hpp:72
wpi::units::meters_per_second_squared_t ConvertFromMechanism(wpi::units::turns_per_second_squared_t mechanismAcceleration) const
wpi::units::meters_per_second_t ConvertFromMechanism(wpi::units::turns_per_second_t mechanismVelocity) const
SmartMotorControllerConfig & WithSimFeedforward(const wpi::math::ArmFeedforward &ff, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
SmartMotorControllerConfig & WithMotorGearing(const gearing::MechanismGearing &gearing)
double GetKp(ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0) const
std::optional< wpi::math::ArmFeedforward > GetArmFeedforward(ClosedLoopControllerSlot slot) const
SmartMotorControllerConfig & WithMechanismLimits(wpi::units::turn_t lower, wpi::units::turn_t upper)
PIDGains GetSlotGains(ClosedLoopControllerSlot slot) const
SmartMotorControllerConfig & WithSimStartingPosition(wpi::units::degree_t startingAngle)
std::optional< wpi::units::ampere_t > GetStatorCurrentLimit() const
wpi::units::meter_t ConvertFromMechanism(wpi::units::turn_t mechanismPosition) const
std::optional< wpi::units::turn_t > GetMechanismUpperLimit() const
SmartMotorControllerConfig & WithSubsystem(wpi::cmd::SubsystemBase *subsystem)
SmartMotorControllerConfig & WithCascadingElevatorStages(int stages)
SmartMotorControllerConfig & WithSimulationPeriod(wpi::units::second_t period)
SmartMotorControllerConfig & WithExternalEncoderGearing(const gearing::MechanismGearing &gearing)
SmartMotorControllerConfig & WithSimTrapezoidProfile(wpi::units::turns_per_second_t maxVelocity, wpi::units::turns_per_second_squared_t maxAcceleration)
SmartMotorControllerConfig Clone() const
SmartMotorControllerConfig & WithFeedforward(const wpi::math::ArmFeedforward &ff, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
std::optional< wpi::units::ampere_t > GetSupplyCurrentLimit() const
std::optional< bool > GetMotorInverted() const
wpi::units::volt_t ConvertToVoltage(const wpi::math::DCMotor &motor, wpi::units::newton_t feedforwardForce) const
SmartMotorControllerConfig & WithFollowers(std::vector< std::pair< std::any, bool > > followers)
SmartMotorControllerConfig & WithExponentialProfile(double kV, double kA, wpi::units::volt_t maxInput)
std::optional< TelemetryVerbosity > GetVerbosity() const
ControlMode
Definition SmartMotorControllerConfig.hpp:68
SmartMotorControllerConfig & WithSimStartingPosition(wpi::units::meter_t startingDistance)
SmartMotorControllerConfig & WithSimFeedforward(const wpi::math::SimpleMotorFeedforward< wpi::units::turns > &ff, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
std::optional< MotorMode > GetZeroPower() const
SmartMotorControllerConfig & WithLinearExponentialProfile(double kV, double kA, wpi::units::volt_t maxInput)
SmartMotorControllerConfig & WithVelocityTrapezoidProfile(wpi::units::meters_per_second_squared_t maxAcceleration, meters_per_second_cubed_t maxJerk)
std::optional< wpi::units::second_t > GetClosedLoopControlPeriod() const
std::optional< wpi::units::second_t > GetClosedLoopRampRate() const
SmartMotorControllerConfig & WithVendorControlRequest(std::any req)
SmartMotorControllerConfig & WithVoltageCompensation(wpi::units::volt_t voltage)
std::optional< wpi::units::meters_per_second_t > GetTrapMaxVelocityLinear() const
SmartMotorControllerConfig & WithFeedback(double kP, double kI, double kD, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
SmartMotorControllerConfig & WithClosedLoopTolerance(wpi::units::meter_t tolerance)
SmartMotorControllerConfig & WithExternalEncoderZeroOffset(wpi::units::turn_t zeroOffset)
SmartMotorControllerConfig & WithExternalEncoderDiscontinuityPoint(wpi::units::turn_t discontinuityPoint)
SmartMotorControllerConfig & WithSimClosedLoopController(double kP, double kI, double kD, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
SmartMotorControllerConfig & WithFeedbackSynchronizationThreshold(wpi::units::turn_t threshold)
SmartMotorControllerConfig & WithVendorConfig(std::any cfg)
SmartMotorControllerConfig & WithFeedforward(const wpi::math::ElevatorFeedforward &ff, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
std::shared_ptr< telemetry::SmartMotorControllerTelemetryConfig > GetSmartControllerTelemetryConfig() const
const std::optional< gearing::MechanismGearing > & GetMotorGearing() const
SmartMotorControllerConfig & WithStatorCurrentLimit(wpi::units::ampere_t limit)
std::optional< double > GetExternalEncoderConversionFactor() const
std::optional< wpi::math::DCMotor > GetSimMotor() const
std::optional< wpi::math::TrapezoidProfile< wpi::units::meters > > GetLinearTrapezoidProfile() const
SmartMotorControllerConfig & WithOpenLoopRampRate(wpi::units::second_t rampRate)
std::optional< std::any > GetVendorConfig() const
SmartMotorControllerConfig & WithMOI(wpi::units::kilogram_square_meter_t moi)
SmartMotorControllerConfig & WithExponentialProfile(wpi::units::volt_t maxVolts, wpi::math::DCMotor motor, wpi::units::kilogram_square_meter_t moi)
wpi::cmd::SubsystemBase * GetSubsystem() const
std::optional< wpi::units::volt_t > GetClosedLoopControllerMaximumVoltage() const
SmartMotorControllerConfig & WithMotorGearing(double reductionRatio)
std::optional< wpi::units::meters_per_second_squared_t > GetTrapMaxAccelLinear() const
SmartMotorControllerConfig & WithMechanismCircumference(wpi::units::meter_t gearPitch, int teeth)
SmartMotorControllerConfig & WithResetPreviousConfig(bool reset)
SmartMotorControllerConfig & WithTelemetry(TelemetryVerbosity verbosity)
SmartMotorControllerConfig & WithMechanismRadius(wpi::units::meter_t radius)
std::optional< std::string > GetTelemetryName() const
std::optional< wpi::math::TrapezoidProfile< wpi::units::turns > > GetTrapezoidProfile() const
SmartMotorControllerConfig & WithMechanismCircumference(wpi::units::meter_t circumference)
meters_per_second_cubed_t ConvertFromMechanism(wpi::units::angular_jerk::turns_per_second_cubed_t mechanismJerk) const
std::optional< wpi::units::turns_per_second_t > GetTrapMaxVelocityTurns() const
SmartMotorControllerConfig & WithMechanismDiameter(wpi::units::meter_t diameter)
SmartMotorControllerConfig & WithExponentialProfile(wpi::units::volt_t maxVolts, wpi::units::turns_per_second_t maxVelocity, wpi::units::turns_per_second_squared_t maxAcceleration)
wpi::units::angular_jerk::turns_per_second_cubed_t ConvertToMechanism(meters_per_second_cubed_t jerk) const
SmartMotorControllerConfig & WithSimExponentialProfile(wpi::math::ExponentialProfile< wpi::units::turns, wpi::units::volts >::Constraints constraints)
SmartMotorControllerConfig & WithExternalEncoder(std::any encoder)
SmartMotorControllerConfig & WithExponentialProfile(wpi::math::ExponentialProfile< wpi::units::turns, wpi::units::volts >::Constraints constraints)
SmartMotorControllerConfig & WithLinearTrapezoidProfile(wpi::units::meters_per_second_t maxVelocity, wpi::units::meters_per_second_squared_t maxAcceleration)
std::optional< std::any > GetVendorControlRequest() const
std::optional< wpi::units::meter_t > GetMeasurementUpperLimit() const
std::optional< math::LQRConfig > GetLQR(ClosedLoopControllerSlot slot) const
std::optional< wpi::units::turn_t > GetClosedLoopTolerance() const
SmartMotorControllerConfig & WithLooselyCoupledFollowers(std::vector< SmartMotorController * > followers)
std::optional< int > GetSupplyStallCurrentLimit() const
std::optional< wpi::units::celsius_t > GetTemperatureCutoff() const
SmartMotorControllerConfig & WithSimClosedLoopController(const math::LQRConfig &lqrConfig, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
ClosedLoopControllerSlot
Definition SmartMotorControllerConfig.hpp:74
SmartMotorControllerConfig & WithClosedLoopTolerance(wpi::units::turn_t tolerance)
SmartMotorControllerConfig & WithLQR(const math::LQRConfig &lqrConfig, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
std::optional< wpi::math::ElevatorFeedforward > GetElevatorFeedforward(ClosedLoopControllerSlot slot) const
std::optional< wpi::math::ExponentialProfile< wpi::units::turns, wpi::units::volts > > GetExponentialProfile() const
SmartMotorControllerConfig & WithOpenLoopMode()
SmartMotorControllerConfig & WithSimMotor(wpi::math::DCMotor motor)
const std::vector< SmartMotorController * > & GetLooselyCoupledFollowers() const
SmartMotorControllerConfig & WithLinearClosedLoopController(bool linear)
wpi::units::turns_per_second_squared_t ConvertToMechanism(wpi::units::meters_per_second_squared_t acceleration) const
SmartMotorControllerConfig & WithEncoderInverted(bool inverted)
SmartMotorControllerConfig & WithVelocityTrapezoidProfile(wpi::units::turns_per_second_squared_t maxAcceleration, wpi::units::angular_jerk::turns_per_second_cubed_t maxJerk)
SmartMotorControllerConfig & WithMeasurementLimits(wpi::units::meter_t lower, wpi::units::meter_t upper)
SmartMotorControllerConfig & WithUseExternalFeedbackEncoder(bool use)
SmartMotorControllerConfig & WithSimTrapezoidProfile(wpi::units::meters_per_second_t maxVelocity, wpi::units::meters_per_second_squared_t maxAcceleration)
std::optional< wpi::math::ExponentialProfile< wpi::units::meters, wpi::units::volts > > GetLinearExponentialProfile() const
const std::optional< gearing::MechanismGearing > & GetExternalEncoderGearing() const
std::optional< wpi::units::turn_t > GetFeedbackSynchronizationThreshold() const
std::optional< wpi::units::meter_t > GetMechanismCircumference() const
wpi::units::second_t GetSimulationPeriod() const
std::optional< wpi::units::turn_t > GetExternalEncoderZeroOffset() const
std::optional< bool > GetEncoderInverted() const
SmartMotorControllerConfig & WithExternalEncoderConversionFactor(double factor)
std::optional< wpi::units::turn_t > GetContinuousWrappingMin() const
MotorMode
Definition SmartMotorControllerConfig.hpp:70
std::optional< double > GetExponentialProfileKA() const
std::optional< double > GetExponentialProfileKV() const
SmartMotorControllerConfig & WithExternalEncoderZeroOffset(wpi::units::meter_t zeroOffset)
SmartMotorControllerConfig & WithSimFeedforward(const wpi::math::ElevatorFeedforward &ff, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
SmartMotorControllerConfig & WithClosedLoopMaxVoltage(wpi::units::volt_t maxVoltage)
SmartMotorControllerConfig & WithFeedforward(const wpi::math::SimpleMotorFeedforward< wpi::units::turns > &ff, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
double GetKd(ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0) const
std::optional< wpi::units::second_t > GetOpenLoopRampRate() const
SmartMotorControllerConfig & WithTelemetry(const std::string &name, telemetry::SmartMotorControllerTelemetryConfig telemetryConfig)
Definition SmartMotorControllerTelemetryConfig.hpp:63
Definition SimSensorConfig.hpp:15
wpi::units::unit_t< wpi::units::compound_unit< wpi::units::meters, wpi::units::inverse< wpi::units::cubed< wpi::units::seconds > > > > meters_per_second_cubed_t
Definition SmartMotorControllerConfig.hpp:56
Definition SwerveDrive.hpp:864
Definition SmartMotorControllerConfig.hpp:971
double kP
Definition SmartMotorControllerConfig.hpp:972
double kD
Definition SmartMotorControllerConfig.hpp:972
double kS
Definition SmartMotorControllerConfig.hpp:973
std::optional< wpi::math::ElevatorFeedforward > elevatorFF
Definition SmartMotorControllerConfig.hpp:975
double kV
Definition SmartMotorControllerConfig.hpp:973
std::optional< math::LQRConfig > lqr
Definition SmartMotorControllerConfig.hpp:977
std::optional< wpi::math::ArmFeedforward > armFF
Definition SmartMotorControllerConfig.hpp:974
double kI
Definition SmartMotorControllerConfig.hpp:972
std::optional< wpi::math::SimpleMotorFeedforward< wpi::units::turns > > simpleFF
Definition SmartMotorControllerConfig.hpp:976
double kG
Definition SmartMotorControllerConfig.hpp:973
double kA
Definition SmartMotorControllerConfig.hpp:973