Search in sources :

Example 1 with DrivetrainSubsystem

use of org.snobotv2.examples.base.subsystems.DrivetrainSubsystem in project SnobotSimV2 by snobotsim.

the class DriveTrajectoryCommand method createWithVoltage.

public static Command createWithVoltage(DrivetrainSubsystem drivetrain, Trajectory trajectory, boolean resetOnStart) {
    DrivetrainSubsystem.DrivetrainConstants drivetrainConstants = drivetrain.getConstants();
    RamseteCommand ramseteCommand = new RamseteCommand(trajectory, drivetrain::getPose, new RamseteController(TrajectoryFactory.AutoConstants.kRamseteB, TrajectoryFactory.AutoConstants.kRamseteZeta), new SimpleMotorFeedforward(drivetrainConstants.getKsVolts(), drivetrainConstants.getKvVoltSecondsPerMeter(), drivetrainConstants.getKaVoltSecondsSquaredPerMeter()), drivetrainConstants.getKinematics(), drivetrain::getWheelSpeeds, new PIDController(TrajectoryFactory.DriveConstants.kPDriveVel, 0, 0), new PIDController(TrajectoryFactory.DriveConstants.kPDriveVel, 0, 0), // RamseteCommand passes volts to the callback
    drivetrain::tankDriveVolts, drivetrain);
    Command runThenStop = ramseteCommand.andThen(() -> drivetrain.stop());
    if (resetOnStart) {
        Command resetPose = new InstantCommand(() -> drivetrain.resetOdometry(trajectory.getInitialPose()));
        return resetPose.andThen(runThenStop);
    }
    return runThenStop;
}
Also used : SimpleMotorFeedforward(edu.wpi.first.math.controller.SimpleMotorFeedforward) InstantCommand(edu.wpi.first.wpilibj2.command.InstantCommand) InstantCommand(edu.wpi.first.wpilibj2.command.InstantCommand) RamseteCommand(edu.wpi.first.wpilibj2.command.RamseteCommand) Command(edu.wpi.first.wpilibj2.command.Command) RamseteCommand(edu.wpi.first.wpilibj2.command.RamseteCommand) RamseteController(edu.wpi.first.math.controller.RamseteController) PIDController(edu.wpi.first.math.controller.PIDController) DrivetrainSubsystem(org.snobotv2.examples.base.subsystems.DrivetrainSubsystem)

Example 2 with DrivetrainSubsystem

use of org.snobotv2.examples.base.subsystems.DrivetrainSubsystem in project SnobotSimV2 by snobotsim.

the class DriveTrajectoryCommand method createWithVelocity.

public static Command createWithVelocity(DrivetrainSubsystem drivetrain, Trajectory trajectory, boolean resetOnStart) {
    DrivetrainSubsystem.DrivetrainConstants drivetrainConstants = drivetrain.getConstants();
    RamseteCommand ramseteCommand = new RamseteCommand(trajectory, drivetrain::getPose, new RamseteController(TrajectoryFactory.AutoConstants.kRamseteB, TrajectoryFactory.AutoConstants.kRamseteZeta), drivetrainConstants.getKinematics(), drivetrain::smartVelocityControlMetersPerSec, drivetrain);
    Command runThenStop = ramseteCommand.andThen(() -> drivetrain.stop());
    if (resetOnStart) {
        Command resetPose = new InstantCommand(() -> drivetrain.resetOdometry(trajectory.getInitialPose()));
        return resetPose.andThen(runThenStop);
    }
    return runThenStop;
}
Also used : InstantCommand(edu.wpi.first.wpilibj2.command.InstantCommand) InstantCommand(edu.wpi.first.wpilibj2.command.InstantCommand) RamseteCommand(edu.wpi.first.wpilibj2.command.RamseteCommand) Command(edu.wpi.first.wpilibj2.command.Command) RamseteCommand(edu.wpi.first.wpilibj2.command.RamseteCommand) RamseteController(edu.wpi.first.math.controller.RamseteController) DrivetrainSubsystem(org.snobotv2.examples.base.subsystems.DrivetrainSubsystem)

Aggregations

RamseteController (edu.wpi.first.math.controller.RamseteController)2 Command (edu.wpi.first.wpilibj2.command.Command)2 InstantCommand (edu.wpi.first.wpilibj2.command.InstantCommand)2 RamseteCommand (edu.wpi.first.wpilibj2.command.RamseteCommand)2 DrivetrainSubsystem (org.snobotv2.examples.base.subsystems.DrivetrainSubsystem)2 PIDController (edu.wpi.first.math.controller.PIDController)1 SimpleMotorFeedforward (edu.wpi.first.math.controller.SimpleMotorFeedforward)1