Skip to content

Commit 2def62a

Browse files
authored
[wpimath] Document ChassisSpeeds::Discretize() math (NFC) (wpilibsuite#6509)
1 parent 3a5d24a commit 2def62a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,19 @@ public static ChassisSpeeds discretize(
9999
double vyMetersPerSecond,
100100
double omegaRadiansPerSecond,
101101
double dtSeconds) {
102+
// Construct the desired pose after a timestep, relative to the current pose. The desired pose
103+
// has decoupled translation and rotation.
102104
var desiredDeltaPose =
103105
new Pose2d(
104106
vxMetersPerSecond * dtSeconds,
105107
vyMetersPerSecond * dtSeconds,
106108
new Rotation2d(omegaRadiansPerSecond * dtSeconds));
109+
110+
// Find the chassis translation/rotation deltas in the robot frame that move the robot from its
111+
// current pose to the desired pose
107112
var twist = new Pose2d().log(desiredDeltaPose);
113+
114+
// Turn the chassis translation/rotation deltas into average velocities
108115
return new ChassisSpeeds(twist.dx / dtSeconds, twist.dy / dtSeconds, twist.dtheta / dtSeconds);
109116
}
110117

wpimath/src/main/native/include/frc/kinematics/ChassisSpeeds.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,15 @@ struct WPILIB_DLLEXPORT ChassisSpeeds {
6161
units::meters_per_second_t vy,
6262
units::radians_per_second_t omega,
6363
units::second_t dt) {
64+
// Construct the desired pose after a timestep, relative to the current
65+
// pose. The desired pose has decoupled translation and rotation.
6466
Pose2d desiredDeltaPose{vx * dt, vy * dt, omega * dt};
67+
68+
// Find the chassis translation/rotation deltas in the robot frame that move
69+
// the robot from its current pose to the desired pose
6570
auto twist = Pose2d{}.Log(desiredDeltaPose);
71+
72+
// Turn the chassis translation/rotation deltas into average velocities
6673
return {twist.dx / dt, twist.dy / dt, twist.dtheta / dt};
6774
}
6875

0 commit comments

Comments
 (0)