Not sure if anyone else has noticed this;
With nothing plugged into the CAN Bus port on the RoboRio;
When I create a CANSparkMax object, and try to access its encoder value with getEncoder().getVelocity() in a loop such as robotPeriodic, it floods the CAN TX queue and the program crashes with a somewhat unhelpful error.
Program stops crashing when something is plugged into the RoboRio CAN Bus port
We will need the log file (eg /tmp/hs_err_pid5754.log), as this doesn’t have enough info. This will be lost when the RoboRIO is powered off. The file will change names each time. You can use a ftp client such as FileZilla to copy it off the Rio.
To be clear, I doubt the Talon SRXes were involved in your crash. This is something we rigorously test.
Our [CTRE] CAN actuators are designed to not crash rio-side software, even if there is no physical CAN bus. I can’t reproduce this, and have not heard of this before. Please send me the steps to reproduce this.
I was able to reproduce with the following minimal code:
public class Robot extends TimedRobot {
private CANSparkMax sm = new CANSparkMax(1, MotorType.kBrushless);
@Override
public void robotPeriodic() {
sm.getEncoder().getVelocity();
}
}
It looks like getEncoder allocates a new object each call.
public CANEncoder getEncoder() {
return getEncoder(EncoderType.kHallSensor, 0);
}
public CANEncoder getEncoder(EncoderType sensorType, int counts_per_rev) {
return new CANEncoder(this, sensorType, counts_per_rev);
}
If I change it to only allocate once, it doesn’t crash.
public class Robot extends TimedRobot {
private CANSparkMax sm = new CANSparkMax(1, MotorType.kBrushed);
private CANEncoder enc = sm.getEncoder();
@Override
public void robotPeriodic() {
enc.getVelocity();
}
}
My note about TalonSRX’s was simply meant to add information to the main report, which said the problem occurred when “nothing plugged into the CAN Bus port on the RoboRIO”. I just wanted to add that the problem could still occur if you had other devices, such as the TalonSRX, plugged into the RoboRIO when trying to call getEncoder().getVelocity() on a Spark MAX.