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
39
40namespace yams::motorcontrollers {
41
42// Forward declaration to avoid circular dependency (SmartMotorController.hpp
43// includes this header, so we cannot include it here).
45
46} // namespace yams::motorcontrollers
47
48namespace yams::telemetry {
49// Forward declaration; SmartMotorControllerTelemetryConfig.hpp includes this header.
51} // namespace yams::telemetry
52
53namespace yams::motorcontrollers {
54
56using meters_per_second_cubed_t = wpi::units::unit_t<wpi::units::compound_unit<
57 wpi::units::meters, wpi::units::inverse<wpi::units::cubed<wpi::units::seconds>>>>;
58
67 public:
71 enum class MotorMode { COAST, BRAKE };
76
79
80 // ---- Feedback -------------------------------------------------------
81
92 double kP, double kI, double kD,
94
95 // ---- Feedforward -------------------------------------------------------
96
105 const wpi::math::ArmFeedforward& ff,
107
116 const wpi::math::ElevatorFeedforward& ff,
118
127 const wpi::math::SimpleMotorFeedforward<wpi::units::turns>& ff,
129
130 // ---- Motion profiles ---------------------------------------------------
131
140 wpi::units::turns_per_second_t maxVelocity,
141 wpi::units::turns_per_second_squared_t maxAcceleration);
142
151 wpi::units::meters_per_second_t maxVelocity,
152 wpi::units::meters_per_second_squared_t maxAcceleration);
153
165 wpi::units::turns_per_second_squared_t maxAcceleration,
166 wpi::units::angular_jerk::turns_per_second_cubed_t maxJerk);
167
178 wpi::units::meters_per_second_squared_t maxAcceleration, meters_per_second_cubed_t maxJerk);
179
189 wpi::units::volt_t maxInput);
190
204 wpi::math::DCMotor motor,
205 wpi::units::kilogram_square_meter_t moi);
206
221 wpi::math::DCMotor motor,
222 wpi::units::kilogram_t mass,
223 wpi::units::meter_t drumRadius);
224
234 wpi::units::volt_t maxVolts, wpi::units::turns_per_second_t maxVelocity,
235 wpi::units::turns_per_second_squared_t maxAcceleration);
236
244 wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>::Constraints constraints);
245
258 wpi::units::volt_t maxInput);
259
260 // ---- LQR ---------------------------------------------------------------
261
270 const math::LQRConfig& lqrConfig,
272
273 // ---- ADRC --------------------------------------------------------------
274
292 const math::ADRCConfig& adrcConfig,
294
303
315
325
336
337 // ---- Gearing / linear --------------------------------------------------
338
346
354
364
371 SmartMotorControllerConfig& WithMechanismCircumference(wpi::units::meter_t circumference);
372
382 SmartMotorControllerConfig& WithMechanismCircumference(wpi::units::meter_t gearPitch, int teeth);
383
392 SmartMotorControllerConfig& WithMechanismDiameter(wpi::units::meter_t diameter);
393
403
404 // ---- Limits ------------------------------------------------------------
405
416 wpi::units::turn_t upper);
417
431 wpi::units::meter_t upper);
432
440
448
455 SmartMotorControllerConfig& WithTemperatureCutoff(wpi::units::celsius_t temperature);
456
464
472
484
485 // ---- Control behaviour -------------------------------------------------
486
494
501
508
516
525
526 // ---- Ramp rates --------------------------------------------------------
527
534 SmartMotorControllerConfig& WithOpenLoopRampRate(wpi::units::second_t rampRate);
535
544 SmartMotorControllerConfig& WithClosedLoopRampRate(wpi::units::second_t rampRate);
545
546 // ---- Inversion ---------------------------------------------------------
547
555
563
564 // ---- External encoder --------------------------------------------------
565
586
595
603
614
622
633
644
652
662 SmartMotorControllerConfig& WithWrapping(wpi::units::turn_t min, wpi::units::turn_t max);
663
677 wpi::units::turn_t max);
678
679 // ---- Telemetry ----------------------------------------------------------
680
689 const std::string& name, TelemetryVerbosity verbosity = TelemetryVerbosity::HIGH);
690
698
711 const std::string& name, telemetry::SmartMotorControllerTelemetryConfig telemetryConfig);
712
713 // ---- Subsystem ---------------------------------------------------------
714
724 SmartMotorControllerConfig& WithSubsystem(wpi::cmd::SubsystemBase* subsystem);
725
726 // ---- Simulation --------------------------------------------------------
727
734 SmartMotorControllerConfig& WithSimMotor(wpi::math::DCMotor motor);
735
745
746 // ---- Simulation overrides -----------------------------------------------
747
757 SmartMotorControllerConfig& WithSimStartingPosition(wpi::units::degree_t startingAngle);
758
767 SmartMotorControllerConfig& WithSimStartingPosition(wpi::units::meter_t startingDistance);
768
777 const wpi::math::ArmFeedforward& ff,
779
788 const wpi::math::ElevatorFeedforward& ff,
790
799 const wpi::math::SimpleMotorFeedforward<wpi::units::turns>& ff,
801
812 double kP, double kI, double kD,
814
825 const math::LQRConfig& lqrConfig,
827
836 wpi::units::turns_per_second_t maxVelocity,
837 wpi::units::turns_per_second_squared_t maxAcceleration);
838
847 wpi::units::meters_per_second_t maxVelocity,
848 wpi::units::meters_per_second_squared_t maxAcceleration);
849
857 wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>::Constraints constraints);
858
865 SmartMotorControllerConfig& WithMOI(wpi::units::kilogram_square_meter_t moi);
866
876 SmartMotorControllerConfig& WithMOI(wpi::units::meter_t length, wpi::units::kilogram_t mass);
877
887 SmartMotorControllerConfig& WithWheelMOI(wpi::units::meter_t diameter, wpi::units::kilogram_t mass);
888
897 SmartMotorControllerConfig& WithStartingPosition(wpi::units::degree_t startingAngle);
898
910 SmartMotorControllerConfig& WithStartingPosition(wpi::units::meter_t startingDistance);
911
930
931 // ---- Followers -------------------------------------------------------------
932
945 SmartMotorControllerConfig& WithFollowers(std::vector<std::pair<std::any, bool>> followers);
946
958 std::vector<SmartMotorController*> followers);
959
962
964 const std::vector<std::pair<std::any, bool>>& GetFollowers() const;
965
967 const std::vector<SmartMotorController*>& GetLooselyCoupledFollowers() const;
968
969 // ---- Clone -----------------------------------------------------------------
970
980
981 // ---- Validation ------------------------------------------------------------
982
989
997
1004
1016
1017 // === Getters ============================================================
1018
1020 struct PIDGains {
1021 double kP{0.0}, kI{0.0}, kD{0.0};
1022 double kS{0.0}, kV{0.0}, kA{0.0}, kG{0.0};
1023 std::optional<wpi::math::ArmFeedforward> armFF;
1024 std::optional<wpi::math::ElevatorFeedforward> elevatorFF;
1025 std::optional<wpi::math::SimpleMotorFeedforward<wpi::units::turns>> simpleFF;
1026 std::optional<math::LQRConfig> lqr;
1027 };
1028
1039
1046 std::optional<wpi::math::ArmFeedforward> GetArmFeedforward(ClosedLoopControllerSlot slot) const;
1047
1054 std::optional<wpi::math::ElevatorFeedforward> GetElevatorFeedforward(
1055 ClosedLoopControllerSlot slot) const;
1056
1063 std::optional<wpi::math::SimpleMotorFeedforward<wpi::units::turns>> GetSimpleFeedforward(
1064 ClosedLoopControllerSlot slot) const;
1065
1072 std::optional<math::LQRConfig> GetLQR(ClosedLoopControllerSlot slot) const;
1073
1081 std::shared_ptr<math::ADRCConfig> GetADRCController(
1083
1091
1099
1107
1114
1116 std::optional<wpi::units::turn_t> GetMechanismLowerLimit() const;
1118 std::optional<wpi::units::turn_t> GetMechanismUpperLimit() const;
1120 std::optional<wpi::units::meter_t> GetMeasurementLowerLimit() const;
1122 std::optional<wpi::units::meter_t> GetMeasurementUpperLimit() const;
1123
1125 std::optional<wpi::units::turn_t> GetWrappingMax() const;
1127 std::optional<wpi::units::turn_t> GetWrappingMin() const;
1134
1144 wpi::units::turn_t GetContinuousWrappingSetpoint(wpi::units::turn_t setpoint,
1145 wpi::units::turn_t current) const;
1146
1148 std::optional<wpi::units::ampere_t> GetStatorCurrentLimit() const;
1150 std::optional<int> GetStatorStallCurrentLimit() const;
1152 std::optional<int> GetSupplyStallCurrentLimit() const;
1154 std::optional<wpi::units::ampere_t> GetSupplyCurrentLimit() const;
1156 std::optional<wpi::units::celsius_t> GetTemperatureCutoff() const;
1158 std::optional<wpi::units::volt_t> GetClosedLoopControllerMaximumVoltage() const;
1160 std::optional<wpi::units::volt_t> GetVoltageCompensation() const;
1162 std::optional<wpi::units::turn_t> GetFeedbackSynchronizationThreshold() const;
1164 std::optional<wpi::units::turn_t> GetClosedLoopTolerance() const;
1167
1171 std::optional<MotorMode> GetZeroPower() const;
1173 std::optional<wpi::units::second_t> GetClosedLoopControlPeriod() const;
1175 std::optional<wpi::units::second_t> GetOpenLoopRampRate() const;
1177 std::optional<wpi::units::second_t> GetClosedLoopRampRate() const;
1178
1183 std::optional<bool> GetMotorInverted() const;
1185 std::optional<bool> GetEncoderInverted() const;
1188
1190 std::optional<std::string> GetTelemetryName() const;
1192 std::optional<TelemetryVerbosity> GetVerbosity() const;
1197 wpi::cmd::SubsystemBase* GetSubsystem() const;
1199 bool HasSubsystem() const;
1204 std::shared_ptr<telemetry::SmartMotorControllerTelemetryConfig>
1207 std::optional<wpi::math::DCMotor> GetSimMotor() const;
1209 wpi::units::second_t GetSimulationPeriod() const;
1211 wpi::units::kilogram_square_meter_t GetMOI() const;
1218 std::optional<wpi::units::turn_t> GetStartingPosition() const;
1220 std::optional<std::any> GetVendorConfig() const;
1222 std::optional<std::any> GetVendorControlRequest() const;
1223
1225 const std::optional<gearing::MechanismGearing>& GetMotorGearing() const;
1227 std::optional<wpi::units::meter_t> GetMechanismCircumference() const;
1228
1230 std::optional<std::any> GetExternalEncoder() const;
1237 std::optional<bool> GetExternalEncoderInverted() const;
1239 std::optional<double> GetExternalEncoderConversionFactor() const;
1241 std::optional<wpi::units::turn_t> GetExternalEncoderZeroOffset() const;
1243 const std::optional<gearing::MechanismGearing>& GetExternalEncoderGearing() const;
1244
1251
1253 std::optional<wpi::math::TrapezoidProfile<wpi::units::turns>> GetTrapezoidProfile() const;
1255 std::optional<wpi::math::TrapezoidProfile<wpi::units::meters>> GetLinearTrapezoidProfile() const;
1257 std::optional<wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>>
1260 std::optional<wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>>
1262
1264 std::optional<wpi::units::turns_per_second_t> GetTrapMaxVelocityTurns() const;
1266 std::optional<wpi::units::turns_per_second_squared_t> GetTrapMaxAccelTurns() const;
1268 std::optional<wpi::units::meters_per_second_t> GetTrapMaxVelocityLinear() const;
1270 std::optional<wpi::units::meters_per_second_squared_t> GetTrapMaxAccelLinear() const;
1271
1273 std::optional<double> GetExponentialProfileKV() const;
1275 std::optional<double> GetExponentialProfileKA() const;
1277 std::optional<wpi::units::volt_t> GetExponentialProfileMaxInput() const;
1278
1288 wpi::units::meter_t ConvertFromMechanism(wpi::units::turn_t mechanismPosition) const;
1289
1296 wpi::units::meters_per_second_t ConvertFromMechanism(
1297 wpi::units::turns_per_second_t mechanismVelocity) const;
1298
1305 wpi::units::meters_per_second_squared_t ConvertFromMechanism(
1306 wpi::units::turns_per_second_squared_t mechanismAcceleration) const;
1307
1315 wpi::units::angular_jerk::turns_per_second_cubed_t mechanismJerk) const;
1316
1323 wpi::units::turn_t ConvertToMechanism(wpi::units::meter_t distance) const;
1324
1331 wpi::units::turns_per_second_t ConvertToMechanism(wpi::units::meters_per_second_t velocity) const;
1332
1339 wpi::units::turns_per_second_squared_t ConvertToMechanism(
1340 wpi::units::meters_per_second_squared_t acceleration) const;
1341
1348 wpi::units::angular_jerk::turns_per_second_cubed_t ConvertToMechanism(
1349 meters_per_second_cubed_t jerk) const;
1350
1360 wpi::units::volt_t ConvertToVoltage(const wpi::math::DCMotor& motor,
1361 wpi::units::newton_t feedforwardForce) const;
1362
1371 wpi::units::ampere_t ConvertToCurrent(const wpi::math::DCMotor& motor,
1372 wpi::units::newton_t feedforwardForce) const;
1373
1374 private:
1375 static constexpr int kNumSlots = 4;
1376
1377 PIDGains m_slots[kNumSlots];
1378 // Slots that received PID gains via WithFeedback (zero gains still count as configured).
1379 bool m_slotHasFeedback[kNumSlots]{false, false, false, false};
1380 int SlotIndex(ClosedLoopControllerSlot slot) const;
1381
1382 // Validation tracking options that every ApplyConfig implementation must access
1383 enum class BasicOptions {
1384 VendorControlRequest,
1386 ClosedLoopMaxVoltage,
1387 StartingPosition,
1388 EncoderInverted,
1389 MotorInverted,
1390 TemperatureCutoff,
1391 UpperLimit,
1392 LowerLimit,
1393 ZeroPower,
1394 StatorCurrentLimit,
1395 SupplyCurrentLimit,
1396 ClosedLoopRampRate,
1397 OpenLoopRampRate,
1398 ExternalEncoder,
1399 Gearing,
1400 SlotGains,
1401 TrapezoidProfile,
1402 ExponentialProfile,
1403 ContinuousWrapping,
1404 Followers,
1405 LooselyCoupledFollowers,
1406 VoltageCompensation,
1407 FeedbackSynchronizationThreshold,
1408 ClosedLoopTolerance,
1409 ClosedLoopControlPeriod,
1410 ResetPreviousConfig,
1411 };
1412 enum class ExternalEncoderOptions {
1413 ZeroOffset,
1414 UseExternalFeedback,
1415 ExternalGearing,
1416 ExternalEncoderInverted,
1417 };
1418 static std::string_view ToString(BasicOptions opt);
1419 static std::string_view ToString(ExternalEncoderOptions opt);
1420 mutable std::set<BasicOptions> m_basicOptions;
1421 mutable std::set<ExternalEncoderOptions> m_externalEncoderOptions;
1422
1424 double ForceToRotorTorque(wpi::units::newton_t feedforwardForce) const;
1426 void RequireCircumference(const std::string& action) const;
1428 bool HasClosedLoopController() const;
1429
1434 struct ADRCSlot {
1435 std::shared_ptr<math::ADRCConfig> config;
1436 ADRCSlot() = default;
1438 ADRCSlot(const ADRCSlot& other)
1439 : config{other.config ? std::make_shared<math::ADRCConfig>(*other.config) : nullptr} {}
1441 ADRCSlot& operator=(const ADRCSlot& other) {
1442 if (this != &other) config = other.config ? std::make_shared<math::ADRCConfig>(*other.config) : nullptr;
1443 return *this;
1444 }
1445 ADRCSlot(ADRCSlot&&) = default;
1446 ADRCSlot& operator=(ADRCSlot&&) = default;
1447 };
1448 ADRCSlot m_adrc[kNumSlots];
1450 bool m_momentOfInertiaConfigured{false};
1451
1452 // Per-slot simulation gain overrides
1453 struct SimGainsOverride {
1454 std::optional<double> kP, kI, kD;
1455 std::optional<math::LQRConfig> lqr;
1456 std::optional<wpi::math::ArmFeedforward> armFF;
1457 std::optional<wpi::math::ElevatorFeedforward> elevatorFF;
1458 std::optional<wpi::math::SimpleMotorFeedforward<wpi::units::turns>> simpleFF;
1459 };
1460 SimGainsOverride m_simGains[kNumSlots];
1461
1462 // Profiles
1463 std::optional<wpi::math::TrapezoidProfile<wpi::units::turns>> m_trapProfile;
1464 std::optional<wpi::math::TrapezoidProfile<wpi::units::meters>> m_linearTrapProfile;
1465 std::optional<wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>> m_expoProfile;
1466 std::optional<wpi::math::ExponentialProfile<wpi::units::meters, wpi::units::volts>>
1467 m_linearExpoProfile;
1468 bool m_velocityTrapProfile{false};
1469 // Stored constraint values for hardware motor controller configuration
1470 std::optional<wpi::units::turns_per_second_t> m_trapMaxVelTurns;
1471 std::optional<wpi::units::turns_per_second_squared_t> m_trapMaxAccTurns;
1472 std::optional<wpi::units::meters_per_second_t> m_trapMaxVelLinear;
1473 std::optional<wpi::units::meters_per_second_squared_t> m_trapMaxAccLinear;
1474 // kV/kA in V*s/turn and V*s²/turn for direct CTRE MotionMagicExpo assignment
1475 std::optional<double> m_expoMotionMagicKV;
1476 std::optional<double> m_expoMotionMagicKA;
1477 std::optional<wpi::units::volt_t> m_expoMaxInput;
1478
1479 // Limits
1480 std::optional<wpi::units::turn_t> m_mechLowerLimit;
1481 std::optional<wpi::units::turn_t> m_mechUpperLimit;
1482 std::optional<wpi::units::ampere_t> m_statorCurrentLimit;
1483 std::optional<wpi::units::ampere_t> m_supplyCurrentLimit;
1484 std::optional<wpi::units::celsius_t> m_temperatureCutoff;
1485 std::optional<wpi::units::volt_t> m_closedLoopMaxVoltage;
1486 std::optional<wpi::units::volt_t> m_voltageCompensation;
1487 std::optional<wpi::units::turn_t> m_feedbackSynchronizationThreshold;
1488 std::optional<wpi::units::turn_t> m_closedLoopTolerance;
1489 bool m_resetPreviousConfig{true};
1490 std::optional<wpi::units::turn_t> m_wrappingMin;
1491 std::optional<wpi::units::turn_t> m_wrappingMax;
1493 bool m_wrappingContinuous{false};
1494
1495 // Control behaviour
1497 std::optional<MotorMode> m_zeroPower;
1498 std::optional<wpi::units::second_t> m_closedLoopPeriod;
1499 std::optional<wpi::units::second_t> m_openLoopRampRate;
1500 std::optional<wpi::units::second_t> m_closedLoopRampRate;
1501
1502 // Inversion empty means the user never called WithMotorInverted / WithEncoderInverted.
1503 std::optional<bool> m_motorInverted;
1504 std::optional<bool> m_encoderInverted;
1505
1506 // Gearing / linear
1507 std::optional<gearing::MechanismGearing> m_motorGearing;
1508 std::optional<wpi::units::meter_t> m_mechanismCircumference;
1509 bool m_linearClosedLoopController{false};
1510
1511 // External encoder
1512 std::optional<std::any> m_externalEncoder;
1513 bool m_useExternalFeedback{true};
1514 std::optional<bool> m_externalEncoderInverted;
1515 std::optional<double> m_externalEncoderConversionFactor;
1516 std::optional<wpi::units::turn_t> m_externalEncoderZeroOffset;
1517 std::optional<gearing::MechanismGearing> m_externalEncoderGearing;
1518
1519 // Telemetry
1520 std::optional<std::string> m_telemetryName;
1521 std::optional<TelemetryVerbosity> m_verbosity;
1522 // shared_ptr so the forward-declared, non-copyable type can be held.
1523 std::shared_ptr<telemetry::SmartMotorControllerTelemetryConfig> m_telemetryConfig;
1524
1525 wpi::cmd::SubsystemBase* m_subsystem{nullptr};
1526 std::optional<wpi::math::DCMotor> m_simMotor;
1527 wpi::units::kilogram_square_meter_t m_moi{0.02_kg_sq_m};
1528 std::optional<wpi::units::second_t> m_simulationPeriod;
1529 std::optional<wpi::units::turn_t> m_startingPosition;
1530 std::optional<wpi::units::meter_t> m_startingPositionDistance;
1531
1532 // Simulation overrides
1533 std::optional<wpi::units::turn_t> m_simStartingPosition;
1534 std::optional<wpi::math::TrapezoidProfile<wpi::units::turns>> m_simTrapProfile;
1535 std::optional<wpi::math::TrapezoidProfile<wpi::units::meters>> m_simLinearTrapProfile;
1536 std::optional<wpi::math::ExponentialProfile<wpi::units::turns, wpi::units::volts>>
1537 m_simExpoProfile;
1538
1539 std::optional<std::any> m_vendorConfig;
1540 std::optional<std::any> m_vendorControlRequest;
1541
1542 // Followers
1543 std::vector<std::pair<std::any, bool>> m_followers;
1544 std::vector<SmartMotorController*> m_looseFollowers;
1545};
1546
1547} // namespace yams::motorcontrollers
Definition MechanismGearing.hpp:19
Definition ADRCConfig.hpp:82
Definition LQRConfig.hpp:28
std::optional< wpi::units::turn_t > GetWrappingMin() const
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::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
SmartMotorControllerConfig & WithWheelMOI(wpi::units::meter_t diameter, wpi::units::kilogram_t mass)
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()
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:73
@ MEDIUM
Definition SmartMotorControllerConfig.hpp:73
SmartMotorControllerConfig & WithWrapping(wpi::units::turn_t min, wpi::units::turn_t max)
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:69
@ OPEN_LOOP
Definition SmartMotorControllerConfig.hpp:69
@ CLOSED_LOOP
Definition SmartMotorControllerConfig.hpp:69
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
std::optional< wpi::units::turn_t > GetWrappingMax() 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 & 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:75
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::shared_ptr< math::ADRCConfig > GetADRCController(ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0) 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 & WithoutADRCController(ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
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)
MotorMode
Definition SmartMotorControllerConfig.hpp:71
@ BRAKE
Definition SmartMotorControllerConfig.hpp:71
@ COAST
Definition SmartMotorControllerConfig.hpp:71
std::optional< double > GetExponentialProfileKA() const
std::optional< double > GetExponentialProfileKV() const
SmartMotorControllerConfig & WithExternalEncoderZeroOffset(wpi::units::meter_t zeroOffset)
SmartMotorControllerConfig & WithADRCController(const math::ADRCConfig &adrcConfig, ClosedLoopControllerSlot slot=ClosedLoopControllerSlot::SLOT_0)
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 SmartMotorController.hpp:49
Definition SmartMotorControllerTelemetryConfig.hpp:63
Definition GearBox.hpp:11
Definition ADRCConfig.hpp:20
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:872
Definition SmartMotorControllerConfig.hpp:1020
double kP
Definition SmartMotorControllerConfig.hpp:1021
double kD
Definition SmartMotorControllerConfig.hpp:1021
double kS
Definition SmartMotorControllerConfig.hpp:1022
std::optional< wpi::math::ElevatorFeedforward > elevatorFF
Definition SmartMotorControllerConfig.hpp:1024
double kV
Definition SmartMotorControllerConfig.hpp:1022
std::optional< math::LQRConfig > lqr
Definition SmartMotorControllerConfig.hpp:1026
std::optional< wpi::math::ArmFeedforward > armFF
Definition SmartMotorControllerConfig.hpp:1023
double kI
Definition SmartMotorControllerConfig.hpp:1021
std::optional< wpi::math::SimpleMotorFeedforward< wpi::units::turns > > simpleFF
Definition SmartMotorControllerConfig.hpp:1025
double kG
Definition SmartMotorControllerConfig.hpp:1022
double kA
Definition SmartMotorControllerConfig.hpp:1022