Skip to content
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

Add basic Maplesim support #24

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@

import edu.wpi.first.epilogue.Logged;
import edu.wpi.first.epilogue.logging.FileBackend;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.networktables.StructArrayPublisher;
import edu.wpi.first.epilogue.Epilogue;
import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import org.ironmaple.simulation.SimulatedArena;
import org.ironmaple.simulation.seasonspecific.reefscape2025.ReefscapeAlgaeOnField;
import org.ironmaple.simulation.seasonspecific.reefscape2025.ReefscapeCoral;

import frc.robot.Constants.LoggingConstants;

/**
Expand All @@ -24,6 +34,19 @@ public class Robot extends TimedRobot {

private final RobotContainer m_robotContainer;

/**
* Used to publish Algae poses from MapleSim.
*/
private final StructArrayPublisher<Pose3d> algaePoses = NetworkTableInstance.getDefault()
.getStructArrayTopic("FieldSimulation/Algae", Pose3d.struct)
.publish();
/**
* Used to publish Coral poses from MapleSim.
*/
private final StructArrayPublisher<Pose3d> coralPoses = NetworkTableInstance.getDefault()
.getStructArrayTopic("FieldSimulation/Coral", Pose3d.struct)
.publish();

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
Expand Down Expand Up @@ -110,9 +133,24 @@ public void testPeriodic() {}

/** This function is called once when the robot is first started up. */
@Override
public void simulationInit() {}
public void simulationInit() {
// Add game pieces to MapleSim
SimulatedArena.getInstance().addGamePiece(new ReefscapeCoral(
// We must specify a heading since the coral is a tube
new Pose2d(2, 2, Rotation2d.fromDegrees(90))));

SimulatedArena.getInstance().addGamePiece(new ReefscapeAlgaeOnField(new Translation2d(2, 2)));
}

/** This function is called periodically whilst in simulation. */
@Override
public void simulationPeriodic() {}
public void simulationPeriodic() {
SimulatedArena.getInstance().simulationPeriodic();

// Send game piece locations from MapleSim
algaePoses.accept(SimulatedArena.getInstance()
.getGamePiecesArrayByType("Algae"));
coralPoses.accept(SimulatedArena.getInstance()
.getGamePiecesArrayByType("Coral"));
}
}
52 changes: 24 additions & 28 deletions vendordeps/maple-sim.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
{
"fileName": "maple-sim.json",
"name": "maplesim",
"version": "0.2.8",
"frcYear": "2025",
"uuid": "c39481e8-4a63-4a4c-9df6-48d91e4da37b",
"mavenUrls": [
"https://shenzhen-robotics-alliance.github.io/maple-sim/vendordep/repos/releases",
"https://repo1.maven.org/maven2"
],
"jsonUrl": "https://shenzhen-robotics-alliance.github.io/maple-sim/vendordep/maple-sim.json",
"javaDependencies": [
{
"groupId": "org.ironmaple",
"artifactId": "maplesim-java",
"version": "0.2.8"
},
{
"groupId": "org.dyn4j",
"artifactId": "dyn4j",
"version": "5.0.2"
}
],
"jniDependencies": [

],
"cppDependencies": [

]
"fileName": "maple-sim.json",
"name": "maplesim",
"version": "0.3.1",
"frcYear": "2025",
"uuid": "c39481e8-4a63-4a4c-9df6-48d91e4da37b",
"mavenUrls": [
"https://shenzhen-robotics-alliance.github.io/maple-sim/vendordep/repos/releases",
"https://repo1.maven.org/maven2"
],
"jsonUrl": "https://shenzhen-robotics-alliance.github.io/maple-sim/vendordep/maple-sim.json",
"javaDependencies": [
{
"groupId": "org.ironmaple",
"artifactId": "maplesim-java",
"version": "0.3.1"
},
{
"groupId": "org.dyn4j",
"artifactId": "dyn4j",
"version": "5.0.2"
}
],
"jniDependencies": [],
"cppDependencies": []
}
Loading