Hi all, so I was trying to figure out how to simulate REV motors using the WPILIB template as a model. I revised it so that the simulation could run with REV motors. However I don’t exactly know how to implement REVLib into the simulation code. I am considering using REVPhysicsSim to simulate a swerve drivetrain model and a single jointed motor arm. Is it possible to simulate robot code with/without using REVPhysicsSim if we are using NEOs and is there template code that I can model off of? We are using Java.
what’s your simulation objective? if you just want something that behaves kinda like a motor, you don’t need a vendor simulation at all.
WPILib has a DCMotor class with an instance representing the characteristics of a NEO motor. A DCMotor is an input to the DCMotorSim class which represents a motor-driven mechanism. You can simulate a swerve module or arm with these classes without using REVPhysicsSim. An example for a swerve module is the AdvantageKit swerve drive example code. The AdvantageKit example also has code for simulating a flywheel such as a shooter, but it does not have an arm. Here is some arm simulation code I happened to find which is structured like the AdvantageKit swerve example and uses NEOs. There are lots of other examples on GitHub.
As said, there exists the DCMotorSim, SingleJointedArmSim and ElevatorSim classes for simulating the motors on various mechanisms. You might be confusing these with vendor simulation, which isn’t really “simulation” per-se; rather, it simply acts as a way for you to directly get simulated outputs from that motor class by supplying the outputs of a DCMotorSim, SingleJointedArmSim, etc. to the motor in the simulationPeriodic() function.
REV doesn’t really have vendor simulation, but ctre does.
REV has the REVPhysicsSim class, which does actually calculate the physical values given a DCMotor.
If they’ll alow for other types of simulations (SingleJointed, etc.) or move to the way CTRE does sim it’ll probably be much better though.
Problem with the REVPhysicsSim is, it only updates the velocity value. It doesn’t iterate any other value, like position or bus voltage.
We never had much luck with REVPhysicsSim, so we use the SimDeviceSim API and a wrapper class (CANSparkMaxSim) to simulate REV motors and encoders. One caveat is that you can’t use get() to read back the motor voltage, so we save it in a variable whenever it is set. Here is an example of the WPILib ArmSimulation example modified to use a SparkMax controller this way.