29 template <
typename Distance>
33 template <
typename Distance>
50 units::kilogram_t mass,
51 units::meter_t radius,
54 throw std::domain_error(
"mass must be greater than zero.");
57 throw std::domain_error(
"radius must be greater than zero.");
60 throw std::domain_error(
"gearing must be greater than zero.");
69 {(gearing * motor.
Kt / (motor.
R * radius * mass)).value()}};
87 DCMotor motor, units::kilogram_square_meter_t J,
double gearing) {
89 throw std::domain_error(
"J must be greater than zero.");
92 throw std::domain_error(
"gearing must be greater than zero.");
97 {0.0, (-
gcem::pow(gearing, 2) * motor.
Kt / (motor.
Kv * motor.
R * J))
127 template <
typename Distance>
128 requires std::same_as<units::meter, Distance> ||
129 std::same_as<units::radian, Distance>
133 if (kV <
decltype(kV){0}) {
134 throw std::domain_error(
"Kv must be greater than or equal to zero.");
136 if (kA <=
decltype(kA){0}) {
137 throw std::domain_error(
"Ka must be greater than zero.");
170 template <
typename Distance>
171 requires std::same_as<units::meter, Distance> ||
172 std::same_as<units::radian, Distance>
176 if (kV <
decltype(kV){0}) {
177 throw std::domain_error(
"Kv must be greater than or equal to zero.");
179 if (kA <=
decltype(kA){0}) {
180 throw std::domain_error(
"Ka must be greater than zero.");
183 Matrixd<2, 2> A{{0.0, 1.0}, {0.0, -kV.value() / kA.value()}};
214 decltype(1_V / 1_mps) kVLinear,
decltype(1_V / 1_mps_sq) kALinear,
215 decltype(1_V / 1_mps) kVAngular,
decltype(1_V / 1_mps_sq) kAAngular) {
216 if (kVLinear <=
decltype(kVLinear){0}) {
217 throw std::domain_error(
"Kv,linear must be greater than zero.");
219 if (kALinear <=
decltype(kALinear){0}) {
220 throw std::domain_error(
"Ka,linear must be greater than zero.");
222 if (kVAngular <=
decltype(kVAngular){0}) {
223 throw std::domain_error(
"Kv,angular must be greater than zero.");
225 if (kAAngular <=
decltype(kAAngular){0}) {
226 throw std::domain_error(
"Ka,angular must be greater than zero.");
229 double A1 = -(kVLinear.value() / kALinear.value() +
230 kVAngular.value() / kAAngular.value());
231 double A2 = -(kVLinear.value() / kALinear.value() -
232 kVAngular.value() / kAAngular.value());
233 double B1 = 1.0 / kALinear.value() + 1.0 / kAAngular.value();
234 double B2 = 1.0 / kALinear.value() - 1.0 / kAAngular.value();
275 decltype(1_V / 1_mps) kVLinear,
decltype(1_V / 1_mps_sq) kALinear,
276 decltype(1_V / 1_rad_per_s) kVAngular,
277 decltype(1_V / 1_rad_per_s_sq) kAAngular, units::meter_t trackwidth) {
278 if (kVLinear <=
decltype(kVLinear){0}) {
279 throw std::domain_error(
"Kv,linear must be greater than zero.");
281 if (kALinear <=
decltype(kALinear){0}) {
282 throw std::domain_error(
"Ka,linear must be greater than zero.");
284 if (kVAngular <=
decltype(kVAngular){0}) {
285 throw std::domain_error(
"Kv,angular must be greater than zero.");
287 if (kAAngular <=
decltype(kAAngular){0}) {
288 throw std::domain_error(
"Ka,angular must be greater than zero.");
290 if (trackwidth <= 0_m) {
291 throw std::domain_error(
"r must be greater than zero.");
305 return IdentifyDrivetrainSystem(kVLinear, kALinear,
306 kVAngular * 2.0 / trackwidth * 1_rad,
307 kAAngular * 2.0 / trackwidth * 1_rad);
321 DCMotor motor, units::kilogram_square_meter_t J,
double gearing) {
322 if (J <= 0_kg_sq_m) {
323 throw std::domain_error(
"J must be greater than zero.");
325 if (gearing <= 0.0) {
326 throw std::domain_error(
"gearing must be greater than zero.");
352 DCMotor motor, units::kilogram_square_meter_t J,
double gearing) {
353 if (J <= 0_kg_sq_m) {
354 throw std::domain_error(
"J must be greater than zero.");
356 if (gearing <= 0.0) {
357 throw std::domain_error(
"gearing must be greater than zero.");
362 {0.0, (-
gcem::pow(gearing, 2) * motor.
Kt / (motor.
Kv * motor.
R * J))
392 template <
typename Distance>
393 requires std::same_as<units::meter, Distance> ||
394 std::same_as<units::radian, Distance>
398 if (kV <
decltype(kV){0}) {
399 throw std::domain_error(
"Kv must be greater than or equal to zero.");
401 if (kA <=
decltype(kA){0}) {
402 throw std::domain_error(
"Ka must be greater than zero.");
405 Matrixd<2, 2> A{{0.0, 1.0}, {0.0, -kV.value() / kA.value()}};
429 const DCMotor& motor, units::kilogram_t mass, units::meter_t r,
430 units::meter_t rb, units::kilogram_square_meter_t J,
double gearing) {
432 throw std::domain_error(
"mass must be greater than zero.");
435 throw std::domain_error(
"r must be greater than zero.");
438 throw std::domain_error(
"rb must be greater than zero.");
440 if (J <= 0_kg_sq_m) {
441 throw std::domain_error(
"J must be greater than zero.");
443 if (gearing <= 0.0) {
444 throw std::domain_error(
"gearing must be greater than zero.");
449 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:395
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:86
static constexpr LinearSystem< 2, 1, 2 > 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:173
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:49
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:320
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:428
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:213
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:130
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:351
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:274
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