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:
- Is there a way to make a follower motor run in the opposite direction of its leader?
- 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)