13#include "wpi/units/acceleration.hpp"
14#include "wpi/units/angular_acceleration.hpp"
15#include "wpi/units/angular_velocity.hpp"
16#include "wpi/units/length.hpp"
17#include "wpi/units/moment_of_inertia.hpp"
18#include "wpi/units/velocity.hpp"
19#include "wpi/units/voltage.hpp"
28 template <
typename Distance>
29 using Velocity_t = wpi::units::unit_t<wpi::units::compound_unit<
30 Distance, wpi::units::inverse<wpi::units::seconds>>>;
32 template <
typename Distance>
34 wpi::units::compound_unit<Distance,
35 wpi::units::inverse<wpi::units::seconds>>,
36 wpi::units::inverse<wpi::units::seconds>>>;
51 DCMotor motor, wpi::units::kilogram_square_meter_t J,
double gearing) {
53 throw std::domain_error(
"J must be greater than zero.");
56 throw std::domain_error(
"gearing must be greater than zero.");
83 decltype(1_V / 1_rad_per_s) kV,
decltype(1_V / 1_rad_per_s_sq) kA) {
84 if (kV <
decltype(kV){0}) {
85 throw std::domain_error(
"Kv must be greater than or equal to zero.");
87 if (kA <=
decltype(kA){0}) {
88 throw std::domain_error(
"Ka must be greater than zero.");
113 DCMotor motor, wpi::units::kilogram_t mass, wpi::units::meter_t radius,
116 throw std::domain_error(
"mass must be greater than zero.");
119 throw std::domain_error(
"radius must be greater than zero.");
121 if (gearing <= 0.0) {
122 throw std::domain_error(
"gearing must be greater than zero.");
128 (motor.
R * wpi::units::math::pow<2>(radius) * mass * motor.
Kv))
131 {(gearing * motor.
Kt / (motor.
R * radius * mass)).value()}};
153 decltype(1_V / 1_mps) kV,
decltype(1_V / 1_mps_sq) kA) {
154 if (kV <
decltype(kV){0}) {
155 throw std::domain_error(
"Kv must be greater than or equal to zero.");
157 if (kA <=
decltype(kA){0}) {
158 throw std::domain_error(
"Ka must be greater than zero.");
161 Matrixd<2, 2> A{{0.0, 1.0}, {0.0, -kV.value() / kA.value()}};
182 DCMotor motor, wpi::units::kilogram_square_meter_t J,
double gearing) {
183 if (J <= 0_kg_sq_m) {
184 throw std::domain_error(
"J must be greater than zero.");
186 if (gearing <= 0.0) {
187 throw std::domain_error(
"gearing must be greater than zero.");
192 {0.0, (-
gcem::pow(gearing, 2) * motor.
Kt / (motor.
Kv * motor.
R * J))
216 decltype(1_V / 1_rad_per_s) kV,
decltype(1_V / 1_rad_per_s_sq) kA) {
217 if (kV <
decltype(kV){0}) {
218 throw std::domain_error(
"Kv must be greater than or equal to zero.");
220 if (kA <=
decltype(kA){0}) {
221 throw std::domain_error(
"Ka must be greater than zero.");
224 Matrixd<2, 2> A{{0.0, 1.0}, {0.0, -kV.value() / kA.value()}};
250 const DCMotor& motor, wpi::units::kilogram_t mass, wpi::units::meter_t r,
251 wpi::units::meter_t rb, wpi::units::kilogram_square_meter_t J,
254 throw std::domain_error(
"mass must be greater than zero.");
257 throw std::domain_error(
"r must be greater than zero.");
260 throw std::domain_error(
"rb must be greater than zero.");
262 if (J <= 0_kg_sq_m) {
263 throw std::domain_error(
"J must be greater than zero.");
265 if (gearing <= 0.0) {
266 throw std::domain_error(
"gearing must be greater than zero.");
270 (motor.
Kv * motor.
R * wpi::units::math::pow<2>(r));
271 auto C2 = gearing * motor.
Kt / (motor.
R * r);
274 {((1 / mass + wpi::units::math::pow<2>(rb) / J) * C1).value(),
275 ((1 / mass - wpi::units::math::pow<2>(rb) / J) * C1).value()},
276 {((1 / mass - wpi::units::math::pow<2>(rb) / J) * C1).value(),
277 ((1 / mass + wpi::units::math::pow<2>(rb) / J) * C1).value()}};
279 {((1 / mass + wpi::units::math::pow<2>(rb) / J) * C2).value(),
280 ((1 / mass - wpi::units::math::pow<2>(rb) / J) * C2).value()},
281 {((1 / mass - wpi::units::math::pow<2>(rb) / J) * C2).value(),
282 ((1 / mass + wpi::units::math::pow<2>(rb) / J) * C2).value()}};
311 decltype(1_V / 1_mps) kVLinear,
decltype(1_V / 1_mps_sq) kALinear,
312 decltype(1_V / 1_mps) kVAngular,
decltype(1_V / 1_mps_sq) kAAngular) {
313 if (kVLinear <=
decltype(kVLinear){0}) {
314 throw std::domain_error(
"Kv,linear must be greater than zero.");
316 if (kALinear <=
decltype(kALinear){0}) {
317 throw std::domain_error(
"Ka,linear must be greater than zero.");
319 if (kVAngular <=
decltype(kVAngular){0}) {
320 throw std::domain_error(
"Kv,angular must be greater than zero.");
322 if (kAAngular <=
decltype(kAAngular){0}) {
323 throw std::domain_error(
"Ka,angular must be greater than zero.");
326 double A1 = -0.5 * (kVLinear.value() / kALinear.value() +
327 kVAngular.value() / kAAngular.value());
328 double A2 = -0.5 * (kVLinear.value() / kALinear.value() -
329 kVAngular.value() / kAAngular.value());
330 double B1 = 0.5 / kALinear.value() + 0.5 / kAAngular.value();
331 double B2 = 0.5 / kALinear.value() - 0.5 / kAAngular.value();
366 decltype(1_V / 1_mps) kVLinear,
decltype(1_V / 1_mps_sq) kALinear,
367 decltype(1_V / 1_rad_per_s) kVAngular,
368 decltype(1_V / 1_rad_per_s_sq) kAAngular,
369 wpi::units::meter_t trackwidth) {
370 if (kVLinear <=
decltype(kVLinear){0}) {
371 throw std::domain_error(
"Kv,linear must be greater than zero.");
373 if (kALinear <=
decltype(kALinear){0}) {
374 throw std::domain_error(
"Ka,linear must be greater than zero.");
376 if (kVAngular <=
decltype(kVAngular){0}) {
377 throw std::domain_error(
"Kv,angular must be greater than zero.");
379 if (kAAngular <=
decltype(kAAngular){0}) {
380 throw std::domain_error(
"Ka,angular must be greater than zero.");
382 if (trackwidth <= 0_m) {
383 throw std::domain_error(
"r must be greater than zero.");
398 kVAngular * 2.0 / trackwidth * 1_rad,
399 kAAngular * 2.0 / trackwidth * 1_rad);
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
Holds the constants for a DC motor.
Definition DCMotor.hpp:19
radians_per_second_per_volt_t Kv
Motor velocity constant.
Definition DCMotor.hpp:47
newton_meters_per_ampere_t Kt
Motor torque constant.
Definition DCMotor.hpp:50
wpi::units::ohm_t R
Motor internal resistance.
Definition DCMotor.hpp:44
A plant defined using state-space notation.
Definition LinearSystem.hpp:35
Linear system factories.
Definition Models.hpp:26
wpi::units::unit_t< wpi::units::compound_unit< Distance, wpi::units::inverse< wpi::units::seconds > > > Velocity_t
Definition Models.hpp:29
static constexpr LinearSystem< 2, 2, 2 > DifferentialDriveFromSysId(decltype(1_V/1_mps) kVLinear, decltype(1_V/1_mps_sq) kALinear, decltype(1_V/1_rad_per_s) kVAngular, decltype(1_V/1_rad_per_s_sq) kAAngular, wpi::units::meter_t trackwidth)
Creates a differential drive state-space model from SysId constants kᵥ and kₐ in both linear {(V/(m/s...
Definition Models.hpp:365
wpi::units::unit_t< wpi::units::compound_unit< wpi::units::compound_unit< Distance, wpi::units::inverse< wpi::units::seconds > >, wpi::units::inverse< wpi::units::seconds > > > Acceleration_t
Definition Models.hpp:33
static constexpr LinearSystem< 2, 2, 2 > DifferentialDriveFromPhysicalConstants(const DCMotor &motor, wpi::units::kilogram_t mass, wpi::units::meter_t r, wpi::units::meter_t rb, wpi::units::kilogram_square_meter_t J, double gearing)
Creates a differential drive state-space model from physical constants.
Definition Models.hpp:249
static constexpr LinearSystem< 2, 1, 2 > ElevatorFromPhysicalConstants(DCMotor motor, wpi::units::kilogram_t mass, wpi::units::meter_t radius, double gearing)
Creates an elevator state-space model from physical constants.
Definition Models.hpp:112
static constexpr LinearSystem< 2, 2, 2 > DifferentialDriveFromSysId(decltype(1_V/1_mps) kVLinear, decltype(1_V/1_mps_sq) kALinear, decltype(1_V/1_mps) kVAngular, decltype(1_V/1_mps_sq) kAAngular)
Creates a differential drive state-space model from SysId constants kᵥ and kₐ in both linear {(V/(m/s...
Definition Models.hpp:310
static constexpr LinearSystem< 2, 1, 2 > SingleJointedArmFromSysId(decltype(1_V/1_rad_per_s) kV, decltype(1_V/1_rad_per_s_sq) kA)
Creates a single-jointed arm state-space model from SysId constants kᵥ (V/(rad/s)) and kₐ (V/(rad/s²)...
Definition Models.hpp:215
static constexpr LinearSystem< 1, 1, 1 > FlywheelFromPhysicalConstants(DCMotor motor, wpi::units::kilogram_square_meter_t J, double gearing)
Creates a flywheel state-space model from physical constants.
Definition Models.hpp:50
static constexpr LinearSystem< 2, 1, 2 > SingleJointedArmFromPhysicalConstants(DCMotor motor, wpi::units::kilogram_square_meter_t J, double gearing)
Create a single-jointed arm state-space model from physical constants.
Definition Models.hpp:181
static constexpr LinearSystem< 2, 1, 2 > ElevatorFromSysId(decltype(1_V/1_mps) kV, decltype(1_V/1_mps_sq) kA)
Creates an elevator state-space model from SysId constants kᵥ (V/(m/s)) and kₐ (V/(m/s²)) from the fe...
Definition Models.hpp:152
static constexpr LinearSystem< 1, 1, 1 > FlywheelFromSysId(decltype(1_V/1_rad_per_s) kV, decltype(1_V/1_rad_per_s_sq) kA)
Creates a flywheel state-space model from SysId constants kᵥ (V/(rad/s)) and kₐ (V/(rad/s²)) from the...
Definition Models.hpp:82
constexpr common_t< T1, T2 > pow(const T1 base, const T2 exp_term) noexcept
Compile-time power function.
Definition pow.hpp:82
Definition LinearSystem.hpp:20
Eigen::Matrix< double, Rows, Cols, Options, MaxRows, MaxCols > Matrixd
Definition EigenCore.hpp:21