Hello SparkMax/Neo experts,
My team is using a chassis with 6 Neo/Spark Max controllers in a three left, three right configuration. We are assigning the 2 of 3 to follow the third as master for each side. While debugging adding current and rate limits to the groups I noticed a problem with the follower configuration. It seems that only one of the two followers would take the assignment. This was consistent for both sides
Code is simple – define the controllers
// CANSpark Max will be used 3 per side, 2 folowing the leader
private final CANSparkMax frontRight = new CANSparkMax(FR_SPARKMAX_CANID, CANSparkMaxLowLevel.MotorType.kBrushless);
private final CANSparkMax frontLeft = new CANSparkMax(FL_SPARKMAX_CANID, CANSparkMaxLowLevel.MotorType.kBrushless);
private final CANSparkMax backRight = new CANSparkMax(BR_SPARKMAX_CANID, CANSparkMaxLowLevel.MotorType.kBrushless);
private final CANSparkMax backLeft = new CANSparkMax(BL_SPARKMAX_CANID, CANSparkMaxLowLevel.MotorType.kBrushless);
private final CANSparkMax middleRight = new CANSparkMax(MR_SPARKMAX_CANID, CANSparkMaxLowLevel.MotorType.kBrushless);
private final CANSparkMax middleLeft = new CANSparkMax(ML_SPARKMAX_CANID, CANSparkMaxLowLevel.MotorType.kBrushless);
private final CANSparkMax[] controllers = new CANSparkMax[] { frontRight, frontLeft, backRight, backLeft,
middleRight, middleLeft };
Set the followers -
// Have motors follow to use Differential Drive
CANSparkMax rMaster = backRight;
err=middleRight.follow(rMaster);
err=frontRight.follow(rMaster);
//err=backRight.follow(rMaster);
err=middleRight.follow(rMaster); //### hack - treat it like a teenager
CANSparkMax lMaster = backLeft;
err= middleLeft.follow(lMaster);
err= frontLeft.follow(lMaster);
//backLeft.follow(lMaster);
err = middleLeft.follow(lMaster); //### hack - tell them twice
I tried switching what was following what, it didn’t matter, only ever saw 2 of three lights work together. Even tried telling the missing controller a 2nd time… hack I know. That didn’t work either.
I suspect there is a timing problem because when I added the error capture and stepped through with the debugger, both sets of 3 where configured and ran correctly. That is, all the controllers showed Red/Green lights when commanded to move. Running code at full speed, only saw 2 of 3 lights again.
Stepping through with the debugger clearly changed the message timing to the devices.
This platform has 10 CAN devices: 6 spark max, PDP, talonSrx, RIO, and a PCM. All devices show up correctly on the CTR or SparkMax Client monitor tools. (I wish CTR and Rev would report other devices on each other’s tools).
When enabling current limits and/or rate limits I was sending the values to all 6 of the SparkMax controllers. See code below. Is this needed? Can I just send the updates to the lead controller? That would be the preference.
Do the followers simply listen for all commands as if they were on the master’s ID?
public double adjustAccelerationLimit(double deltaRate) {
rateLimit = MathUtil.limit((rateLimit + deltaRate), 0.0, RATE_MAX_SECONDS);
for (CANSparkMax c : controllers) {
c.setOpenLoopRampRate(rateLimit);
}
SmartDashboard.putNumber("motorRate", rateLimit );
return rateLimit;
}
Given my assumption about CAN timing, this could be a problem. We intend to adjust the values in the real-time loop for tuning/trimming behavior.
When this code was run with a .5 second rateLimit the motor cluster started jerking and not moving well. Is this a known issue or any ideas what the cause could be?
Similar code was used to set the smartCurrentLimit and secondary current limits without any perceived problem, but we weren’t able to test the current limits were actually working yet.
The rate limit setting caused the whole drive train to stutter like the motors were fighting or simply dropping out.
Any suggestions would be great.
Full code: https://github.com/2202Programming/FRC-2020/tree/Larry
DriveTrain code: https://github.com/2202Programming/FRC-2020/blob/Larry/FRC-2020/src/main/java/frc/robot/subsystems/VelocityDifferentialDrive_Subsystem.java
Thanks for the help,
Derek