Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Command getAutonomousCommand() {
- // Create a voltage constraint to ensure we don't accelerate too fast
- var autoVoltageConstraint =
- new DifferentialDriveVoltageConstraint(
- new SimpleMotorFeedforward(Constants.ksVolts,
- Constants.kvVoltSecondsPerMeter,
- Constants.kaVoltSecondsSquaredPerMeter),
- Constants.kinematics,
- 10);
- // Create config for trajectory
- TrajectoryConfig config =
- new TrajectoryConfig(Constants.kMaxSpeedMetersPerSecond,
- Constants.kMaxAccelerationMetersPerSecondSquared)
- // Add kinematics to ensure max speed is actually obeyed
- .setKinematics(Constants.kinematics)
- // Apply the voltage constraint
- .addConstraint(autoVoltageConstraint);
- // An example trajectory to follow. All units in meters.
- Trajectory exampleTrajectory = TrajectoryGenerator.generateTrajectory(
- // Start at the origin facing the +X direction
- new Pose2d(0, 0, new Rotation2d(0)),
- // Pass through these two interior waypoints, making an 's' curve path
- List.of(
- new Translation2d(1, 0),
- new Translation2d(2, 0)
- ),
- // End 3 meters straight ahead of where we started, facing forward
- new Pose2d(3, 0, new Rotation2d(0)),
- // Pass config
- config
- );
- for (Trajectory.State s : exampleTrajectory.getStates()) {
- Pose2d p = s.poseMeters;
- System.out.println("mp x" + p.getTranslation().getX());
- System.out.println("mp y" + p.getTranslation().getY());
- System.out.println("mp r" + p.getRotation().getDegrees());
- }
- RamseteCommand ramseteCommand = new RamseteCommand(
- exampleTrajectory,
- drivetrain::getPose,
- new RamseteController(Constants.kRamseteB, Constants.kRamseteZeta),
- new SimpleMotorFeedforward(Constants.ksVolts,
- Constants.kvVoltSecondsPerMeter,
- Constants.kaVoltSecondsSquaredPerMeter),
- Constants.kinematics,
- drivetrain::getWheelSpeeds,
- new PIDController(Constants.kPDriveVel, 0, 0),
- new PIDController(Constants.kPDriveVel, 0, 0),
- // RamseteCommand passes volts to the callback
- drivetrain::tankDriveVolts,
- drivetrain
- );
- // Run path following command, then stop at the end.
- return ramseteCommand.andThen(() -> drivetrain.tankDriveVolts(0, 0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement