Search in sources :

Example 26 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project 2022-Rapid-React by Manchester-Central.

the class SwerveDrive method moveFieldRelative.

public void moveFieldRelative(double sidewaysSpeed, double forwardSpeed, double theta) {
    ChassisSpeeds speeds = ChassisSpeeds.fromFieldRelativeSpeeds(sidewaysSpeed, forwardSpeed, theta, getRotation());
    move(speeds);
}
Also used : ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Example 27 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project 2022-Rapid-React by Manchester-Central.

the class SwerveDrive method moveRobotRelative.

public void moveRobotRelative(double sidewaysSpeed, double forwardSpeed, double theta) {
    ChassisSpeeds speeds = new ChassisSpeeds(forwardSpeed, sidewaysSpeed, theta);
    move(speeds);
}
Also used : ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Example 28 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project 2022-Rapid-React by Manchester-Central.

the class SwerveDrive method simulationPeriodic.

@Override
public void simulationPeriodic() {
    super.simulationPeriodic();
    ChassisSpeeds speeds = m_kinematics.toChassisSpeeds(getModuleStates());
    var currentYaw = m_gyro.getYaw();
    setSimulationAngle(currentYaw + new Rotation2d(speeds.omegaRadiansPerSecond / Constants.RobotUpdate_hz).getDegrees());
}
Also used : Rotation2d(edu.wpi.first.math.geometry.Rotation2d) ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Example 29 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project FRC2022-Rapid-React by BitBucketsFRC4183.

the class DrivetrainSubsystem method init.

@Override
public void init() {
    this.maxVelocity_metersPerSecond = 6380.0 / 60.0 * SdsModuleConfigurations.MK4_L2.getDriveReduction() * SdsModuleConfigurations.MK4_L2.getWheelDiameter() * Math.PI;
    this.maxAngularVelocity_radiansPerSecond = maxVelocity_metersPerSecond / Math.hypot(config.drive.drivetrainTrackWidth_meters / 2.0, config.drive.drivetrainWheelBase_meters / 2.0);
    this.speedModifier = 1.0;
    this.moduleFrontLeftLocation = new Translation2d(config.drive.drivetrainTrackWidth_meters / 2.0, config.drive.drivetrainWheelBase_meters / 2.0);
    this.moduleFrontRightLocation = new Translation2d(config.drive.drivetrainTrackWidth_meters / 2.0, -config.drive.drivetrainWheelBase_meters / 2.0);
    this.moduleBackLeftLocation = new Translation2d(-config.drive.drivetrainTrackWidth_meters / 2.0, config.drive.drivetrainWheelBase_meters / 2.0);
    this.moduleBackRightLocation = new Translation2d(-config.drive.drivetrainTrackWidth_meters / 2.0, -config.drive.drivetrainWheelBase_meters / 2.0);
    this.kinematics = new SwerveDriveKinematics(moduleFrontLeftLocation, moduleFrontRightLocation, moduleBackLeftLocation, moduleBackRightLocation);
    this.gyro = new AHRS(SPI.Port.kMXP, (byte) 200);
    this.chassisSpeeds = new ChassisSpeeds(0.0, 0.0, 0.0);
    this.initializeModules();
    setOdometry(new Pose2d());
}
Also used : SwerveDriveKinematics(edu.wpi.first.math.kinematics.SwerveDriveKinematics) Translation2d(edu.wpi.first.math.geometry.Translation2d) AHRS(com.kauailabs.navx.frc.AHRS) Pose2d(edu.wpi.first.math.geometry.Pose2d) ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Example 30 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project FRC2022-Rapid-React by BitBucketsFRC4183.

the class Robot method autonomousInit.

/**
 * This autonomous (along with the chooser code above) shows how to select
 * between different
 * autonomous modes using the dashboard. The sendable chooser code works with
 * the Java
 * SmartDashboard. If you prefer the LabVIEW Dashboard, remove all of the
 * chooser code and
 * uncomment the getString line to get the auto name from the text box below the
 * Gyro
 *
 * <p>
 * You can add additional auto modes by adding additional comparisons to the
 * switch structure
 * below with additional strings. If using the make sure to add them to the
 * chooser code above as well.
 */
@Override
public void autonomousInit() {
    if (config.enableDriveSubsystem && config.enableAutonomousSubsystem) {
        this.info.log(LogLevel.GENERAL, "auton started");
        Command command;
        switch(this.autonomousPathChooser.getSelected()) {
            case NOTHING:
                command = new AutonomousFollowPathCommand(config.auto.nothingPath, this.autonomousSubsystem, this.drivetrainSubsystem);
                break;
            case PATH_PLANNER_DRIVE_BACKWARDS:
                command = new AutonomousFollowPathCommand(config.auto.driveBackwardsPath, this.autonomousSubsystem, this.drivetrainSubsystem);
                break;
            case HARDCODED_SHOOT_DRIVE_BACK:
                command = new AutonomousCommand(this.autonomousSubsystem, this.drivetrainSubsystem, this.intakeSubsystem, this.shooterSubsystem).executeShootPreload().executeAction((d, i, s) -> {
                    i.forceIntaking();
                    i.spinForward();
                    // Run the feeder in reverse so that ball stays inside bms
                    s.antiFeed();
                }).executeAction((d, i, s) -> d.drive(new ChassisSpeeds(1.5, 0.0, 0)), // Drive out of the tarmac
                1).executeAction((d, i, s) -> d.stop(), // Drive out of the tarmac pt 2
                2.0).complete();
                break;
            case HARDCODED_SHOOT_DRIVE_BACK_AND_SHOOT_LOW:
                drivetrainSubsystem.resetGyroWithOffset(Rotation2d.fromDegrees(-150));
                command = new AutonomousCommand(this.autonomousSubsystem, this.drivetrainSubsystem, this.intakeSubsystem, this.shooterSubsystem).executeShootPreload().executeAction((d, i, s) -> {
                    i.forceIntaking();
                    i.spinForward();
                    // Run the feeder in reverse so that ball stays inside bms
                    s.antiFeed();
                }).executeAction((d, i, s) -> d.drive(new ChassisSpeeds(1.5, 0.0, 0)), // Drive out of the tarmac
                1).executeAction((d, i, s) -> d.stop(), // Drive out of the tarmac pt 2
                2.0).executeAction((d, i, s) -> d.drive(new ChassisSpeeds(-1.5, 0.0, 0)), // Drive back to the hub
                2).executeAction((d, i, s) -> d.stop(), // Drive back to the hub pt 2
                2.5).executeAction((d, i, s) -> d.stop(), // Drive back to the hub pt 2
                .5).executeShootPreloadLow().complete();
                break;
            case HARDCODED_SHOOT_DRIVE_BACK_AND_SHOOT_HIGH:
                drivetrainSubsystem.resetGyroWithOffset(Rotation2d.fromDegrees(-150));
                command = new AutonomousCommand(this.autonomousSubsystem, this.drivetrainSubsystem, this.intakeSubsystem, this.shooterSubsystem).executeShootPreload().executeAction((d, i, s) -> {
                    i.forceIntaking();
                    i.spinForward();
                    // Run the feeder in reverse so that ball stays inside bms
                    s.antiFeed();
                }).executeAction((d, i, s) -> d.drive(new ChassisSpeeds(1.5, 0.0, 0)), // Drive out of the tarmac
                1).executeAction((d, i, s) -> d.stop(), // Drive out of the tarmac pt 2
                2.0).executeAction((d, i, s) -> d.drive(new ChassisSpeeds(-1.5, 0.0, 0)), // Drive back to the hub
                2).executeAction((d, i, s) -> d.stop(), // Drive back to the hub pt 2
                2.5).executeAction((d, i, s) -> d.stop(), // Drive back to the hub pt 2
                .5).executeShootPreload().complete();
                break;
            case PATH_PLANNER_SHOOT_AND_DRIVE_BACKWARDS:
                command = new AutonomousCommand(this.autonomousSubsystem, this.drivetrainSubsystem, this.intakeSubsystem, this.shooterSubsystem).executeShootPreload().executeAction((d, i, s) -> i.spinForward()).executeDrivePath("Drive Backwards Single Ball", 1).executeAction((d, i, s) -> i.stopSpin(), 2).complete();
                break;
            case PATH_PLANNER_SHOOT_INTAKE_TWO_BALLS:
                command = new AutonomousCommand(this.autonomousSubsystem, this.drivetrainSubsystem, this.intakeSubsystem, this.shooterSubsystem).executeShootPreload().executeDrivePath("Drive Backwards Double Ball P1").executeAction((d, i, s) -> i.spinForward()).executeDrivePath("Drive Backwards Double Ball P2", 2).executeAction((d, i, s) -> i.stopSpin(), 2).complete();
                break;
            case MAIN_NO_TERMINAL:
                command = new AutonomousCommand(this.autonomousSubsystem, this.drivetrainSubsystem, this.intakeSubsystem, this.shooterSubsystem).executeShootPreload().executeDrivePath(// Drive to the first ball
                "Main P1").executeAction(// Activate intake
                (d, i, s) -> i.spinForward()).executeDrivePath("Main P2 Ball", // Skip terminal, go straight to the second ball
                2.0).executeAction((d, i, s) -> i.spinBackward(), // Turn off the intake after getting the ball
                2.0).executeDrivePath(// Drive to the base of the hub
                "Main P3").executeAction(// Shoot - Spin up Top
                (d, i, s) -> s.spinUpTop()).executeAction((d, i, s) -> {
                    // Activate feeders
                    s.turnOnFeeders();
                    // Activate BMS in case a ball doesn't get pulled by the feeders
                    i.ballManagementForward();
                }, // Wait 2 seconds for the shooter to spin up
                2).complete();
                break;
            case MAIN_WITH_TERMINAL:
                command = new AutonomousCommand(this.autonomousSubsystem, this.drivetrainSubsystem, this.intakeSubsystem, this.shooterSubsystem).executeShootPreload().executeDrivePath(// Drive to the first ball
                "Main P1").executeAction(// Activate intake
                (d, i, s) -> i.spinForward()).executeDrivePath("Main P2 Terminal", // Head to the Terminal ball and push it in
                2.0).executeDrivePath(// Head to the second ball
                "Main P2.5 Terminal").executeAction((d, i, s) -> i.spinBackward(), // Turn off the intake after getting the ball
                2.0).executeDrivePath(// Drive to the base of the hub
                "Main P3").executeAction(// Shoot - Spin up Top
                (d, i, s) -> s.spinUpTop()).executeAction((d, i, s) -> {
                    // Activate feeders
                    s.turnOnFeeders();
                    // Activate BMS in case a ball doesn't get pulled by the feeders
                    i.ballManagementForward();
                }, // Wait 2 seconds for the shooter to spin up
                2).complete();
                break;
            default:
                info.log(LogLevel.CRITICAL, "Invalid Autonomous Path! (SendableChooser Output: " + this.autonomousPathChooser.getSelected() + ")");
                return;
        }
        command.schedule();
    }
}
Also used : AutonomousFollowPathCommand(frc.robot.commands.AutonomousFollowPathCommand) AutonomousCommand(frc.robot.commands.AutonomousCommand) MathUtils(frc.robot.utils.MathUtils) Field2d(edu.wpi.first.wpilibj.smartdashboard.Field2d) TimedRobot(edu.wpi.first.wpilibj.TimedRobot) Pose2d(edu.wpi.first.math.geometry.Pose2d) Rotation2d(edu.wpi.first.math.geometry.Rotation2d) ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds) AutonomousFollowPathCommand(frc.robot.commands.AutonomousFollowPathCommand) CTREPhysicsSim(frc.robot.simulator.CTREPhysicsSim) Command(edu.wpi.first.wpilibj2.command.Command) ArrayList(java.util.ArrayList) List(java.util.List) Config(frc.robot.config.Config) CommandScheduler(edu.wpi.first.wpilibj2.command.CommandScheduler) DefaultDriveCommand(frc.robot.commands.DefaultDriveCommand) SmartDashboard(edu.wpi.first.wpilibj.smartdashboard.SmartDashboard) SetModeTestSubsystem(frc.robot.simulator.SetModeTestSubsystem) AutonomousPath(frc.robot.utils.AutonomousPath) frc.robot.log(frc.robot.log) SlewRateLimiter(edu.wpi.first.math.filter.SlewRateLimiter) frc.robot.subsystem(frc.robot.subsystem) SendableChooser(edu.wpi.first.wpilibj.smartdashboard.SendableChooser) SimulatorTestSubsystem(frc.robot.simulator.SimulatorTestSubsystem) AutonomousCommand(frc.robot.commands.AutonomousCommand) AutonomousCommand(frc.robot.commands.AutonomousCommand) AutonomousFollowPathCommand(frc.robot.commands.AutonomousFollowPathCommand) Command(edu.wpi.first.wpilibj2.command.Command) DefaultDriveCommand(frc.robot.commands.DefaultDriveCommand) ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Aggregations

ChassisSpeeds (edu.wpi.first.math.kinematics.ChassisSpeeds)31 Pose2d (edu.wpi.first.math.geometry.Pose2d)6 Rotation2d (edu.wpi.first.math.geometry.Rotation2d)4 DifferentialDriveWheelSpeeds (edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds)3 PathPlannerState (com.pathplanner.lib.PathPlannerTrajectory.PathPlannerState)2 RamseteController (edu.wpi.first.math.controller.RamseteController)2 Transform2d (edu.wpi.first.math.geometry.Transform2d)2 Translation2d (edu.wpi.first.math.geometry.Translation2d)2 Trajectory (edu.wpi.first.math.trajectory.Trajectory)2 Field2d (edu.wpi.first.wpilibj.smartdashboard.Field2d)2 ArrayList (java.util.ArrayList)2 AHRS (com.kauailabs.navx.frc.AHRS)1 MatBuilder (edu.wpi.first.math.MatBuilder)1 SlewRateLimiter (edu.wpi.first.math.filter.SlewRateLimiter)1 DifferentialDriveKinematics (edu.wpi.first.math.kinematics.DifferentialDriveKinematics)1 MecanumDriveMotorVoltages (edu.wpi.first.math.kinematics.MecanumDriveMotorVoltages)1 SwerveDriveKinematics (edu.wpi.first.math.kinematics.SwerveDriveKinematics)1 SwerveModuleState (edu.wpi.first.math.kinematics.SwerveModuleState)1 N1 (edu.wpi.first.math.numbers.N1)1 N3 (edu.wpi.first.math.numbers.N3)1