-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix oscillating velocity for differential drive
Also attempt to add unit tests to exercise this code, but they are Windows-specific at the moment (needs fix!)
- Loading branch information
1 parent
1027141
commit f1c022e
Showing
3 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
pathplannerlib/src/test/java/com/pathplanner/lib/trajectory/PathPlannerTrajectoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.pathplanner.lib.trajectory; | ||
|
||
import static edu.wpi.first.units.Units.MetersPerSecond; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.pathplanner.lib.config.ModuleConfig; | ||
import com.pathplanner.lib.config.RobotConfig; | ||
import com.pathplanner.lib.path.GoalEndState; | ||
import com.pathplanner.lib.path.IdealStartingState; | ||
import com.pathplanner.lib.path.PathConstraints; | ||
import com.pathplanner.lib.path.PathPlannerPath; | ||
import com.pathplanner.lib.path.Waypoint; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.math.kinematics.ChassisSpeeds; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
|
||
public class PathPlannerTrajectoryTest { | ||
@Test | ||
public void testGenerateTrajectoryHolonomic() { | ||
RobotConfig holonomicConfig = new RobotConfig(74.088, 6.883, | ||
new ModuleConfig(0.048, 5.45, 1.2, DCMotor.getKrakenX60(1).withReduction(5.143), 60, 4), | ||
new Translation2d(0.273, 0.273), | ||
new Translation2d(0.273, -0.273), | ||
new Translation2d(-0.273, 0.273), | ||
new Translation2d(-0.273, -0.273)); | ||
List<Waypoint> waypoints = Arrays.asList( | ||
new Waypoint(null, new Translation2d(), new Translation2d(1.0, 0.0)), | ||
new Waypoint(new Translation2d(5.0, 0.0), new Translation2d(6.0, 0.0), null)); | ||
PathConstraints pathConstraints = new PathConstraints(3.0, 3.0, 540.0, 720.0); | ||
IdealStartingState startingState = new IdealStartingState(MetersPerSecond.zero(), new Rotation2d()); | ||
GoalEndState endState = new GoalEndState(MetersPerSecond.zero(), new Rotation2d()); | ||
PathPlannerPath path = new PathPlannerPath(waypoints, pathConstraints, startingState, endState); | ||
PathPlannerTrajectory trajectory = new PathPlannerTrajectory(path, new ChassisSpeeds(), new Rotation2d(), | ||
holonomicConfig); | ||
List<PathPlannerTrajectoryState> states = trajectory.getStates(); | ||
assertTrue(states.size() > 10); | ||
double lastLV = 0; | ||
for (int i = 0; i < states.size(); i++) { | ||
double linearVelocity = states.get(i).moduleStates[0].speedMetersPerSecond; | ||
assertTrue(linearVelocity <= pathConstraints.maxVelocityMPS()); | ||
if (i > 0) { | ||
if (i < states.size() / 2) { | ||
// Verify that we are more or less monotonically increasing for the first half. | ||
assertTrue(linearVelocity - lastLV >= -0.001); | ||
} else { | ||
// and decreasing for the second half. | ||
assertTrue(linearVelocity - lastLV <= 0.001); | ||
} | ||
} | ||
lastLV = linearVelocity; | ||
} | ||
} | ||
|
||
@Test | ||
public void testGenerateTrajectoryDifferential() { | ||
RobotConfig differentialConfig = new RobotConfig(74.088, 6.883, | ||
new ModuleConfig(0.048, 5.45, 1.2, DCMotor.getKrakenX60(1).withReduction(5.143), 60, 2), | ||
0.56); | ||
List<Waypoint> waypoints = Arrays.asList( | ||
new Waypoint(null, new Translation2d(), new Translation2d(1.0, 0.0)), | ||
new Waypoint(new Translation2d(5.0, 0.0), new Translation2d(6.0, 0.0), null)); | ||
PathConstraints pathConstraints = new PathConstraints(3.0, 3.0, 540.0, 720.0); | ||
IdealStartingState startingState = new IdealStartingState(MetersPerSecond.zero(), new Rotation2d()); | ||
GoalEndState endState = new GoalEndState(MetersPerSecond.zero(), new Rotation2d()); | ||
PathPlannerPath path = new PathPlannerPath(waypoints, pathConstraints, startingState, endState); | ||
PathPlannerTrajectory trajectory = new PathPlannerTrajectory(path, new ChassisSpeeds(), new Rotation2d(), | ||
differentialConfig); | ||
List<PathPlannerTrajectoryState> states = trajectory.getStates(); | ||
assertTrue(states.size() > 10); | ||
double lastLV = 0; | ||
for (int i = 0; i < states.size(); i++) { | ||
double linearVelocity = states.get(i).moduleStates[0].speedMetersPerSecond; | ||
assertTrue(linearVelocity <= pathConstraints.maxVelocityMPS()); | ||
if (i > 0) { | ||
if (i < states.size() / 2) { | ||
// Verify that we are more or less monotonically increasing for the first half. | ||
assertTrue(linearVelocity - lastLV >= -0.001); | ||
} else { | ||
// and decreasing for the second half. | ||
assertTrue(linearVelocity - lastLV <= 0.001); | ||
} | ||
} | ||
lastLV = linearVelocity; | ||
} | ||
} | ||
|
||
} |