mirror of
https://github.com/Team4388/2023WayOfTheRobot.git
synced 2026-06-09 00:37:59 -06:00
converstions and getState
This commit is contained in:
@@ -34,6 +34,7 @@ public class RobotContainer {
|
|||||||
/* Subsystems */
|
/* Subsystems */
|
||||||
private final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.leftFront, m_robotMap.rightFront, m_robotMap.leftBack, m_robotMap.rightBack, m_robotMap.gyro);
|
private final SwerveDrive m_robotSwerveDrive = new SwerveDrive(m_robotMap.leftFront, m_robotMap.rightFront, m_robotMap.leftBack, m_robotMap.rightBack, m_robotMap.gyro);
|
||||||
private final LED m_robotLED = new LED(m_robotMap.LEDController);
|
private final LED m_robotLED = new LED(m_robotMap.LEDController);
|
||||||
|
|
||||||
|
|
||||||
/* Controllers */
|
/* Controllers */
|
||||||
private final XboxController m_driverXbox = new XboxController(OIConstants.XBOX_DRIVER_ID);
|
private final XboxController m_driverXbox = new XboxController(OIConstants.XBOX_DRIVER_ID);
|
||||||
@@ -67,13 +68,19 @@ public class RobotContainer {
|
|||||||
*/
|
*/
|
||||||
private void configureButtonBindings() {
|
private void configureButtonBindings() {
|
||||||
/* Driver Buttons */
|
/* Driver Buttons */
|
||||||
// test command to spin the robot while pressing A on the driver controller
|
|
||||||
|
new JoystickButton(getDriverJoystick(), XboxController.A_BUTTON)
|
||||||
|
.onTrue(new InstantCommand(() -> gyroRef.reset()));
|
||||||
|
|
||||||
/* Operator Buttons */
|
/* Operator Buttons */
|
||||||
// activates "Lit Mode"
|
// activates "Lit Mode"
|
||||||
new JoystickButton(getOperatorJoystick(), XboxController.A_BUTTON)
|
new JoystickButton(getOperatorJoystick(), XboxController.A_BUTTON)
|
||||||
.whileTrue(new RunCommand(() -> m_robotLED.setPattern(LEDPatterns.LAVA_RAINBOW), m_robotLED))
|
.whileTrue(new RunCommand(() -> m_robotLED.setPattern(LEDPatterns.LAVA_RAINBOW), m_robotLED))
|
||||||
.whileFalse(new RunCommand(() -> m_robotLED.setPattern(LEDConstants.DEFAULT_PATTERN), m_robotLED));
|
.whileFalse(new RunCommand(() -> m_robotLED.setPattern(LEDConstants.DEFAULT_PATTERN), m_robotLED));
|
||||||
|
|
||||||
|
//New interupt button
|
||||||
|
new JoystickButton(getOperatorJoystick(), XboxController.X_BUTTON)
|
||||||
|
.onTrue(new InstantCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package frc4388.robot.subsystems;
|
|||||||
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
|
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
|
||||||
import com.ctre.phoenix.motorcontrol.RemoteSensorSource;
|
import com.ctre.phoenix.motorcontrol.RemoteSensorSource;
|
||||||
import com.ctre.phoenix.motorcontrol.TalonFXControlMode;
|
import com.ctre.phoenix.motorcontrol.TalonFXControlMode;
|
||||||
|
import com.ctre.phoenix.motorcontrol.can.TalonFX;
|
||||||
import com.ctre.phoenix.motorcontrol.can.TalonFXConfiguration;
|
import com.ctre.phoenix.motorcontrol.can.TalonFXConfiguration;
|
||||||
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
|
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
|
||||||
import com.ctre.phoenix.sensors.CANCoder;
|
import com.ctre.phoenix.sensors.CANCoder;
|
||||||
@@ -81,6 +82,26 @@ public class SwerveModule extends SubsystemBase {
|
|||||||
return Rotation2d.fromDegrees(canCoder.getAbsolutePosition());
|
return Rotation2d.fromDegrees(canCoder.getAbsolutePosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
driveMotor.set(0);
|
||||||
|
angleMotor.set(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rotateToAngle(double angle){
|
||||||
|
angleMotor.set(TalonFXControlMode.Position, angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get state of swerve module
|
||||||
|
* @return speed in m/s and angle in degrees
|
||||||
|
*/
|
||||||
|
public SwerveModuleState getState() {
|
||||||
|
return new SwerveModuleState(
|
||||||
|
Units.inchesToMeters(driveMotor.getSelectedSensorVelocity() * SwerveDriveConstants.Conversions.INCHES_PER_TICK) * SwerveDriveConstants.Conversions.TICK_TIME_TO_SECONDS,
|
||||||
|
getAngle()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the speed and rotation of the SwerveModule from a SwerveModuleState object
|
* Set the speed and rotation of the SwerveModule from a SwerveModuleState object
|
||||||
* @param desiredState a SwerveModuleState representing the desired new state of the module
|
* @param desiredState a SwerveModuleState representing the desired new state of the module
|
||||||
@@ -104,4 +125,6 @@ public class SwerveModule extends SubsystemBase {
|
|||||||
driveMotor.set(angleMotor.get() + feetPerSecond / SwerveDriveConstants.MAX_SPEED_FEET_PER_SECOND);
|
driveMotor.set(angleMotor.get() + feetPerSecond / SwerveDriveConstants.MAX_SPEED_FEET_PER_SECOND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user