Go to Post I mean, there is a 40 second period where your alliance has to play defense, so you might as well play it well. - Jeff Rodriguez [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-02-2015, 22:15
Chaube97 Chaube97 is offline
Registered User
FRC #4859
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Byron, MN
Posts: 7
Chaube97 is an unknown quantity at this point
Using Encoders with TalonSRX

Hi,
I'm trying to learn how to use encoders in a command based robot, and I'm having trouble finding how to create them and use them. I've checked several other forums already, and found nothing. Also, we can read values from our encoders, if that helps at all. If you could point me to a source that explains how to do those things, that would be amazing and very much appreciated.

Thank you!

Sorry if I sound a little unprofessional, I'm a student from my team and this is my first post.
Reply With Quote
  #2   Spotlight this post!  
Unread 07-02-2015, 22:17
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: 523
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: Using Encoders with TalonSRX

Take a look at the Talon SRX Software Reference Manual...
http://crosstheroadelectronics.com/control_system.html

Also the SRX User's Guide is worth checking out for wiring.

EDIT : Are you connecting encoders to the Talon SRX Data Port. Or are you just asking how to read encoders using the roboRIO I/O and use them that way?
Reply With Quote
  #3   Spotlight this post!  
Unread 07-02-2015, 23:13
Chaube97 Chaube97 is offline
Registered User
FRC #4859
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Byron, MN
Posts: 7
Chaube97 is an unknown quantity at this point
Re: Using Encoders with TalonSRX

We've looked at the software reference manual, and we couldn't find out how to create the encoder correctly. In the middle of writing this, one of our programmers figured out was wrong and fixed it. Now we are wondering what getEncPositon() measures in. Our encoders are connected through the Talon SRX Data Port. Also, do you know where any examples of encoder code are? Because I think that would really help us. Thanks for the quick response!
Reply With Quote
  #4   Spotlight this post!  
Unread 08-02-2015, 13:38
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: 523
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: Using Encoders with TalonSRX

The Units are explained in Section 17. Quad. Encoder units are in Section 17.1.
They are in 4X units.

Examples for reading the encoder? That would be a one line example...
int quadEncPos = motorController.getEncPosition(); /* section 5 */

You can also sanity check the values without code changes by using the Self-Test (section 2.4).

How do you plan on using the encoders exactly? Do you want to setup the Talon SRX to internally closed-loop position and/or velocity? Or do you just want to retrieve the encoder values so your logic in the RIO can make it's own decisions (for example doing a closed-loop in the RIO).

I think once you make that clear, then the community can give you better answers.
Reply With Quote
  #5   Spotlight this post!  
Unread 09-02-2015, 19:17
Chaube97 Chaube97 is offline
Registered User
FRC #4859
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Byron, MN
Posts: 7
Chaube97 is an unknown quantity at this point
Re: Using Encoders with TalonSRX

Thank you so much for the response! We plan to setup the Talon SRX to use closed-loop.
Reply With Quote
  #6   Spotlight this post!  
Unread 09-02-2015, 22:38
JefferMC JefferMC is offline
Registered User
AKA: Jeff Corbett
FRC #1319 (Flash)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2005
Location: United States
Posts: 44
JefferMC will become famous soon enough
Re: Using Encoders with TalonSRX

If you're doing closed loop, then you don't actually talk to the encoders. You wire the encoders to the TalonSRX, and you tell it to use them. This is fairly well explained in the updated version of the Talon Software Guide.

However, you may run into several challenges:

1) Assuming these are your drive motors, RobotDrive will have an issue providing the correct range of values to the Talon object using the set() method.

You'll want to call the method "ControlMode" with the Speed constant (the default is PercentVbus). And tell it that you're using an Encoder (via "setFeedbackDevice" with value QuadEncoder).

When I was playing with this, I derived a class from the CANTalon and overloaded the set() method to multiply the -1..0..+1 range to the range of encoder counts I expected. How well this would have worked, we won't know, because the CANTalon in C++ doesn't have the methods necessary to reverse (described below for Java), and the CanTalonSrx looked too foreign to rewrap myself, and my encoders needed to spin in the opposite direction from the motor, so...

2) Since you're in Java, you have the call to reverse the control input. You'll know you need to do this if you're telling the motor to spin at 0.50 speed and the encoder says it's doing a negative turn rate (and vice versa). A good way to see that your encoder is working and the direction values it's giving you is by using the RoboRio's web page, selecting your CANTalonSRX and clicking SelfTest while it's operating. Anyway, the CANTalon method to reverse the sign is called "reverseSensor()"

3) If you normally create your RobotDrive giving it port numbers, you'll need
to create the objects yourself and pass them to RobotDrive.

Yes, you can get the Encoder information from the Talon if you want to look at it or put it on the Dashboard, but you don't need to do that to do closed loop control.
Reply With Quote
  #7   Spotlight this post!  
Unread 09-02-2015, 22:51
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: 523
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: Using Encoders with TalonSRX

Quote:
How well this would have worked, we won't know, because the CANTalon in C++ doesn't have the methods necessary to reverse...
...section 7.2 of the Talon SRX software reference manual.

Quote:
2) Since you're in Java, you have the call to reverse the control input. You'll know you need to do this if you're telling the motor to spin at 0.50 speed and the encoder says it's doing a negative turn rate (and vice versa). A good way to see that your encoder is working and the direction values it's giving you is by using the RoboRio's web page, selecting your CANTalonSRX and clicking SelfTest while it's operating. Anyway, the CANTalon method to reverse the sign is called "reverseSensor()"
...section 7.4 of the Talon SRX software reference manual.
Reply With Quote
  #8   Spotlight this post!  
Unread 10-02-2015, 15:50
JefferMC JefferMC is offline
Registered User
AKA: Jeff Corbett
FRC #1319 (Flash)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2005
Location: United States
Posts: 44
JefferMC will become famous soon enough
Re: Using Encoders with TalonSRX

Quote:
Originally Posted by ozrien View Post
...section 7.2 of the Talon SRX software reference manual.
Ah... I had not gone back for the 2/1 update of the manual. I'll look at this yet again.

Quote:
Originally Posted by ozrien View Post
...section 7.4 of the Talon SRX software reference manual.
Well, yes. Do you disagree with something that I said?
Reply With Quote
  #9   Spotlight this post!  
Unread 10-02-2015, 16:34
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: 523
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: Using Encoders with TalonSRX

Nope just doc'ing for other teams benefit.
Reply With Quote
  #10   Spotlight this post!  
Unread 10-02-2015, 17:40
Chaube97 Chaube97 is offline
Registered User
FRC #4859
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Byron, MN
Posts: 7
Chaube97 is an unknown quantity at this point
Re: Using Encoders with TalonSRX

Sorry to bother you again. How would I use the set() method when I change a CANTalon to the speed control mode? I have my CANTalon bound to a button that, when pressed, sets the CANTalon speed to 0.5. Thanks for the help!
Reply With Quote
  #11   Spotlight this post!  
Unread 10-02-2015, 18:01
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: 523
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: Using Encoders with TalonSRX

If you set the control mode to Speed, then set() will take the target speed you want. The units are sensor-dependent and better explained in section 17, but it's basically the change in sensor value per 100ms. You can also cheat by using the Self-Test to see what your "Sensor Velocity" reads while driving the motor.

Examples on how to change modes is in Section 3.6. (Section 3.6.3 for Java).

Also after you changed the mode, the Talon SRX will not drive motors until the next call to set(). See Section 16.12 for more info.
Reply With Quote
  #12   Spotlight this post!  
Unread 10-02-2015, 18:58
Chaube97 Chaube97 is offline
Registered User
FRC #4859
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Byron, MN
Posts: 7
Chaube97 is an unknown quantity at this point
Re: Using Encoders with TalonSRX

Ok, I just thought set() was something else that applied to CANTalon modes and PID control. I figured out that the set() values in speed mode go from 0 to 1000. Everything works now. Thank you so much for your help!
Reply With Quote
  #13   Spotlight this post!  
Unread 10-02-2015, 19:13
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: 523
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: Using Encoders with TalonSRX

Quote:
Originally Posted by Chaube97 View Post
I figured out that the set() values in speed mode go from 0 to 1000. Everything works now. Thank you so much for your help!
Well...wait....it sets the target speed in pos per 100ms, which can be negative (reverse) and can be larger than 1000.

So do you see how in section 17.1 (Talon SRX software reference manual) the example math for a CPR=360 quadrature encoder calculates a speed of 28800 for 20 rotations per second (or RPM=1200)? So set(28800) would servo a velocity of 1200RPM in the positive direction IF using a quad encoder (that's CPR=360).

Make sense?
Reply With Quote
  #14   Spotlight this post!  
Unread 11-02-2015, 17:47
Chaube97 Chaube97 is offline
Registered User
FRC #4859
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Byron, MN
Posts: 7
Chaube97 is an unknown quantity at this point
Re: Using Encoders with TalonSRX

Ohhh. Our encoder is the E4P-250-250-D-D-D-B. I don't know the CPR, is it 250? If we set the speed to 500, the encoder reads a velocity of 300.
Reply With Quote
  #15   Spotlight this post!  
Unread 11-02-2015, 17:53
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Using Encoders with TalonSRX

Quote:
Originally Posted by Chaube97 View Post
Ohhh. Our encoder is the E4P-250-250-D-D-D-B. I don't know the CPR, is it 250?
Yes.

Quote:
If we set the speed to 500, the encoder reads a velocity of 300.
What value is the Talon reporting for the setpoint-process_variable error?



Last edited by Ether : 11-02-2015 at 17:58.
Reply With Quote
Reply


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 12:36.

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