We have two spark max motor controllers that we need to change the leader/follower status of
motor1.follow(motor2);
motor2.set(1) // works fine
// later in the code
motor2.follow(motor1);
motor1.set(1) // nothing spins
Other than resetting the defaults and reconfiguring both motors, is there a way to change which motor is following which?
Why do you want to change the leader?
Yeah I’d really like to better understand the reasoning for this. I don’t believe this is supported (without resetting/reconfiguring at least). I can’t think of a valid reason anyone would want to do this though.
Our use case is two spark maxes in a gearbox, one with a relative encoder (m1), one with a reverse limit switch (m2). Ideally we’d set m2 to be the leader during zeroing, allowing the limit switch to stop the motor and that stoppage to be sent to m1. After zeroing, m1 becomes leader and uses soft limits.
What we ended up doing was disabling the limit switch, but reading its value while controlling m1, zeroing the encoder, setting soft limits, and going about our day. Works fine because the mechanism is slow, and there isn’t much delay in the limit switch.
But I would’ve liked to get my original method working so that if I needed to use the hard limits, I could.
Does the SparkMax API not allow enabling/disabling the hard limit switch? That seems much easier
It does, but if the limit is reached on m2 while m1 is leader, it doesn’t stop m1. Hence the want to make m2 the leader until encoders were zeroed.
Seems silly to not have a way to remove a follower of a motor
Right, so wire the limit to m1, keep it as the leader, and simply enable/disable as needed
You can’t use alternate encoders and limit switches together on spark max. Conflict with the pinout
Ahhh okay, i missed where it was an alternate encoder. Out of curiosity, any reason the built-in one doesnt work for you? If you needed absolute, I’d understand completely (though I don’t believe that has the same pin conflict)
We wanted to read the position closer to the output, especially with the backlash in the gearbox. We’re even swapping the gearbox for the maxplanetaries and will actually not have the alternate encoder by default, so the original use case of this problem has pretty much gone away. But I’m sure it’ll pop up again eventually, either for us, or someone else.
I’m pretty confident you could change the follower with the API, but I think you’d be better off not messing with the configuration during operation. Instead just read the limit switch over CAN to the RIO and do your logic there. You can read the state of the follower limit switch over CAN.
1 Like
stupid idea, but could you just swap which motor is connected to which spark max.
No, I’m not sure what that would solve