Go to Post Sometimes, it takes years to gain respect and to learn to understand the opportunities that avail themselves to those who pay attention, are willing to learn from the best, and dig deeper into understanding what it means to be a competitive FRC team. - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 26-01-2015, 15:54
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
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.
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #2   Spotlight this post!  
Unread 26-01-2015, 15:59
Thad House Thad House is offline
Volunteer, WPILib Contributor
no team (Waiting for 2021)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Thousand Oaks, California
Posts: 1,106
Thad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond repute
Re: Programming US Digital Encoder

Quote:
Originally Posted by TimTheGreat View Post
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.
__________________
All statements made are my own and not the feelings of any of my affiliated teams.
Teams 1510 and 2898 - Student 2010-2012
Team 4488 - Mentor 2013-2016
Co-developer of RobotDotNet, a .NET port of the WPILib.
  #3   Spotlight this post!  
Unread 26-01-2015, 16:39
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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.
  #4   Spotlight this post!  
Unread 26-01-2015, 17:00
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 531
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
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?
  #5   Spotlight this post!  
Unread 26-01-2015, 17:52
TimTheGreat's Avatar
TimTheGreat TimTheGreat is offline
ArchdukeTim
FRC #1418 (Vae Victis)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2011
Location: Falls Church
Posts: 238
TimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura aboutTimTheGreat has a spectacular aura about
Re: Programming US Digital Encoder

Quote:
Originally Posted by Thad House View Post
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 View Post

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
__________________
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.



2012 - Gracious Professionalism - Greater DC
2014 - Regional Finalist - Virginia | Industrial Design - Virginia | Regional Finalist - Greater DC
2015 - Innovation in Control - Greater DC
2016 - District Event Winner - VAHAY | Innovation in Control - VAHAY | District Event Winner - MDBET | Industrial Design - MDBET | District Champion - CHCMP | Innovation in Control - CHCMP
  #6   Spotlight this post!  
Unread 26-01-2015, 17:58
Thad House Thad House is offline
Volunteer, WPILib Contributor
no team (Waiting for 2021)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Thousand Oaks, California
Posts: 1,106
Thad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond repute
Re: Programming US Digital Encoder

Quote:
Originally Posted by TimTheGreat View Post
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.
__________________
All statements made are my own and not the feelings of any of my affiliated teams.
Teams 1510 and 2898 - Student 2010-2012
Team 4488 - Mentor 2013-2016
Co-developer of RobotDotNet, a .NET port of the WPILib.
  #7   Spotlight this post!  
Unread 26-01-2015, 18:00
ozrien's Avatar
ozrien ozrien is offline
Omar Zrien
AKA: Omar
no team
Team Role: Mentor
 
Join Date: Sep 2006
Rookie Year: 2003
Location: Sterling Heights, MI
Posts: 531
ozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond reputeozrien has a reputation beyond repute
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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 21:03.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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