configure encoder in can

our team is switching over to can with the talons srx, our drive system works well using master/follower. my question is how do i configure my cui encoder which is attached to my talon. I’ve read the manuals and perused through git hub but i’m looking for a begin example and an autonomous example. I would like to move 120" using 6" wheels. Thanks.

The encoder config at the bottom right of your screenshot has an easily corrected error. You’ve used a RefNum Set function instead of a RefNum Get. Notice the direction of the arrow in the motor control (MC) icon? It’s going into the refnum registry, where it needs to be coming out of it.

However, while that will correct the syntax error and let it run, it still won’t work properly. The problem is that you’re trying to read from the registry at the same time everything else in Begin is running, and the Left Drive Motor probably won’t have had time to be opened and set yet. There’s another easy fix for that, though. Instead of using a RefNum Get function to obtain the reference to the Talon, just wire the reference directly from the output of the Talon Open to the input of the Config Sensor function. Take it from the same place you’re getting the wire to the Follow function.

Rule of thumb: RefNum Set functions go in Begin and nowhere else. RefNum Get functions go everywhere else and never in Begin.

I didn’t find it worthwhile to setup the encoders for the Talon in You can do it, I think connecting it directly is a better practice, like Alan mentions. But instead I prefer to setup the encoders in Periodic, because you will want to get updated encoder readings. I write these to Robot Global, which allows them to easily be accessed either in or Autonomous

Here is an example of that:

The math afterwards is converting (roughly) for 6" wheels from pulses to inches, but for a 4096 pulses per revolution. I’m not sure about the CUI AMT103-V, but think it might be 2048. You can see once you have code up and running.

For autonomous to go 120", you will need some code to drive for distance, by comparing your encoder value to your setpoint (120"). PID is a typical way to address this, and here is code I’ve used:

Just place it somewhere in your autonomous case, and you can use the error in/error out to control the sequence.

Notes: 1) The gyro code might need disabled. It is for helping drive straight by compensating with the gyro, but uses some additional code. 2) The loop speed on the first snippet is at 50 mS, which is possibly a little slow, especially when mismatched with the 5 mS speed for the PID loop. 3) You’ll want to tune the PID gains.

Thank you
I will try it tomorrow.