Skip to content

Simulation(MapleSim)

Charles Kennedy edited this page Jan 2, 2026 · 1 revision

Things you need

  • Make sure you have the MapleSim vendor installed
  • PhoenixUtil file(will be in common library soon)
  • The rest of the module's code completed

Different simulation modules

You will need a wpilibj simulation object to do a lot of the simulation stuff so you don't have to.

DCMotorSim is to simulate an individual motor

MapleMotorSim is to simulate a motor but with a bit more physics

FlywheelSim is to simulate shooter mechanisms

ElevatorSim is to simulate elevator mechanisms

LinearSystemSim is for mechanisms with linear change in forces

SingleJointedArmSim is for simulating mechanisms that rotate around a single joint such as an arm, shooter mount, or an intake mount

IntakeSimulation is for simulating intake mechanisms, this one functions a bit differently than the others as it is not made by WPI so a lot of the methods are different

SwerveDriveSimulation is for simulating swerve, like intake simulation it is made by MapleSim instead of WPI so the methods are different

SimulatedBattery this simulates the battery and it draining over time, if you want to get a rough estimate of when your robot will experience a brownout, use this (I don't know how accurate this is)

SimulatedMotorController is for simulating the motor controller, you will generally need this for all mechanisms(except pneumatics)

IOSim constructor

You will need to define your simulated module which will look something like this:

ElevatorIOSim(){
//Last one is for simulating gravity, the parameters will depend on the module
this.elevatorSim = new ElevatorSim(elevatorGearbox, elevatorGearingReduction, elevatorMass, drumRadius, elevatorMinHeight, elevatorMaxHeight, true);
this.simulatedMotorController = new SimulatedMotorController.GenericMotorController(elevatorGearbox);
SimulatedBattery.addElectricalAppliances(this::getSupplyCurrent);
elevatorSim.update(0.0)
}

updateInputs method

Then you will need to make a updateInputs method to have the simulation update the IO data which will look something like this:

@Override
public void updateInputs(ElevatorIOInputs inputs){
Voltage realVoltage = motorController.constrainOutputVoltage(elevatorPosition, elevatorVelocity, targetVoltage);
realVoltage = SimulatedBattery.clamp(realVoltage);
inputs.elevatorData = new ElevatorIOData(
true,//Main Motor Connected
true,//Follower Motor Connected
elevatorPosition.in(Rotations),
realVoltage.in(Volts), //Main Motor Voltage
elevatorVelocity.in(RotationsPerSecond), //Main Motor Velocity
getSupplyCurrent().in(Amps), //Main Motor Current
realVoltage.in(Volts), //Follower Motor Voltage, usually you can mirror if it is a follower motor
elevatorVelocity.in(RotationsPerSecond), //Follower Motor Velocity
getSupplyCurrent().in(Amps)); //Follower Motor Current
}

Clone this wiki locally