Reading Spark MAX encoders (Labview)

Hello, I’m currently trying to add encoders into autonomous so I can have the robot stop after it goes a certain distance. I know that I need to use encoders for this, and I know that our Spark MAXs already have encoders built in. However, I have no idea how to access these encoders in either the code or wiring. While I’m not entirely sure if the wiring needs to be changed, I’ll keep to the programming side of it first;

how do I read the encoder values for our spark MAX drive train in LabVIEW?

(I tried looking at the encoder example code in Labview and noticed that it used DIO inputs, however we don’t have any DIOs plugged in, which is where my confusion with the wiring comes in- our current drive train uses a CAN loop, not DIOs)

Just want to verify a couple of things on your setup:

  1. You indicate that you are using Spark MAXs. I want to make sure you are using the Spark MAX to control a NEO motor. If you are using the Spark MAX to control a CIM/mini-CIM a separate encoder will be needed.

  2. Do you have the third-party library from REV installed? The VIs you will need are included in the third party library.

Check out the SparkMax docs
Here is a code snippet from there:

Yes, I’m controlling NEO motors. Could you specify which library you mean? I have the libraries for the Spark MAXs (I can control them in teleop already) but I’m not sure if you mean a different one

I tried recreating that in the code, however I’m not getting any readings on the encoders. Our drive train has 4 motor controllers (two motors to one wheel), could that be the issue?

Did you change the reference name from drive motors to the one you’re using?

1 Like

Please screenshot the code as you recreated it. The code above is intended to be in the Periodic Tasks VI due to the while loops and delay functions.

Also check what errors you’re getting on the driver station log. There is a particular error that you would get if there was inconsistent spelling or a hidden space, etc.

I don’t know if this helps, but for last year’s code we made like this


periodic tasks