How to use SparkMax encoders

Hello, I am very early beginner to coding in LabVeiw, and I’m trying to use SparkMax encoders to help me write accurate auto-code, but I can’t find anything anywhere!

If anyone knows how to:
A. Set an encoder up on a SparkMax (which is connected to a Neo)
B. Draw values from it that I can use in auto

Please comment on this post so I can learn how!

1 Like

Take a look at the Rev SparkMax example code to Read Encoder Values here: SPARK-MAX-Examples/LabVIEW at master · REVrobotics/SPARK-MAX-Examples · GitHub

Okay perfect, my encoder is now reading, but how can we use those values from the encoder in our auto code? I couldn’t really find any examples on that anywhere…

For example: I want to run my motors until we hit 15 revolutions.

Something like this in Autonomous Independent.vi
I’d usually translate revolutions into inches traveled as that’s easier to think about and measure,
e.g., either calculate it or push the robot a measured distance and see what value Left Motor Rotations ends with.

Wow, thank you so much! I’ll give it a shot and tell you if it works!

Watch the value of Left Motor Rotations when you try this.
The value may be negative depending on direction, so you may need to add a check for (< -15) as well, e.g., > 15 or < -15

1 Like

Okay, I’ll watch for that

Okay, the motors will run in our auto, but they won’t stop after 15 rotations. I’ve tried <-15 and >15 but neither seem to work. No errors appear in the driver station. I just copied the screenshot so I don’t exactly know what the problem could be, mind helping out again?

Nevermind, I think we got it all to work! Something in the begin.vi files was messing with it, thank you very much!

Great!

We have gotten it working now, however I am trying to write it myself but I don’t know how you got the DBL for the motor rotations. If you could explain how you got it that would help a lot!

That’s just a right-click and “Create indicator” on the output node.
It’ll first appear a little different and will work fine, but there is a show as icon selection that just makes it smaller.

1 Like

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