29 template <
typename Distance>
33 template <
typename Distance>
49 units::kilogram_t mass,
50 units::meter_t radius,
53 throw std::domain_error(
"mass must be greater than zero.");
56 throw std::domain_error(
"radius must be greater than zero.");
59 throw std::domain_error(
"gearing must be greater than zero.");
68 {(gearing * motor.
Kt / (motor.
R * radius * mass)).value()}};
86 DCMotor motor, units::kilogram_square_meter_t J,
double gearing) {
88 throw std::domain_error(
"J must be greater than zero.");
91 throw std::domain_error(
"gearing must be greater than zero.");
96 {0.0, (-
gcem::pow(gearing, 2) * motor.
Kt / (motor.
Kv * motor.
R * J))
126 template <
typename Distance>
127 requires std::same_as<units::meter, Distance> ||
128 std::same_as<units::radian, Distance>
132 if (kV <
decltype(kV){0}) {
133 throw std::domain_error(
"Kv must be greater than or equal to zero.");
135 if (kA <=
decltype(kA){0}) {
136 throw std::domain_error(
"Ka must be greater than zero.");
169 template <
typename Distance>
170 requires std::same_as<units::meter, Distance> ||
171 std::same_as<units::radian, Distance>
175 if (kV <
decltype(kV){0}) {
176 throw std::domain_error(
"Kv must be greater than or equal to zero.");
178 if (kA <=
decltype(kA){0}) {
179 throw std::domain_error(
"Ka must be greater than zero.");
182 Matrixd<2, 2> A{{0.0, 1.0}, {0.0, -kV.value() / kA.value()}};
213 decltype(1_V / 1_mps) kVLinear,
decltype(1_V / 1_mps_sq) kALinear,
214 decltype(1_V / 1_mps) kVAngular,
decltype(1_V / 1_mps_sq) kAAngular) {
215 if (kVLinear <=
decltype(kVLinear){0}) {
216 throw std::domain_error(
"Kv,linear must be greater than zero.");
218 if (kALinear <=
decltype(kALinear){0}) {
219 throw std::domain_error(
"Ka,linear must be greater than zero.");
221 if (kVAngular <=
decltype(kVAngular){0}) {
222 throw std::domain_error(
"Kv,angular must be greater than zero.");
224 if (kAAngular <=
decltype(kAAngular){0}) {
225 throw std::domain_error(
"Ka,angular must be greater than zero.");
228 double A1 = -(kVLinear.value() / kALinear.value() +
229 kVAngular.value() / kAAngular.value());
230 double A2 = -(kVLinear.value() / kALinear.value() -
231 kVAngular.value() / kAAngular.value());
232 double B1 = 1.0 / kALinear.value() + 1.0 / kAAngular.value();
233 double B2 = 1.0 / kALinear.value() - 1.0 / kAAngular.value();
274 decltype(1_V / 1_mps) kVLinear,
decltype(1_V / 1_mps_sq) kALinear,
275 decltype(1_V / 1_rad_per_s) kVAngular,
276 decltype(1_V / 1_rad_per_s_sq) kAAngular, units::meter_t trackwidth) {
277 if (kVLinear <=
decltype(kVLinear){0}) {
278 throw std::domain_error(
"Kv,linear must be greater than zero.");
280 if (kALinear <=
decltype(kALinear){0}) {
281 throw std::domain_error(
"Ka,linear must be greater than zero.");
283 if (kVAngular <=
decltype(kVAngular){0}) {
284 throw std::domain_error(
"Kv,angular must be greater than zero.");
286 if (kAAngular <=
decltype(kAAngular){0}) {
287 throw std::domain_error(
"Ka,angular must be greater than zero.");
289 if (trackwidth <= 0_m) {
290 throw std::domain_error(
"r must be greater than zero.");
304 return IdentifyDrivetrainSystem(kVLinear, kALinear,
305 kVAngular * 2.0 / trackwidth * 1_rad,
306 kAAngular * 2.0 / trackwidth * 1_rad);
320 DCMotor motor, units::kilogram_square_meter_t J,
double gearing) {
321 if (J <= 0_kg_sq_m) {
322 throw std::domain_error(
"J must be greater than zero.");
324 if (gearing <= 0.0) {
325 throw std::domain_error(
"gearing must be greater than zero.");
351 DCMotor motor, units::kilogram_square_meter_t J,
double gearing) {
352 if (J <= 0_kg_sq_m) {
353 throw std::domain_error(
"J must be greater than zero.");
355 if (gearing <= 0.0) {
356 throw std::domain_error(
"gearing must be greater than zero.");
361 {0.0, (-
gcem::pow(gearing, 2) * motor.
Kt / (motor.
Kv * motor.
R * J))
390 template <
typename Distance>
391 requires std::same_as<units::meter, Distance> ||
392 std::same_as<units::radian, Distance>
396 if (kV <
decltype(kV){0}) {
397 throw std::domain_error(
"Kv must be greater than or equal to zero.");
399 if (kA <=
decltype(kA){0}) {
400 throw std::domain_error(
"Ka must be greater than zero.");
403 Matrixd<2, 2> A{{0.0, 1.0}, {0.0, -kV.value() / kA.value()}};
427 const DCMotor& motor, units::kilogram_t mass, units::meter_t r,
428 units::meter_t rb, units::kilogram_square_meter_t J,
double gearing) {
430 throw std::domain_error(
"mass must be greater than zero.");
433 throw std::domain_error(
"r must be greater than zero.");
436 throw std::domain_error(
"rb must be greater than zero.");
438 if (J <= 0_kg_sq_m) {
439 throw std::domain_error(
"J must be greater than zero.");
441 if (gearing <= 0.0) {
442 throw std::domain_error(
"gearing must be greater than zero.");
447 auto C2 = gearing * motor.
Kt / (motor.
R * r);
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Holds the constants for a DC motor.
Definition DCMotor.h:20
radians_per_second_per_volt_t Kv
Motor velocity constant.
Definition DCMotor.h:48
units::ohm_t R
Motor internal resistance.
Definition DCMotor.h:45
newton_meters_per_ampere_t Kt
Motor torque constant.
Definition DCMotor.h:51
A plant defined using state-space notation.
Definition LinearSystem.h:35
Linear system ID utility functions.
Definition LinearSystemId.h:27
static constexpr LinearSystem< 2, 1, 2 > DCMotorSystem(decltype(1_V/Velocity_t< Distance >(1)) kV, decltype(1_V/Acceleration_t< Distance >(1)) kA)
Create a state-space model of a DC motor system from its kV (volts/(unit/sec)) and kA (volts/(unit/se...
Definition LinearSystemId.h:393
static constexpr LinearSystem< 2, 1, 2 > SingleJointedArmSystem(DCMotor motor, units::kilogram_square_meter_t J, double gearing)
Create a state-space model of a single-jointed arm system.The states of the system are [angle,...
Definition LinearSystemId.h:85
static constexpr LinearSystem< 2, 1, 2 > ElevatorSystem(DCMotor motor, units::kilogram_t mass, units::meter_t radius, double gearing)
Create a state-space model of the elevator system.
Definition LinearSystemId.h:48
static constexpr LinearSystem< 2, 1, 1 > IdentifyPositionSystem(decltype(1_V/Velocity_t< Distance >(1)) kV, decltype(1_V/Acceleration_t< Distance >(1)) kA)
Create a state-space model for a 1 DOF position system from its kV (volts/(unit/sec)) and kA (volts/(...
Definition LinearSystemId.h:172
static constexpr LinearSystem< 1, 1, 1 > FlywheelSystem(DCMotor motor, units::kilogram_square_meter_t J, double gearing)
Create a state-space model of a flywheel system, the states of the system are [angular velocity],...
Definition LinearSystemId.h:319
static constexpr LinearSystem< 2, 2, 2 > DrivetrainVelocitySystem(const DCMotor &motor, units::kilogram_t mass, units::meter_t r, units::meter_t rb, units::kilogram_square_meter_t J, double gearing)
Create a state-space model of differential drive drivetrain.
Definition LinearSystemId.h:426
static constexpr LinearSystem< 2, 2, 2 > IdentifyDrivetrainSystem(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)
Identify a differential drive drivetrain given the drivetrain's kV and kA in both linear {(volts/(met...
Definition LinearSystemId.h:212
static constexpr LinearSystem< 1, 1, 1 > IdentifyVelocitySystem(decltype(1_V/Velocity_t< Distance >(1)) kV, decltype(1_V/Acceleration_t< Distance >(1)) kA)
Create a state-space model for a 1 DOF velocity system from its kV (volts/(unit/sec)) and kA (volts/(...
Definition LinearSystemId.h:129
static constexpr LinearSystem< 2, 1, 2 > DCMotorSystem(DCMotor motor, units::kilogram_square_meter_t J, double gearing)
Create a state-space model of a DC motor system.
Definition LinearSystemId.h:350
static constexpr LinearSystem< 2, 2, 2 > IdentifyDrivetrainSystem(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, units::meter_t trackwidth)
Identify a differential drive drivetrain given the drivetrain's kV and kA in both linear {(volts/(met...
Definition LinearSystemId.h:273
Container for values which represent quantities of a given unit.
Definition base.h:1930
typename units::detail::inverse_impl< U >::type inverse
represents the inverse unit type of class U.
Definition base.h:1138
typename units::detail::compound_impl< U, Us... >::type compound_unit
Represents a unit type made up from other units.
Definition base.h:1438
Eigen::Matrix< double, Rows, Cols, Options, MaxRows, MaxCols > Matrixd
Definition EigenCore.h:21
constexpr common_t< T1, T2 > pow(const T1 base, const T2 exp_term) noexcept
Compile-time power function.
Definition pow.hpp:82
constexpr auto pow(const UnitType &value) noexcept -> unit_t< typename units::detail::power_of_unit< power, typename units::traits::unit_t_traits< UnitType >::unit_type >::type, typename units::traits::unit_t_traits< UnitType >::underlying_type, linear_scale >
computes the value of value raised to the power
Definition base.h:2810