From 4f034e6c142c9906b7852fe10592923ee58659d6 Mon Sep 17 00:00:00 2001 From: Prateek Machiraju Date: Mon, 21 Oct 2019 19:21:46 -0400 Subject: [PATCH] generateTrajectory: default reversed param to false (#1953) --- .../frc/trajectory/TrajectoryGenerator.h | 12 +- .../trajectory/TrajectoryGenerator.java | 118 ++++++++++++++++++ 2 files changed, 126 insertions(+), 4 deletions(-) diff --git a/wpilibc/src/main/native/include/frc/trajectory/TrajectoryGenerator.h b/wpilibc/src/main/native/include/frc/trajectory/TrajectoryGenerator.h index 3f2156d887..9ca48c6543 100644 --- a/wpilibc/src/main/native/include/frc/trajectory/TrajectoryGenerator.h +++ b/wpilibc/src/main/native/include/frc/trajectory/TrajectoryGenerator.h @@ -45,7 +45,8 @@ class TrajectoryGenerator { units::meters_per_second_t startVelocity, units::meters_per_second_t endVelocity, units::meters_per_second_t maxVelocity, - units::meters_per_second_squared_t maxAcceleration, bool reversed); + units::meters_per_second_squared_t maxAcceleration, + bool reversed = false); /** * Generates a trajectory with the given waypoints and constraints. @@ -72,7 +73,8 @@ class TrajectoryGenerator { units::meters_per_second_t startVelocity, units::meters_per_second_t endVelocity, units::meters_per_second_t maxVelocity, - units::meters_per_second_squared_t maxAcceleration, bool reversed); + units::meters_per_second_squared_t maxAcceleration, + bool reversed = false); /** * Generates a trajectory with the given waypoints and differential drive @@ -98,7 +100,8 @@ class TrajectoryGenerator { units::meters_per_second_t startVelocity, units::meters_per_second_t endVelocity, units::meters_per_second_t maxVelocity, - units::meters_per_second_squared_t maxAcceleration, bool reversed); + units::meters_per_second_squared_t maxAcceleration, + bool reversed = false); /** * Generates a trajectory with the given waypoints and differential drive @@ -128,7 +131,8 @@ class TrajectoryGenerator { units::meters_per_second_t startVelocity, units::meters_per_second_t endVelocity, units::meters_per_second_t maxVelocity, - units::meters_per_second_squared_t maxAcceleration, bool reversed); + units::meters_per_second_squared_t maxAcceleration, + bool reversed = false); /** * Generate spline points from a vector of splines by parameterizing the diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGenerator.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGenerator.java index 9d40206bc6..a93e4683a1 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGenerator.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryGenerator.java @@ -80,6 +80,31 @@ public final class TrajectoryGenerator { maxAccelerationMetersPerSecondSq, reversed); } + /** + * Generates a trajectory with the given waypoints and constraints. + * + * @param waypoints A vector of points that the trajectory must go through. + * @param constraints A vector of various velocity and acceleration + * constraints. + * @param startVelocityMetersPerSecond The start velocity for the trajectory. + * @param endVelocityMetersPerSecond The end velocity for the trajectory. + * @param maxVelocityMetersPerSecond The max velocity for the trajectory. + * @param maxAccelerationMetersPerSecondSq The max acceleration for the trajectory. + * @return The trajectory. + */ + public static Trajectory generateTrajectory( + List waypoints, + List constraints, + double startVelocityMetersPerSecond, + double endVelocityMetersPerSecond, + double maxVelocityMetersPerSecond, + double maxAccelerationMetersPerSecondSq + ) { + return generateTrajectory(waypoints, constraints, startVelocityMetersPerSecond, + endVelocityMetersPerSecond, maxVelocityMetersPerSecond, maxAccelerationMetersPerSecondSq, + false); + } + /** * Generates a trajectory with the given waypoints and constraints. * @@ -133,6 +158,37 @@ public final class TrajectoryGenerator { maxAccelerationMetersPerSecondSq, reversed); } + /** + * Generates a trajectory with the given waypoints and constraints. + * + * @param start The starting pose for the trajectory. + * @param waypoints The interior waypoints for the trajectory. The headings + * will be determined automatically to ensure continuous + * curvature. + * @param end The ending pose for the trajectory. + * @param constraints A vector of various velocity and acceleration + * constraints. + * @param startVelocityMetersPerSecond The start velocity for the trajectory. + * @param endVelocityMetersPerSecond The end velocity for the trajectory. + * @param maxVelocityMetersPerSecond The max velocity for the trajectory. + * @param maxAccelerationMetersPerSecondSq The max acceleration for the trajectory. + * @return The trajectory. + */ + public static Trajectory generateTrajectory( + Pose2d start, + List waypoints, + Pose2d end, + List constraints, + double startVelocityMetersPerSecond, + double endVelocityMetersPerSecond, + double maxVelocityMetersPerSecond, + double maxAccelerationMetersPerSecondSq + ) { + return generateTrajectory(start, waypoints, end, constraints, + startVelocityMetersPerSecond, endVelocityMetersPerSecond, maxVelocityMetersPerSecond, + maxAccelerationMetersPerSecondSq, false); + } + /** * Generates a trajectory with the given waypoints and differential drive constraints. Use * this method if you just want a constraint such that none of the wheels on your differential @@ -172,6 +228,34 @@ public final class TrajectoryGenerator { ); } + /** + * Generates a trajectory with the given waypoints and differential drive constraints. Use + * this method if you just want a constraint such that none of the wheels on your differential + * drive exceed the specified max velocity. If you desire to impose more constraints, please + * use the other overloads. + * + * @param waypoints A vector of points that the trajectory must go through. + * @param differentialDriveKinematics The DifferentialDriveKinematics object that represents + * your drivetrain. + * @param startVelocityMetersPerSecond The start velocity for the trajectory. + * @param endVelocityMetersPerSecond The end velocity for the trajectory. + * @param maxVelocityMetersPerSecond The max velocity for the trajectory. + * @param maxAccelerationMetersPerSecondSq The max acceleration for the trajectory. + * @return The trajectory. + */ + public static Trajectory generateTrajectory( + List waypoints, + DifferentialDriveKinematics differentialDriveKinematics, + double startVelocityMetersPerSecond, + double endVelocityMetersPerSecond, + double maxVelocityMetersPerSecond, + double maxAccelerationMetersPerSecondSq + ) { + return generateTrajectory(waypoints, differentialDriveKinematics, startVelocityMetersPerSecond, + endVelocityMetersPerSecond, maxVelocityMetersPerSecond, + maxAccelerationMetersPerSecondSq, false); + } + /** * Generates a trajectory with the given waypoints and differential drive constraints. Use * this method if you just want a constraint such that none of the wheels on your differential @@ -217,6 +301,40 @@ public final class TrajectoryGenerator { ); } + /** + * Generates a trajectory with the given waypoints and differential drive constraints. Use + * this method if you just want a constraint such that none of the wheels on your differential + * drive exceed the specified max velocity. If you desire to impose more constraints, please + * use the other overloads. + * + * @param start The starting pose for the trajectory. + * @param waypoints The interior waypoints for the trajectory. The headings + * will be determined automatically to ensure continuous + * curvature. + * @param end The ending pose for the trajectory. + * @param differentialDriveKinematics The DifferentialDriveKinematics object that represents + * your drivetrain. + * @param startVelocityMetersPerSecond The start velocity for the trajectory. + * @param endVelocityMetersPerSecond The end velocity for the trajectory. + * @param maxVelocityMetersPerSecond The max velocity for the trajectory. + * @param maxAccelerationMetersPerSecondSq The max acceleration for the trajectory. + * @return The trajectory. + */ + public static Trajectory generateTrajectory( + Pose2d start, + List waypoints, + Pose2d end, + DifferentialDriveKinematics differentialDriveKinematics, + double startVelocityMetersPerSecond, + double endVelocityMetersPerSecond, + double maxVelocityMetersPerSecond, + double maxAccelerationMetersPerSecondSq + ) { + return generateTrajectory(start, waypoints, end, differentialDriveKinematics, + startVelocityMetersPerSecond, endVelocityMetersPerSecond, + maxVelocityMetersPerSecond, maxAccelerationMetersPerSecondSq, false); + } + /** * Generate spline points from a vector of splines by parameterizing the * splines.