Go to Post Dave has said that straight out. Well, straight by dave standards. - phrontist [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

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 04-02-2017, 11:52
T8PineappleSam T8PineappleSam is offline
Jonathan
AKA: Jonathan Zwiebel
FRC #0008 (Paly Robotics)
Team Role: Driver
 
Join Date: Jan 2016
Rookie Year: 2013
Location: California
Posts: 28
T8PineappleSam will become famous soon enoughT8PineappleSam will become famous soon enough
Re: Confused on how to use Encoder

Quote:
Originally Posted by Yousuf View Post
We're trying to use the encoder to make the robot travel a specific distance and trying to figure out how to use a PID controller to keep the both sides of the robot travel at the same speed. Any help or guidance would be much appreciated. We use CANTalon SRX's as our speed controllers for the motors and an SRX Magnetic Encoder.
The Talon SRX's has onboard speed controllers which assist a lot with running PID loops. CTRE does a really good job of documenting their work and I would recommend reading through the software manual http://www.ctr-electronics.com/downl...e%20Manual.pdf and checking out the sample code https://github.com/CrossTheRoadElec/FRC-Examples. The section on closed-loop position control can be found in section 10.1 (page 62) of the manual. Note that to use the onboard processing that the Talon provides, the encoders need to plugged in directly to the data ports on the Talons.

Specific to running any loop through TalonSRX's the first steps would be ensuring the Talon drives the correct direction and that the encoder is wired correctly and returning values.
Code:
talon.setFeedbackDevice(CANTalon.FeedbackDevice.CtreMagEncoder_Relative)
talon.reverseSensor(is_reversed)
talon.reverseOutput(is_reversed)
.

To run a closed-loop position loop you must set the Talons to position mode, set PID constants, and then set a setpoint.
Code:
talon.changeControlMode(CANTalon.TalonControlMode.Position)
talon.setPID(P, I, D, 0, 0, 0, 0)
talon.setSetpoint(target_distance)
__________________
Jonathan Zwiebel
Driver, Project Manager, Programmer [Team 8, Paly Robotics]




2016 Central Valley Regional Finalist and Wildcard, Silicon Valley Regional Quarterfinalist, Curie Division, CalGames Quarterfinalist and Entrepreneurship Award, Capital City Classic Quarterfinalist
2015 Central Valley Regional Entrepreneurship Award, Silicon Valley Regional Entrepreneurship Award, Capital City Classic Semifinalist and Judges' Award
2014 Central Valley Regional, Silicon Valley Regional, Chezy Champs

Last edited by T8PineappleSam : 04-02-2017 at 11:53. Reason: Clarified that encoders need to go through data ports.
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 01:50.

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