We are doing swerve for the first time using the SDS template code as a starting point. After some tinkering and looking at a lot of other team’s code, it is working pretty well. Still some issues to work out but the biggest problem right now is simulation.
The drive and steer SparkMax (Neos) are configured with REVPhysicsSim.getInstance().addSparkMax(motor, DCMotor.getNEO(1)) and in the SimulationPeriodic function we call REVPhysicsSim.getInstance().run(). This sort of works. There two problems we are seeing.
First, the drive SparkMax do show simulated values when the code is run under sim. However, the velocity returned from the SparkMax encoder
getVelocity() method is totally wrong. Looking at the Other Devices simgui display for a drive SparkMax, the velocity pre-conversion is set to the Free Speed value at very small input voltages. The velocity is effectively always the free speed until we reverse direction. Then the velocity jumps to a very high negative number, like one with 8 digits. The drive SparkMax are controlled with the setVoltage() method.
Second, the SparkMax used for steering do nothing at all. All values stay zero. The steering is done using the SparkMax onboard PID controller via setReference() method using the default pid slot. Now I have seen other team examples where the onboard PID is shifted to pid slot 3 when under sim. I have found no doc or code comments or posts that explain what that slot shift is all about so our code is not doing that.
I have looked at the available documentation and searched CD and found all kinds of information but nothing that appears to address these symptoms directly. Thanks for any help!