Inverting Rev spark max encoder Neo hall effect sensor?

Hello,

We have a few projects going right now. One is running through 6814s excellent 0-auto tutorial. our new coders are making some excellent progress. However, we are not able to successfully invert the integrated encoder readings for the left side of our drivetrain. When we try to use encoder.setInverted(); both lint and gradle throw an error (I do not remember the error they were getting, unfortunately, but it led us to believe the method needs a different variable than true or false).

Here is our code (we just ended up multiplying the outbput by -1 for now),

Anyway, does anyone know the correct method to call?
Thank you for your help,
R2

You should be setting the CANSparkMax to inverted not the encoder.

Would be something like (off the top of my head)

in the class definition you should have something like this

private final CANSparkMax m_motor = new CANSparkMax(ID, MotorType.kBrushless);

Then in your constructor you can set the following

m_motor.setInverted(true):
m_motor.burnFlash();

When you invert the motor it automatically will invert encoder readings so that a positive input results in positive direction motion from the NEO.

2 Likes

Thank you. That makes sense. As I look at the code, we were reversing the motor manually hence the discrepancy. So, when you invert the motor, it inverts the sensor automatically?

Yep. It wouldn’t make sense for the sensor and the motor to be out of phase so they are coupled automatically.

1 Like

So, that totally explains why we could not figure it out doh!!! Thank you both so much.

1 Like

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