CANTalonSRX simulation not working

I was writing some test code, ran it through the simulator (which I seldom use).

It appears that CANTalonSRXs are supported in the simulator (if I instantiate one in the code, it shows up in the simulator GUI), but .set() method calls do not seem to change the “applied power” for that controller in the simulator.

What am I doing wrong? Motor power should change as I switch between auto, teleop, test, and disabled with this program:

package frc.robot;

import com.revrobotics.CANSparkMax;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;

public class Robot extends edu.wpi.first.wpilibj.TimedRobot {
  CANSparkMax motor;
  
  @Override
  public void robotInit() {
    motor = new CANSparkMax(1, MotorType.kBrushed);
  }

  @Override
  public void autonomousPeriodic() {
    motor.set (-1);
  }

  @Override
  public void teleopPeriodic() {
    motor.set (1);
  }

  @Override
  public void disabledInit() {
    motor.stopMotor();
  }

  @Override
  public void testPeriodic() {
    motor.set (0.5);
  }
}

I’m a little confused, you say TalonSRX but your code has SparkMax

1 Like

So there may be a few issues. Rev’s simulation support is generally pretty lackluster and people have written basic libraries to workaround some of its limitations (I cant vouch specifically for any of these libraries) . If you are looking to use strictly Revs simulation support it only supports control modes of kVelocity and kVoltage.

To use revs simulation support you need to make calls to the RevPhysicsSim.getInstance() to both add motor controllers and periodically update the physics loop. Some sparse documentation on how this works is available Here The device showing up within WPI-libs sim window does not necessarily mean that the vender simulation is working. Just that it has support for wpilib’s, SimDevice api.

2 Likes

yeah, the SparkMax thingy is what I meant.

ah. replaced the calls to .set with calls to .setVoltage, and things are as expected.

using .setVoltage() is smarter anyway, it helps with conpensating for battery voltage sag…

thanks!

1 Like

Absolutely, it also has the added benefit of making PIDF coefficients have reasonable units.

1 Like