Programming US Digital Encoder

So I am trying to get a motor to go to a certain position using the encoder provided by US Digital, and am having trouble.

self.talon = wpilib.CANTalon(15)
        self.talon.setFeedbackDevice(CANTalon.FeedbackDevice.EncFalling) #Not sure if the encode is EncFalling or Quad

and in OperatorControl


But when I enable the DS, the motor just keeps spinning, and the value goes past 270.

You do want to be using Quad for an encoder like that.

Remember that the encoder is always in 4x mode, which means that 1 rotation of the shaft is 1440 pulses is using a 360 CPR encoder. Moving from 0 to 270 is only moving the output shaft about 80 degrees. Is that what you want?

Also, the P gain needs to be a much smaller number then 1. With a P gain of one, your motor will always be moving at a full speed. I would recommend using a P gain of 0.01, if not 0.001 to start with, then start increasing from there if its not moving fast enough, or at all.

Put some sort of mechanical load on the motor when you’re trying out closed-loop position control. If you don’t, it’s going to overshoot. A lot.

You’re sensor is not single-direction (not a tachometer). So you want to select Quad-encoder. That’s part of the problem.

So you’re initial closedloopErr is +270 ( target - currentPos), such that currentPos is about ‘0’. 270 times a pgain of ‘1’ will yield ‘270’. That’s about 26% positive throttle (1023 is full, see Duty-Cycle Section 17.5 in software reference manual). So I think that’s ok.

Also I see that you reversed the sensor. I’m guessing you followed the procedure in section 7.4 (or similar) to ensure that positive throttle makes “Sensor Position” move in the positive direction.

Just curious how did you hookup the encoder to the motor mechanically. I mean what’s the gear ratio between the two?

Can you explain how you came up with 80 degrees?

So for testing I have it hooked up to a super shifter. On the actual robot we will have it on a planetary gearbox which is 16:1 I believe

One rotation of the output shaft is 1440 pulses. Thats 0.25 degrees per pulse. 0.25 * 270 pulses is 67.5 Degrees to be exact. The 80 was more a guess just by looking at the ratio, but I guess I was a little off. Its 67.5 Degrees.

Cool. You should be able closed loop position with that. I’ve tested closed-looping a quad encoder right to the output shaft of a CIM (>5000 rpm) using the S4 encoder (360 cpr) so that’ll work.

My math says : 360cpr = 1440 position units per rotation.
270 / 1440 = 0.1875 rotations or 67.5 deg.

Also checkout section 11.2 for checking on the closed-loop err and the applied throttle to sanity check your closed-loop.