-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
maple sim swerve sim #65
base: master
Are you sure you want to change the base?
Changes from all commits
de2f56a
53b0cfe
1518951
336c726
f301794
8b1f43f
b4f8617
bd66aef
2280314
ab73879
30497c3
af653f6
37e07ff
f5a7e9a
ef39e7f
c29ffb9
c10c8c5
6f466da
7d52a97
d5d7f76
06c0ce3
bcd7d01
2997d86
2454b7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
package org.curtinfrc.frc2025; | ||
|
||
import static edu.wpi.first.units.Units.Inches; | ||
import static org.curtinfrc.frc2025.subsystems.intake.IntakeConstants.intakeVolts; | ||
import static org.curtinfrc.frc2025.subsystems.vision.VisionConstants.*; | ||
|
||
import choreo.auto.AutoFactory; | ||
import com.ctre.phoenix6.SignalLogger; | ||
import edu.wpi.first.math.geometry.Pose2d; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.DriverStation; | ||
import edu.wpi.first.wpilibj.Joystick; | ||
import edu.wpi.first.wpilibj.Threads; | ||
import edu.wpi.first.wpilibj2.command.CommandScheduler; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
import edu.wpi.first.wpilibj2.command.button.CommandXboxController; | ||
import edu.wpi.first.wpilibj2.command.button.RobotModeTriggers; | ||
import edu.wpi.first.wpilibj2.command.button.Trigger; | ||
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine; | ||
import java.util.Set; | ||
import org.curtinfrc.frc2025.Constants.Mode; | ||
import org.curtinfrc.frc2025.Constants.RobotType; | ||
import org.curtinfrc.frc2025.Constants.Setpoints; | ||
import org.curtinfrc.frc2025.generated.TunerConstants; | ||
import org.curtinfrc.frc2025.subsystems.drive.Drive; | ||
|
@@ -44,6 +50,10 @@ | |
import org.curtinfrc.frc2025.subsystems.vision.VisionIOQuestNav; | ||
import org.curtinfrc.frc2025.util.AutoChooser; | ||
import org.curtinfrc.frc2025.util.VirtualSubsystem; | ||
import org.ironmaple.simulation.SimulatedArena; | ||
import org.ironmaple.simulation.drivesims.COTS; | ||
import org.ironmaple.simulation.drivesims.SwerveDriveSimulation; | ||
import org.ironmaple.simulation.drivesims.configs.DriveTrainSimulationConfig; | ||
import org.littletonrobotics.junction.LogFileUtil; | ||
import org.littletonrobotics.junction.LoggedRobot; | ||
import org.littletonrobotics.junction.Logger; | ||
|
@@ -75,6 +85,10 @@ public class Robot extends LoggedRobot { | |
private final AutoFactory autoFactory; | ||
private final Autos autos; | ||
|
||
private Joystick simJoystick; // Joystick for simulation input | ||
private final Trigger Z = new Trigger(() -> simJoystick.getRawAxis(0) == 1); | ||
private final Trigger X = new Trigger(() -> simJoystick.getRawAxis(1) == 1); | ||
|
||
public Robot() { | ||
// Record metadata | ||
Logger.recordMetadata("ProjectName", BuildConstants.MAVEN_NAME); | ||
|
@@ -167,15 +181,39 @@ public Robot() { | |
|
||
case SIMBOT -> { | ||
// Sim robot, instantiate physics sim IO implementations | ||
// Create and configure a drivetrain simulation configuration | ||
final DriveTrainSimulationConfig driveTrainSimulationConfig = | ||
DriveTrainSimulationConfig.Default() | ||
// Specify gyro type (for realistic gyro drifting and error simulation) | ||
.withGyro(COTS.ofPigeon2()) | ||
// Specify swerve module (for realistic swerve dynamics) | ||
.withSwerveModule( | ||
COTS.ofMark4( | ||
DCMotor.getKrakenX60Foc(1), // Drive motor is a Kraken X60 | ||
DCMotor.getFalcon500(1), // Steer motor is a Falcon 500 | ||
COTS.WHEELS.COLSONS.cof, // Use the COF for Colson Wheels | ||
3)) // L3 Gear ratio | ||
// Configures the track length and track width (spacing between swerve modules) | ||
.withTrackLengthTrackWidth(Inches.of(24), Inches.of(24)) | ||
// Configures the bumper size (dimensions of the robot bumper) | ||
.withBumperSize(Inches.of(30), Inches.of(30)); | ||
|
||
final SwerveDriveSimulation swerveDriveSimulation = | ||
new SwerveDriveSimulation( | ||
// Specify Configuration | ||
driveTrainSimulationConfig, | ||
// Specify starting pose | ||
new Pose2d(3, 3, new Rotation2d())); | ||
|
||
SimulatedArena.getInstance().addDriveTrainSimulation(swerveDriveSimulation); | ||
|
||
drive = | ||
new Drive( | ||
new GyroIOSim( | ||
() -> drive.getKinematics(), | ||
() -> drive.getModuleStates()) {}, // work around crash | ||
new ModuleIOSim(TunerConstants.FrontLeft), | ||
new ModuleIOSim(TunerConstants.FrontRight), | ||
new ModuleIOSim(TunerConstants.BackLeft), | ||
new ModuleIOSim(TunerConstants.BackRight)); | ||
new GyroIOSim(swerveDriveSimulation.getGyroSimulation()) {}, // work around crash | ||
new ModuleIOSim(swerveDriveSimulation.getModules()[0]), | ||
new ModuleIOSim(swerveDriveSimulation.getModules()[1]), | ||
new ModuleIOSim(swerveDriveSimulation.getModules()[2]), | ||
new ModuleIOSim(swerveDriveSimulation.getModules()[3])); | ||
vision = | ||
new Vision( | ||
drive::addVisionMeasurement, | ||
|
@@ -186,6 +224,8 @@ public Robot() { | |
elevator = new Elevator(new ElevatorIO() {}); | ||
intake = new Intake(new IntakeIOSim()); | ||
ejector = new Ejector(new EjectorIOSim()); | ||
|
||
simJoystick = new Joystick(0); // Assuming keyboard/joystick is ID 0 | ||
} | ||
} | ||
} else { | ||
|
@@ -262,12 +302,35 @@ public Robot() { | |
RobotModeTriggers.autonomous().whileTrue(autoChooser.selectedCommandScheduler()); | ||
|
||
// Default command, normal field-relative drive | ||
drive.setDefaultCommand( | ||
drive.joystickDrive( | ||
() -> -controller.getLeftY(), | ||
() -> -controller.getLeftX(), | ||
() -> -controller.getRightX())); | ||
if (Constants.robotType == RobotType.SIMBOT) { | ||
// drive.setDefaultCommand( | ||
// drive.joystickDrive( | ||
// () -> -simJoystick.getRawAxis(0), () -> -simJoystick.getRawAxis(1), () -> 0)); | ||
drive.setDefaultCommand(drive.joystickDrive(() -> 0, () -> 0, () -> 0)); | ||
Z.whileTrue(superstructure.align(Setpoints.L2)); | ||
X.whileTrue(superstructure.align(Setpoints.COLLECT)); | ||
} else { | ||
drive.setDefaultCommand( | ||
drive.joystickDrive( | ||
() -> -controller.getLeftY(), | ||
() -> -controller.getLeftX(), | ||
() -> -controller.getRightX())); | ||
|
||
controller.rightBumper().whileTrue(superstructure.align(Setpoints.L3)); | ||
controller.leftBumper().whileTrue(superstructure.align(Setpoints.L2)); | ||
controller.leftTrigger().whileTrue(superstructure.align(Setpoints.COLLECT)); | ||
} | ||
Comment on lines
+305
to
+322
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is input changed in sim? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So i could test it in class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert pls I will just use xbox controller thx |
||
|
||
elevator.setDefaultCommand( | ||
Commands.defer(() -> elevator.goToSetpoint(Setpoints.COLLECT), Set.of(elevator))); | ||
|
||
// controller | ||
// .rightBumper() | ||
// .negate() | ||
// .and(controller.leftBumper().negate()) | ||
// .onTrue(Commands.defer(() -> elevator.goToSetpoint(Setpoints.COLLECT), Set.of(elevator))); | ||
|
||
// controller.a().whileTrue(elevator.zero()); | ||
elevator | ||
.isNotAtCollect | ||
.and(elevator.atSetpoint) | ||
|
@@ -278,6 +341,16 @@ public Robot() { | |
ejector.setDefaultCommand(ejector.stop()); | ||
elevator.setDefaultCommand(elevator.goToSetpoint(Setpoints.COLLECT)); | ||
|
||
drive | ||
.atSetpointPose | ||
.and(elevator.isNotAtCollect) | ||
.and(elevator.atSetpoint) | ||
.onTrue( | ||
ejector.eject(1000).until(elevator.isNotAtCollect.negate()).andThen(ejector.stop())); | ||
|
||
// elevator.toZero.whileTrue(intake.intake(intakeVolts)); | ||
// elevator.toZero.().whileTrue(intake.stop()); | ||
|
||
intake | ||
.backSensor | ||
.and(intake.frontSensor.negate()) | ||
|
@@ -316,10 +389,6 @@ public Robot() { | |
new Pose2d(drive.getPose().getTranslation(), Rotation2d.kZero)), | ||
drive) | ||
.ignoringDisable(true)); | ||
|
||
controller.rightBumper().whileTrue(superstructure.align(Setpoints.L3)); | ||
controller.leftBumper().whileTrue(superstructure.align(Setpoints.L2)); | ||
controller.leftTrigger().whileTrue(superstructure.align(Setpoints.COLLECT)); | ||
} | ||
|
||
/** This function is called periodically during all modes. */ | ||
|
@@ -391,7 +460,7 @@ public void teleopPeriodic() { | |
Logger.recordOutput("IntakeCommand", "null"); | ||
} | ||
|
||
if (intake.getCurrentCommand() != null) { | ||
if (drive.getCurrentCommand() != null) { | ||
Logger.recordOutput("DriveCommand", drive.getCurrentCommand().getName()); | ||
} else { | ||
Logger.recordOutput("DriveCommand", "null"); | ||
|
@@ -415,5 +484,7 @@ public void simulationInit() {} | |
|
||
/** This function is called periodically whilst in simulation. */ | ||
@Override | ||
public void simulationPeriodic() {} | ||
public void simulationPeriodic() { | ||
SimulatedArena.getInstance().simulationPeriodic(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment outdated