Confusion about the spark max api

My team’s robot has an arm that is powered by two Neos facing in opposite directions, and we’re unsure what the best way to control them is.

The first thing we tried was using a leader and a follower motor. This didn’t work because the motors spun in the same direction, even when we set one of the motors to be inverted.

The next thing we tried was to invert one of the motors, but not use leaders/followers and instead directly set the voltage on both motors. This worked fine initially, with a positive voltage making the arm go up.

We wanted our arm to never be command to go below its starting position, and we tried adding soft stops, resulting in this code:

left.setInverted(true);
right.setInverted(false);

// encoders measure in degrees of arm rotation
left.getEncoder().setPositionConversionFactor(360 * gearbox);
right.getEncoder().setPositionConversionFactor(360 * gearbox);
left.getEncoder().setPosition(0);
right.getEncoder().setPosition(0);

left.setSoftLimit(SoftLimitDirection.kReverse, 0);
right.setSoftLimit(SoftLimitDirection. kReverse,  0);

left.enableSoftLimit(SoftLimitDirection. kReverse, true);
right.enableSoftLimit(SoftLimitDirection. kReverse, true);

But this seemed to only allow one motor to move (I’d love to have more certainty about what was happening but we were very strapped for time).

Two questions:

  1. Is there a way to make a follower motor run in the opposite direction of its leader?
  2. Does our soft stop code look sensible, or is there a weird interaction between motor inversion and soft stops that we are missing? (For example should one of the soft stops be kForward because the motor is inverted)

Full disclaimer: I have never worked with soft limits with these motors. The closest thing I have done is simply to check if a motor’s encoder shows anything more/less than a specified value, and handle it from there.

That said, have you tried using SoftLimitDirection.kForward on either of the motors? My guess would be the inverted one.

You may want to try setting inversion by using the two parameter form of follow().

Ahhh thank you, I figured there was a way to do this I was missing. Do you happen to know how this interacts with soft stops? Should one of the soft stop directions be backwards, or can I just leave soft stops off of the follower motor?

We haven’t tested that yet. It’s on the list of things to test, but programming is getting limited time on our team’s robot right now because of mechanical issues.

I’m kinda hoping someone just knows this off the top of their head :slight_smile:

So far as I know, the follower should stop when the leader is stopped.

Oh lovely that makes things easy then. Thank you!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.