Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Programming US Digital Encoder (http://www.chiefdelphi.com/forums/showthread.php?t=133530)

TimTheGreat 26-01-2015 15:54

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.

Code:

self.talon = wpilib.CANTalon(15)
        self.talon.changeControlMode(CANTalon.ControlMode.Position)
        self.talon.setFeedbackDevice(CANTalon.FeedbackDevice.EncFalling) #Not sure if the encode is EncFalling or Quad
        self.talon.reverseSensor(True)
        self.talon.setP(1)
        self.talon.setPosition(0)

and in OperatorControl

Code:

  self.talon.set(270)
But when I enable the DS, the motor just keeps spinning, and the value goes past 270.

Thad House 26-01-2015 15:59

Re: Programming US Digital Encoder
 
Quote:

Originally Posted by TimTheGreat (Post 1434237)
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.

Code:

self.talon = wpilib.CANTalon(15)
        self.talon.changeControlMode(CANTalon.ControlMode.Position)
        self.talon.setFeedbackDevice(CANTalon.FeedbackDevice.EncFalling) #Not sure if the encode is EncFalling or Quad
        self.talon.reverseSensor(True)
        self.talon.setP(1)
        self.talon.setPosition(0)

and in OperatorControl

Code:

  self.talon.set(270)
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.

Alan Anderson 26-01-2015 16:39

Re: Programming US Digital Encoder
 
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.

ozrien 26-01-2015 17:00

Re: Programming US Digital Encoder
 
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?

TimTheGreat 26-01-2015 17:52

Re: Programming US Digital Encoder
 
Quote:

Originally Posted by Thad House (Post 1434241)
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?

Can you explain how you came up with 80 degrees?


Quote:

Originally Posted by ozrien (Post 1434285)

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

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

Thad House 26-01-2015 17:58

Re: Programming US Digital Encoder
 
Quote:

Originally Posted by TimTheGreat (Post 1434303)
Can you explain how you came up with 80 degrees?

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.

ozrien 26-01-2015 18:00

Re: Programming US Digital Encoder
 
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.


All times are GMT -5. The time now is 01:40.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi