-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented maple-sim to advanced swerve drive example
Showing
12 changed files
with
286 additions
and
79 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
templates/AdvantageKit_AdvancedSwerveDriveProject/LICENSE-IronMaple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Shenzhen-Robotics-Alliance | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Advantage Kit - Advanced Swerve Drive Project | ||
|
||
### With more enhanced swerve drive simulation using [maple-sim](https://github.com/Shenzhen-Robotics-Alliance/maple-sim). | ||
Original Project is [here](https://www.chiefdelphi.com/t/advantagekit-2024-log-replay-again/442968/54). | ||
|
||
To use the simulation in your own project, please refer to this [Commit Change-Log](https://github.com/Shenzhen-Robotics-Alliance/maple-sim/commit/a0a469b3ec917b1246300f53d17d5558ad653e07). | ||
To see how to simulate intake for your robot, please refer to this [Commit Change-Log](https://github.com/Shenzhen-Robotics-Alliance/maple-sim/commit/d13e542aaa6557ad946fd1f78dda3e133cbb6f5c) | ||
|
||
To run the simulation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ntageKit_AdvancedSwerveDriveProject/src/main/java/frc/robot/subsystems/IntakeExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package frc.robot.subsystems; | ||
|
||
import edu.wpi.first.math.geometry.Pose3d; | ||
import edu.wpi.first.math.geometry.Rotation3d; | ||
import edu.wpi.first.math.geometry.Transform3d; | ||
import org.ironmaple.simulation.IntakeSimulation; | ||
import org.ironmaple.simulation.SimulatedArena; | ||
import org.ironmaple.simulation.drivesims.AbstractDriveTrainSimulation; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
/** An example of a simulated intake, which will such a note if activated. */ | ||
public class IntakeExample extends IntakeSimulation { | ||
private final AbstractDriveTrainSimulation driveTrainSimulation; | ||
|
||
public IntakeExample(SimulatedArena arena, AbstractDriveTrainSimulation driveTrainSimulation) { | ||
super(arena, driveTrainSimulation, 0.6, IntakeSimulation.IntakeSide.BACK, 1); | ||
this.driveTrainSimulation = driveTrainSimulation; | ||
} | ||
|
||
@Override | ||
public void startIntake() { | ||
super.startIntake(); | ||
} | ||
|
||
@Override | ||
public void stopIntake() { | ||
super.stopIntake(); | ||
} | ||
|
||
/** visualizes the note in the intake */ | ||
public void visualizeNoteInIntake() { | ||
final Pose3d robotPose = new Pose3d(driveTrainSimulation.getSimulatedDriveTrainPose()), | ||
noteInIntakePose = | ||
robotPose.plus(new Transform3d(0.1, 0, 0.4, new Rotation3d(0, -Math.toRadians(60), 0))); | ||
Logger.recordOutput( | ||
"Intake/NoteInIntake", this.gamePieceCount != 0 ? noteInIntakePose : new Pose3d()); | ||
} | ||
|
||
public void clearGamePiece() { | ||
super.gamePieceCount = 0; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ageKit_AdvancedSwerveDriveProject/src/main/java/frc/robot/subsystems/drive/GyroIOSim.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package frc.robot.subsystems.drive; | ||
|
||
import frc.robot.util.OdometryTimeStampsSim; | ||
import org.ironmaple.simulation.drivesims.GyroSimulation; | ||
|
||
public class GyroIOSim implements GyroIO { | ||
private final GyroSimulation gyroSimulation; | ||
|
||
public GyroIOSim(GyroSimulation gyroSimulation) { | ||
this.gyroSimulation = gyroSimulation; | ||
} | ||
|
||
@Override | ||
public void updateInputs(GyroIOInputs inputs) { | ||
inputs.connected = true; | ||
inputs.odometryYawPositions = gyroSimulation.getCachedGyroReadings(); | ||
inputs.odometryYawTimestamps = OdometryTimeStampsSim.getTimeStamps(); | ||
inputs.yawPosition = gyroSimulation.getGyroReading(); | ||
inputs.yawVelocityRadPerSec = gyroSimulation.getMeasuredAngularVelocityRadPerSec(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.