View Single Post
  #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