Go to Post There should be no teams yelling "robot". - RoboMom [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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-01-2005, 16:38
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Updated Encoder Code Available

I've significantly updated my example quadrature encoder code with additional functionality and documentation. Here's an excerpt from the readme.txt:


Code:
This source code in this file implements an interface to two
quadrature output encoders with the assumption that they are
coupled to the robot's drive train, one on the left side, the
other on the right. Used with suitable PID control software,
encoders can be used to control the position and velocity of
of your robot. This software was tested with Grayhill 63R256
and 61K128 quadrature output optical encoders. Data sheets for
these devices are included.
		
This source code will work with the Robovation (A/K/A EDU-RC) 
robot controller and the FIRST Robotics robot controller.
On a 40MHz PIC18F8520, this software can track peak encoder 
count rates as high as a few thousand counts per second, which
should be more than adequate for most applications. To meet
your performance expectations, selecting the proper Counts Per 
Revolution (CPR) parameter of your encoder is very important.
If the CPR is too high, the robot controller will spend too
much time counting encoder "ticks" and not enough time on
other tasks. At the extreme, you will see very wacky behavior
in your robot controller including corrupted data, the red-
light-of-death or the controller may even think the robot is
traveling in a direction that it isn't. Selecting a CPR that
is too low will not give you the resolution you desire. The
CPR should be optimized to minimize the number of interrupts
your robot controller will have to service yet meet your
resolution expectations (yes, millimeter position resolution
to too much to ask for).
 
The included project files were built with MPLAB version 6.60.
If your version of MPLAB complains about the project version, 
the best thing to do is just create a new project with MPLAB's 
project wizard. Include every file except: FRC_alltimers.lib 
and ifi_alltimers.lib and you should be able to build the code.
This file is best viewed with tabs set to four characters.
 
****************************************************************
Here's a description of the functions in encoder.c:

Initialize_Encoders()
This function initializes the encoder software. It should be
called from user_routines.c/User_Initialization().
 
Get_Left_Encoder_Count()
Get_Right_Encoder_Count()
These functions will return the current number of encoder
counts or "ticks".

Set_Left_Encoder_Count()
Set_Right_Encoder_Count()
These functions are used to reset or change the encoder count.

Left_Encoder_Int_Handler()
Right_Encoder_Int_Handler()
When the phase-A signal of an encoder transitions from a zero
to a one, the microcontroller will automatically call these 
functions to sample the phase-B signal and increment/decrement
the encoder count variables. You shouldn't have to call these 
functions yourself.
 
****************************************************************
Five things must be done before this software will work 
correctly on the FRC-RC:
1) The left encoder's phase-A output is wired to digital input 
one and the phase-B output is wired to digital I/O six.
2) The right encoder's phase-A output is wired to digital input
two and the phase-B output is wired to digital I/O 8.
3) Digital I/O pins one, two, six and eight are configured as 
inputs in user_routines.c/User_Initialization(). If you notice
that the encoder only counts in one direction, you forgot to
do this step.
4) A #include statement for the encoder.h header file must be 
included at the beginning of each source file that calls the 
functions in this source file. The statement should look like 
this: #include "encoder.h".
5) Initialize_Encoders() must be called from user_routines.c/
User_Initialization().

Five things must be done before this software will work 
correctly on the EDU-RC:
1) The left encoder's phase-A output is wired to interrupt 
one and the phase-B output is wired to digital I/O six.
2) The right encoder's phase-A output is wired to interrupt 
two and the phase-B output is wired to digital I/O eight.
3) Digital I/O pins six and eight are configured as inputs in
user_routines.c/User_Initialization(). If you notice that the
encoder only counts in one direction, you forgot to do this 
step.
4) A #include statement for the encoder.h header file must be 
included at the beginning of each source file that calls the 
functions in this source file. The statement should look like 
this: #include "encoder.h".
5) Initialize_Encoders() must be called from user_routines.c/
User_Initialization().
 
Kevin Watson
kevinw@jpl.nasa.gov
The code can be found here: http://kevin.org/frc

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #2   Spotlight this post!  
Unread 03-01-2005, 23:13
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
Re: Updated Encoder Code Available

Kevin, this is great! Thanks very much, this will be a big help in the days to come!
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic
  #3   Spotlight this post!  
Unread 04-01-2005, 01:00
thoughtful's Avatar
thoughtful thoughtful is offline
Registered User
FRC #1219 (Emery Iron Eagle)
Team Role: Alumni
 
Join Date: Nov 2003
Location: Toronto,Canada
Posts: 291
thoughtful is a splendid one to beholdthoughtful is a splendid one to beholdthoughtful is a splendid one to beholdthoughtful is a splendid one to beholdthoughtful is a splendid one to beholdthoughtful is a splendid one to beholdthoughtful is a splendid one to behold
Re: Updated Encoder Code Available

Once again a helpful and essential contribution. It will be very helpful for us because we are planning to implement encoders on our robot this year. Thankyou!
__________________
.:Bringling Brains to Life:.

03,04,05-Team 1219 Captain
2003 Rookie all Start @ GTR
2005 Galileo Semi-Finalist & Alliance captain
06-Team 1219 Mentor
2006 Radio Shack Innovation in control @ Waterloo
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sourceforge for Code Repository and other stuff SilverStar Programming 9 15-01-2005 21:16
A Centralized Code Dump? colt527 Programming 29 01-01-2005 16:07
heres the code. y this not working omega Programming 16 31-03-2004 15:18
Updated Infrared Tracking Code Kevin Watson Programming 0 18-02-2004 21:41
how to add steps in the provided encoder program for the edu Zaramel2002 Programming 3 11-02-2004 08:35


All times are GMT -5. The time now is 02:46.

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