Skip to content

Commit

Permalink
[wpimath] Fix LinearSystemId return type and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jan 13, 2025
1 parent c5f7a2b commit 43b69e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private LinearSystemId() {

/**
* Create a state-space model of an elevator system. The states of the system are [position,
* velocity]ᵀ, inputs are [voltage], and outputs are [position].
* velocity]ᵀ, inputs are [voltage], and outputs are [position, velocity]ᵀ.
*
* @param motor The motor (or gearbox) attached to the carriage.
* @param massKg The mass of the elevator carriage, in kilograms.
Expand Down Expand Up @@ -88,8 +88,8 @@ public static LinearSystem<N1, N1, N1> createFlywheelSystem(

/**
* Create a state-space model of a DC motor system. The states of the system are [angular
* position, angular velocity], inputs are [voltage], and outputs are [angular position, angular
* velocity].
* position, angular velocity], inputs are [voltage], and outputs are [angular position, angular
* velocity].
*
* @param motor The motor (or gearbox) attached to system.
* @param JKgMetersSquared The moment of inertia J of the DC motor.
Expand Down Expand Up @@ -125,7 +125,7 @@ public static LinearSystem<N2, N1, N2> createDCMotorSystem(
/**
* Create a state-space model of a DC motor system from its kV (volts/(unit/sec)) and kA
* (volts/(unit/sec²)). These constants can be found using SysId. the states of the system are
* [position, velocity], inputs are [voltage], and outputs are [position].
* [position, velocity], inputs are [voltage], and outputs are [position].
*
* <p>The distance unit you choose MUST be an SI unit (i.e. meters or radians). You can use the
* {@link edu.wpi.first.math.util.Units} class for converting between unit types.
Expand Down Expand Up @@ -211,7 +211,7 @@ public static LinearSystem<N2, N2, N2> createDrivetrainVelocitySystem(

/**
* Create a state-space model of a single jointed arm system. The states of the system are [angle,
* angular velocity], inputs are [voltage], and outputs are [angle].
* angular velocity], inputs are [voltage], and outputs are [angle, angular velocity]ᵀ.
*
* @param motor The motor (or gearbox) attached to the arm.
* @param JKgSquaredMeters The moment of inertia J of the arm.
Expand Down Expand Up @@ -279,7 +279,7 @@ public static LinearSystem<N1, N1, N1> identifyVelocitySystem(double kV, double
/**
* Create a state-space model for a 1 DOF position system from its kV (volts/(unit/sec)) and kA
* (volts/(unit/sec²). These constants cam be found using SysId. The states of the system are
* [position, velocity]ᵀ, inputs are [voltage], and outputs are [position].
* [position, velocity]ᵀ, inputs are [voltage], and outputs are [position, velocity]ᵀ.
*
* <p>The distance unit you choose MUST be an SI unit (i.e. meters or radians). You can use the
* {@link edu.wpi.first.math.util.Units} class for converting between unit types.
Expand Down
34 changes: 18 additions & 16 deletions wpimath/src/main/native/include/frc/system/plant/LinearSystemId.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class WPILIB_DLLEXPORT LinearSystemId {

/**
* Create a state-space model of the elevator system. The states of the system
* are [position, velocity], inputs are [voltage], and outputs are [position].
* are [position, velocity]ᵀ, inputs are [voltage], and outputs are [position,
* velocity]ᵀ.
*
* @param motor The motor (or gearbox) attached to the carriage.
* @param mass The mass of the elevator carriage, in kilograms.
Expand Down Expand Up @@ -74,8 +75,8 @@ class WPILIB_DLLEXPORT LinearSystemId {

/**
* Create a state-space model of a single-jointed arm system.The states of the
* system are [angle, angular velocity], inputs are [voltage], and outputs are
* [angle].
* system are [angle, angular velocity], inputs are [voltage], and outputs
* are [angle, angular velocity]ᵀ.
*
* @param motor The motor (or gearbox) attached to the arm.
* @param J The moment of inertia J of the arm.
Expand Down Expand Up @@ -147,8 +148,8 @@ class WPILIB_DLLEXPORT LinearSystemId {
/**
* Create a state-space model for a 1 DOF position system from its kV
* (volts/(unit/sec)) and kA (volts/(unit/sec²)). These constants can be
* found using SysId. the states of the system are [position, velocity],
* inputs are [voltage], and outputs are [position].
* found using SysId. the states of the system are [position, velocity],
* inputs are [voltage], and outputs are [position, velocity]ᵀ.
*
* You MUST use an SI unit (i.e. meters or radians) for the Distance template
* argument. You may still use non-SI units (such as feet or inches) for the
Expand All @@ -169,7 +170,7 @@ class WPILIB_DLLEXPORT LinearSystemId {
template <typename Distance>
requires std::same_as<units::meter, Distance> ||
std::same_as<units::radian, Distance>
static constexpr LinearSystem<2, 1, 1> IdentifyPositionSystem(
static constexpr LinearSystem<2, 1, 2> IdentifyPositionSystem(
decltype(1_V / Velocity_t<Distance>(1)) kV,
decltype(1_V / Acceleration_t<Distance>(1)) kA) {
if (kV < decltype(kV){0}) {
Expand All @@ -180,11 +181,11 @@ class WPILIB_DLLEXPORT LinearSystemId {
}

Matrixd<2, 2> A{{0.0, 1.0}, {0.0, -kV.value() / kA.value()}};
Matrixd<2, 1> B{0.0, 1.0 / kA.value()};
Matrixd<1, 2> C{1.0, 0.0};
Matrixd<1, 1> D{0.0};
Matrixd<2, 1> B{{0.0}, {1.0 / kA.value()}};
Matrixd<2, 2> C{{1.0, 0.0}, {0.0, 1.0}};
Matrixd<2, 1> D{{0.0}, {0.0}};

return LinearSystem<2, 1, 1>(A, B, C, D);
return LinearSystem<2, 1, 2>(A, B, C, D);
}

/**
Expand Down Expand Up @@ -337,8 +338,8 @@ class WPILIB_DLLEXPORT LinearSystemId {

/**
* Create a state-space model of a DC motor system. The states of the system
* are [angular position, angular velocity], inputs are [voltage], and outputs
* are [angular position, angular velocity].
* are [angular position, angular velocity], inputs are [voltage], and outputs
* are [angular position, angular velocity].
*
* @param motor The motor (or gearbox) attached to the system.
* @param J the moment of inertia J of the DC motor.
Expand Down Expand Up @@ -370,8 +371,9 @@ class WPILIB_DLLEXPORT LinearSystemId {
/**
* Create a state-space model of a DC motor system from its kV
* (volts/(unit/sec)) and kA (volts/(unit/sec²)). These constants can be
* found using SysId. the states of the system are [position, velocity],
* inputs are [voltage], and outputs are [position].
* found using SysId. the states of the system are [angular position, angular
* velocity]ᵀ, inputs are [voltage], and outputs are [angular position,
* angular velocity]ᵀ.
*
* You MUST use an SI unit (i.e. meters or radians) for the Distance template
* argument. You may still use non-SI units (such as feet or inches) for the
Expand Down Expand Up @@ -410,9 +412,9 @@ class WPILIB_DLLEXPORT LinearSystemId {

/**
* Create a state-space model of differential drive drivetrain. In this model,
* the states are [left velocity, right velocity], the inputs are [left
* the states are [left velocity, right velocity], the inputs are [left
* voltage, right voltage], and the outputs are [left velocity, right
* velocity]
* velocity]ᵀ.
*
* @param motor The motor (or gearbox) driving the drivetrain.
* @param mass The mass of the robot in kilograms.
Expand Down

0 comments on commit 43b69e1

Please sign in to comment.