Search in sources :

Example 16 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project Dreadbots2022 by Dreadbot.

the class VelocityControlTestCommand method end.

@Override
public void end(boolean interrupted) {
    drive.setChassisSpeeds(new ChassisSpeeds(0, 0, 0));
    drive.stopMotors();
}
Also used : ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Example 17 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project frc-2022-rapid-react by team581.

the class VelocityControlTestCommand method end.

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
    driveSubsystem.setChassisSpeeds(new ChassisSpeeds(0, 0, 0));
    driveSubsystem.stopMotors();
}
Also used : ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Example 18 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project Entropy2022 by Team138Entropy.

the class Drive method autoomousDrive.

/**
 * Drives the robot with the given linear velocity and angular velocity.
 *
 * @param xSpeed Linear velocity in m/s.
 * @param rot Angular velocity in rad/s.
 */
public void autoomousDrive(double xSpeed, double rot) {
    var wheelSpeeds = mKinematics.toWheelSpeeds(new ChassisSpeeds(xSpeed, 0.0, rot));
    setAutoSpeeds(wheelSpeeds);
}
Also used : ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Example 19 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project RoboCode2022 by HarkerRobo.

the class SwerveManualPercentOutput method execute.

@Override
public void execute() {
    double angularVelocity = MathUtil.mapJoystickOutput(OI.getInstance().getDriverGamepad().getRightX(), OI.DEADBAND);
    double translationy = -MathUtil.mapJoystickOutput(OI.getInstance().getDriverGamepad().getLeftX(), OI.DEADBAND);
    double translationx = MathUtil.mapJoystickOutput(OI.getInstance().getDriverGamepad().getLeftY(), OI.DEADBAND);
    double chasisMagnitude = Math.sqrt(Math.pow(translationx, 2) + Math.pow(translationy, 2));
    if (Math.abs(chasisMagnitude) < Drivetrain.MIN_OUTPUT) {
        translationx = 0;
        translationy = 0;
        if (Math.abs(angularVelocity) < Drivetrain.MIN_OUTPUT) {
            // Drivetrain.getInstance().getPigeon().getYaw();
            angularVelocity = 0;
        }
    }
    SmartDashboard.putNumber("trans X", translationx);
    angularVelocity *= Drivetrain.MAX_ANGULAR_VEL * OUTPUT_MULTIPLIER;
    translationx *= Drivetrain.MAX_DRIVE_VEL * OUTPUT_MULTIPLIER;
    translationy *= Drivetrain.MAX_DRIVE_VEL * OUTPUT_MULTIPLIER;
    if (debouncer.calculate(Math.abs(MathUtil.mapJoystickOutput(OI.getInstance().getDriverGamepad().getRightX(), OI.DEADBAND)) < Drivetrain.MIN_OUTPUT)) {
        angularVelocity = -PIGEON_KP * (pigeonAngle - Drivetrain.getInstance().getPigeon().getYaw());
        SmartDashboard.putBoolean("holding pigeon angle", true);
    } else {
        pigeonAngle = Drivetrain.getInstance().getPigeon().getYaw();
        SmartDashboard.putBoolean("holding pigeon angle", false);
    }
    // ChassisSpeeds chassis = ChassisSpeeds.fromFieldRelativeSpeeds(translationx, translationy, -angularVelocity, new Rotation2d(Math.toRadians(Drivetrain.getInstance().getPigeon().getYaw())));
    ChassisSpeeds chassis;
    if (Drivetrain.getInstance().isFieldCentric())
        chassis = ChassisSpeeds.fromFieldRelativeSpeeds(translationx, translationy, -angularVelocity, Rotation2d.fromDegrees(-Drivetrain.getInstance().getPigeon().getYaw()));
    else
        chassis = ChassisSpeeds.fromFieldRelativeSpeeds(translationx, translationy, -angularVelocity, Rotation2d.fromDegrees(0));
    Drivetrain.getInstance().setAngleAndDriveVelocity(Drivetrain.getInstance().getKinematics().toSwerveModuleStates(chassis), true);
}
Also used : ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds)

Example 20 with ChassisSpeeds

use of edu.wpi.first.math.kinematics.ChassisSpeeds in project 2022-Robot-Development by SirLanceABot.

the class Drivetrain method drive.

/**
 * Method to drive the robot using joystick info.
 *
 * @param xSpeed Speed of the robot in the x direction (forward).
 * @param ySpeed Speed of the robot in the y direction (sideways).
 * @param turn Angular rate of the robot.
 * @param fieldRelative Whether the provided x and y speeds are relative to the field.
 */
@SuppressWarnings("ParameterName")
public void drive(double xSpeed, double ySpeed, double turn, boolean fieldRelative) {
    ChassisSpeeds chassisSpeeds;
    SwerveModuleState[] swerveModuleStates;
    if (fieldRelative)
        chassisSpeeds = ChassisSpeeds.fromFieldRelativeSpeeds(xSpeed, ySpeed, turn, navX.getRotation2d());
    else
        chassisSpeeds = new ChassisSpeeds(xSpeed, ySpeed, turn);
    swerveModuleStates = kinematics.toSwerveModuleStates(chassisSpeeds);
    SwerveDriveKinematics.desaturateWheelSpeeds(swerveModuleStates, Constant.MAX_DRIVE_SPEED);
    if (xSpeed == 0 && ySpeed == 0 && turn == 0 && previousSwerveModuleStates != null) {
        for (int i = 0; i < swerveModuleStates.length; i++) {
            swerveModuleStates[i].angle = previousSwerveModuleStates[i].angle;
        }
    }
    frontLeft.setDesiredState(swerveModuleStates[0]);
    frontRight.setDesiredState(swerveModuleStates[1]);
    backLeft.setDesiredState(swerveModuleStates[2]);
    backRight.setDesiredState(swerveModuleStates[3]);
    previousSwerveModuleStates = swerveModuleStates;
    feedWatchdog();
}
Also used : ChassisSpeeds(edu.wpi.first.math.kinematics.ChassisSpeeds) SwerveModuleState(edu.wpi.first.math.kinematics.SwerveModuleState)

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