Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix oscillating velocity for differential drive #1052

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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