Skip to content

Commit

Permalink
Fix oscillating velocity for differential drive (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
icros-personal authored Feb 6, 2025
1 parent 1027141 commit ce94d1e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/trajectory/trajectory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class PathPlannerTrajectory {
var accelStates =
robotConfig.kinematics.toSwerveModuleStates(chassisAccel);
for (int m = 0; m < numModules; m++) {
num moduleAcceleration = accelStates[m].speedMetersPerSecond;
num moduleAcceleration = accelStates[m].speedMetersPerSecond.abs();

// Calculate the module velocity at the current state
// vf^2 = v0^2 + 2ad
Expand Down Expand Up @@ -371,7 +371,7 @@ class PathPlannerTrajectory {

// Use the robot accelerations to calculate how each module should decelerate
for (int m = 0; m < numModules; m++) {
num moduleAcceleration = accelStates[m].speedMetersPerSecond;
num moduleAcceleration = accelStates[m].speedMetersPerSecond.abs();

// Calculate the module velocity at the current state
// vf^2 = v0^2 + 2ad
Expand Down
4 changes: 2 additions & 2 deletions pathplannerlib-python/pathplannerlib/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def _forwardAccelPass(states: List[PathPlannerTrajectoryState], config: RobotCon
state.pose.rotation())
accelStates = config.toSwerveModuleStates(chassisAccel)
for m in range(config.numModules):
moduleAcceleration = accelStates[m].speed
moduleAcceleration = abs(accelStates[m].speed)

# Calculate the module velocity at the current state
# vf^2 = v0^2 + 2ad
Expand Down Expand Up @@ -669,7 +669,7 @@ def _reverseAccelPass(states: List[PathPlannerTrajectoryState], config: RobotCon
state.pose.rotation())
accelStates = config.toSwerveModuleStates(chassisAccel)
for m in range(config.numModules):
moduleAcceleration = accelStates[m].speed
moduleAcceleration = abs(accelStates[m].speed)

# Calculate the module velocity at the current state
# vf^2 = v0^2 + 2ad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ private static void forwardAccelPass(
accelVec.getX(), accelVec.getY(), angularAccel, state.pose.getRotation());
var accelStates = config.toSwerveModuleStates(chassisAccel);
for (int m = 0; m < config.numModules; m++) {
double moduleAcceleration = accelStates[m].speedMetersPerSecond;
double moduleAcceleration = Math.abs(accelStates[m].speedMetersPerSecond);

// Calculate the module velocity at the current state
// vf^2 = v0^2 + 2ad
Expand Down Expand Up @@ -527,7 +527,7 @@ private static void reverseAccelPass(
state.pose.getRotation());
var accelStates = config.toSwerveModuleStates(chassisAccel);
for (int m = 0; m < config.numModules; m++) {
double moduleAcceleration = accelStates[m].speedMetersPerSecond;
double moduleAcceleration = Math.abs(accelStates[m].speedMetersPerSecond);

// Calculate the module velocity at the current state
// vf^2 = v0^2 + 2ad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void PathPlannerTrajectory::forwardAccelPass(
auto accelStates = config.toSwerveModuleStates(chassisAccel);
for (size_t m = 0; m < config.numModules; m++) {
units::meters_per_second_squared_t moduleAcceleration {
accelStates[m].speed() };
units::math::abs(accelStates[m].speed)() };

// Calculate the module velocity at the current state
// vf^2 = v0^2 + 2ad
Expand Down Expand Up @@ -580,7 +580,7 @@ void PathPlannerTrajectory::reverseAccelPass(
auto accelStates = config.toSwerveModuleStates(chassisAccel);
for (size_t m = 0; m < config.numModules; m++) {
units::meters_per_second_squared_t moduleAcceleration {
accelStates[m].speed() };
units::math::abs(accelStates[m].speed)() };

// Calculate the module velocity at the current state
// vf^2 = v0^2 + 2ad
Expand Down

0 comments on commit ce94d1e

Please sign in to comment.