Advertisement
Guest User

auton code

a guest
Feb 21st, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. public Command getAutonomousCommand() {
  2. // Create a voltage constraint to ensure we don't accelerate too fast
  3. var autoVoltageConstraint =
  4. new DifferentialDriveVoltageConstraint(
  5. new SimpleMotorFeedforward(Constants.ksVolts,
  6. Constants.kvVoltSecondsPerMeter,
  7. Constants.kaVoltSecondsSquaredPerMeter),
  8. Constants.kinematics,
  9. 10);
  10.  
  11. // Create config for trajectory
  12. TrajectoryConfig config =
  13. new TrajectoryConfig(Constants.kMaxSpeedMetersPerSecond,
  14. Constants.kMaxAccelerationMetersPerSecondSquared)
  15. // Add kinematics to ensure max speed is actually obeyed
  16. .setKinematics(Constants.kinematics)
  17. // Apply the voltage constraint
  18. .addConstraint(autoVoltageConstraint);
  19.  
  20. // An example trajectory to follow. All units in meters.
  21. Trajectory exampleTrajectory = TrajectoryGenerator.generateTrajectory(
  22. // Start at the origin facing the +X direction
  23. new Pose2d(0, 0, new Rotation2d(0)),
  24. // Pass through these two interior waypoints, making an 's' curve path
  25. List.of(
  26. new Translation2d(1, 0),
  27. new Translation2d(2, 0)
  28. ),
  29. // End 3 meters straight ahead of where we started, facing forward
  30. new Pose2d(3, 0, new Rotation2d(0)),
  31. // Pass config
  32. config
  33. );
  34.  
  35. for (Trajectory.State s : exampleTrajectory.getStates()) {
  36. Pose2d p = s.poseMeters;
  37. System.out.println("mp x" + p.getTranslation().getX());
  38. System.out.println("mp y" + p.getTranslation().getY());
  39. System.out.println("mp r" + p.getRotation().getDegrees());
  40. }
  41.  
  42. RamseteCommand ramseteCommand = new RamseteCommand(
  43. exampleTrajectory,
  44. drivetrain::getPose,
  45. new RamseteController(Constants.kRamseteB, Constants.kRamseteZeta),
  46. new SimpleMotorFeedforward(Constants.ksVolts,
  47. Constants.kvVoltSecondsPerMeter,
  48. Constants.kaVoltSecondsSquaredPerMeter),
  49. Constants.kinematics,
  50. drivetrain::getWheelSpeeds,
  51. new PIDController(Constants.kPDriveVel, 0, 0),
  52. new PIDController(Constants.kPDriveVel, 0, 0),
  53. // RamseteCommand passes volts to the callback
  54. drivetrain::tankDriveVolts,
  55. drivetrain
  56. );
  57.  
  58. // Run path following command, then stop at the end.
  59. return ramseteCommand.andThen(() -> drivetrain.tankDriveVolts(0, 0));
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement