MapleSIM Strange Behavior (Need Help)

Alright, so I implemented MapleSIM into our codebase, pretty simple. basically just copied the AdvantageKit Talon Swerve Template - Enhanced Version template.

The weird thing is when trying to change the values to our actual swerve values it does this weird slow movement thing and then dissapears entirely. I know SPAM has encountered this same issue aswell.

heres a link to a video and the log file
https://drive.google.com/drive/folders/1NrHoKot1Q0oUVSRLllvt3iKhxLKceK6H?usp=sharing
lmk if you can’t access it but you should be able to.

heres the whole codebase:
https://github.com/10219Ryba/REEFSCAPEFIX

As you can see, it works when using a Falcon500 as the steer, and the steerGearRatio being 15.42857142857143, which was just the default in the template.

Has anyone encountered an issue similar?
I think it’s something to do with the steerInertia based off the log file.

2 Likes

@catrix

2 Likes

Unfortunately, the simulated PIDs are different from real-life ones. So, any alterations to the motors and mechanisms in the simulation would require retuning the simulated PIDs.

3 Likes

This is a known issue: [BUG]-Swerve Module motor selection leads to NaNs · Issue #86 · Shenzhen-Robotics-Alliance/maple-sim · GitHub

3 Likes

Hey!

I noticed your repo is private, so I can’t run the simulation rn.

It looks like it’s the swerve simulation being jittery. I’m sorry to say that MapleSim and Phoenix motor simulations haven’t been playing nice together. For now, I’m afraid your best option is probably to stick with the default configuration.

Since simulation is to make sure that your code works correctly (which it should regardless of the swerve motor), you shouldn’t stress too much about it :grinning:

Update: After playing around a little, I found a few tricks that might be useful for you:

1: Changing Steer Inertia and Friction Voltage for maple-sim

In Drive.java, change the maple-sim drivetrain configuration to:

public static final DriveTrainSimulationConfig mapleSimConfig = DriveTrainSimulationConfig.Default()
        .withRobotMass(Kilograms.of(ROBOT_MASS_KG))
        .withCustomModuleTranslations(getModuleTranslations())
        .withGyro(COTS.ofPigeon2())
        .withSwerveModule(new SwerveModuleSimulationConfig(
                DCMotor.getKrakenX60(1),
                DCMotor.getKrakenX60(1),
                TunerConstants.FrontLeft.DriveMotorGearRatio,
                TunerConstants.FrontLeft.SteerMotorGearRatio,
                Volts.of(0.3), // Change drive friction voltage to 0.3
                Volts.of(0.5), // Change steer friction voltage to 0.5
                Meters.of(TunerConstants.FrontLeft.WheelRadius),
                KilogramSquareMeters.of(0.05), // Change steer intertia to 0.05
                WHEEL_COF));

2: Making the steer closed-loop run at 50HZ

In the constructor of ModuleIOTalonFXSim.java, add these two lines:

public ModuleIOTalonFXSim(
        SwerveModuleConstants<TalonFXConfiguration, TalonFXConfiguration, CANcoderConfiguration> constants,
        SwerveModuleSimulation simulation) {
    super(...);

    ... // Other Code not shown
        
    // Set steer control loop to run at 50Hz and turn off CTRE-CAN-Time-Synchronization
    super.positionTorqueCurrentRequest.withUpdateFreqHz(50.0).withUseTimesync(false);
    super.positionVoltageRequest.withUpdateFreqHz(50.0).withUseTimesync(false);
}
1 Like

Thankyou!