Go to Post Only Dave knows [if the 2010 game is designed already], and he aint tellin' but he'll happily feed you lots of red herrings. - Koko Ed [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 19-07-2007, 12:11
Demothesis's Avatar
Demothesis Demothesis is offline
Team Leader/Programmer
FRC #2169 (KING TeC)
Team Role: Leadership
 
Join Date: Dec 2006
Rookie Year: 2007
Location: Prior Lake
Posts: 32
Demothesis is on a distinguished road
Question Gear encoder code

How do you program the gear tooth encoder? The PDF that discusses the electrical hookup (power mainly and pin descriptions) of these modules is very in-specific about programming. Which port do you hook the encoders up to, and how do you get the uP to process data from them?

Demothesis
  #2   Spotlight this post!  
Unread 19-07-2007, 12:17
chris31 chris31 is offline
Team 2021 Captain
AKA: Chris Davidson
FRC #2021 (FA Robotics)
Team Role: Mentor
 
Join Date: Nov 2005
Rookie Year: 2006
Location: Atlanta, GA/ Fredericksburg,VA
Posts: 949
chris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond repute
Send a message via AIM to chris31
Re: Gear encoder code

I would recommend that you download and look at Kevin Watson's code.
http://www.kevin.org/frc/
  #3   Spotlight this post!  
Unread 19-07-2007, 16:36
Demothesis's Avatar
Demothesis Demothesis is offline
Team Leader/Programmer
FRC #2169 (KING TeC)
Team Role: Leadership
 
Join Date: Dec 2006
Rookie Year: 2007
Location: Prior Lake
Posts: 32
Demothesis is on a distinguished road
Re: Gear encoder code

I looked there! It is for the wrong encoder!!! The code there is for an optical sensor that looks like a potentiometer(there are pictures), and the one that first gives out (the one I have) uses a field effect transistor to sense the teeth on the gears.
  #4   Spotlight this post!  
Unread 19-07-2007, 16:42
chris31 chris31 is offline
Team 2021 Captain
AKA: Chris Davidson
FRC #2021 (FA Robotics)
Team Role: Mentor
 
Join Date: Nov 2005
Rookie Year: 2006
Location: Atlanta, GA/ Fredericksburg,VA
Posts: 949
chris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond reputechris31 has a reputation beyond repute
Send a message via AIM to chris31
Re: Gear encoder code

Oh. I always thought he has GTS code on his website. You might want to PM him and see, I think I remember him posting a GTS beta once. Maybe not. Do you have experience using interupts?

Last edited by chris31 : 19-07-2007 at 16:44.
  #5   Spotlight this post!  
Unread 19-07-2007, 18:18
lukevanoort lukevanoort is offline
in between teams
AKA: Luke Van Oort
no team
 
Join Date: Oct 2005
Rookie Year: 2005
Location: Waterloo, ON, Canada
Posts: 1,873
lukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond repute
Send a message via AIM to lukevanoort
Re: Gear encoder code

You can use Kevin Watson's encoder code for the GTS, just remove the Phase B stuff. It's also a pretty simple to write your own code for the GTS, but it is easier to just modify Kevin's.
__________________
Team 1219: 2009 - Mentor
Team 587: 2005 - Animator, 2006-2008 - Team Captain

Last edited by lukevanoort : 19-07-2007 at 18:24. Reason: grammar
  #6   Spotlight this post!  
Unread 20-07-2007, 11:11
John Gutmann John Gutmann is offline
I'm right here
AKA: sparksandtabs
FRC #0340 (GRR)
Team Role: Mechanical
 
Join Date: Feb 2005
Rookie Year: 2004
Location: rochester
Posts: 804
John Gutmann has a brilliant futureJohn Gutmann has a brilliant futureJohn Gutmann has a brilliant futureJohn Gutmann has a brilliant futureJohn Gutmann has a brilliant futureJohn Gutmann has a brilliant futureJohn Gutmann has a brilliant futureJohn Gutmann has a brilliant futureJohn Gutmann has a brilliant futureJohn Gutmann has a brilliant futureJohn Gutmann has a brilliant future
Send a message via AIM to John Gutmann Send a message via MSN to John Gutmann Send a message via Yahoo to John Gutmann
Re: Gear encoder code

Perhaps you should be asking for the theory so you can write your own code and learn more. But Since I am a nice guy who has some time on his hands I will spoon feed it to you.

Basically what you want to do with the GTS is either sense your speed or your relative movement.

Go look at the data sheet for the robot controller and see which pin is the external interrupt, you will hook the signal pin of the GTS to that. Now what happens with the GTS is any time the gear tooth comes within range of the GTS the magnetic field changes and the sensors lets you read that change as a binary 1 or 0. ( I don't know all the specifics, I have never actually used one). The interrupt pin of the robot controller when triggered litterally interrupts the code to enter into a interupt service routine. Inside the interrupt service routine you need to have as little code as possible so not to bog down your processor. When I code something like this all I put in the ISR (interupt service routine) is an increment statement. Then in the main loop I put the code to manipulate the incremented variable. By manipulate I mean measure time between increments, # of increments, distance calculations, etc. This is the exact same process I use for an encoder. The 2 are basically the same when it comes to programming.

Just tell me if I left anything out.

-John
  #7   Spotlight this post!  
Unread 20-07-2007, 11:14
Demothesis's Avatar
Demothesis Demothesis is offline
Team Leader/Programmer
FRC #2169 (KING TeC)
Team Role: Leadership
 
Join Date: Dec 2006
Rookie Year: 2007
Location: Prior Lake
Posts: 32
Demothesis is on a distinguished road
Re: Gear encoder code

Thanks teams. Now, I looked at the code and "phase b" is all over the place in "encoder.c" (And maybe elsewhere). What do I comment out? I have a feeling that just taking out all lines that have "phase b" anywhere in them is going to give me syntax errors that I haven't even heard of!

Demothesis


PS just for curiosity sake, how would you go about programming your own encoder code? How do you get the uP to recognize the signals coming from the GTS when plugged into the Digital Input?
  #8   Spotlight this post!  
Unread 20-07-2007, 11:54
SgtMillhouse648's Avatar
SgtMillhouse648 SgtMillhouse648 is offline
Registered User
AKA: Malhon Godwin
FRC #0648 (QC Elite)
Team Role: Engineer
 
Join Date: Apr 2006
Rookie Year: 2005
Location: Davenport, IA
Posts: 153
SgtMillhouse648 has a spectacular aura aboutSgtMillhouse648 has a spectacular aura about
Send a message via MSN to SgtMillhouse648
Re: Gear encoder code

Most encoders I know like the vex encoder plug into an interrupt port or are like the new magnetic absolute encoders we just got and plug into an analog input and act like a continuous spin pot
__________________
2007-
Midwest Regional-
Regional Finalists with 1000 and 447
Rockwell Automation Inspiration in Control Award
Regional Woodie Flowers - Ed Wegscheid



  #9   Spotlight this post!  
Unread 20-07-2007, 17:15
lukevanoort lukevanoort is offline
in between teams
AKA: Luke Van Oort
no team
 
Join Date: Oct 2005
Rookie Year: 2005
Location: Waterloo, ON, Canada
Posts: 1,873
lukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond repute
Send a message via AIM to lukevanoort
Re: Gear encoder code

A lot of this will probably sound like what John Gutmann said, but here goes. Basically you can envision the GTS as a little switch that triggers when it is 'hit' by a gear/sprocket tooth. Now, on the software side you have to be able to detect this 'hit' and count them. Unfortunately, so many teeth 'hit' the GTS per second that you can't just check for a 1 or a 0 on their port in the normal program loop. Here is where interrupts come in.

Whenever a certain type of event occurs (encoder ticks, serial port data, and timer overflows are some common ones) something called an Interrupt Flag is set. The controller then stops whatever its doing and goes to call the ISR (Interrupt Service Routine) associated with that flag. (ISRs are called from the InterruptHandlerLow() function in user_routines_fast.c in the default code) In the ISR, you do whatever you need to do with that data, (in this case increment a counter) however, the ISR should be very short and fast executing, otherwise the controller will spend all its time servicing interrupts. The interrupt flag is then cleared, and the controller resumes its usual programming.

So, on to the actual issue at hand. To write your own code, you first have to decide which digital IOs you want to use. IOs 1-6 all can interrupt, but 1 & 2 are easiest to use. So what you'd do first is enable the interrupts in the User_Initialization() function. For exactly what that entails, look at Kevin Watson's initialization code for encoders 1&2. Then you'd write your ISR, lets say these are functions called something like GTS_1_ISR() and GTS_2_ISR(). In these functions, you increment a very large variable. Then you'd call them in the appropriate place in InterruptHandlerLow. In this case the appropriate places are where it checks for the "INTCON3bits.INT2IF && INTCON3bits.INT2IE" flags for digital IO 1 and "INTCON3bits.INT3IF && INTCON3bits.INT3IE" for digital IO 2. Check to make sure the interrupt flag is reset somewhere (either in your ISR or in InterruptHandlerLow()). Then it is time to use the counter.

To access the count, you should probably so something like Kevin Watson does and disable the interrupt before you read the count. (Check out his code for how to do this)

Now, for the easy solution, modifying Levin Watson's encoder code. Go to the ISR for encoders 1 & 2 (Encoder_1_Int_Handler, and Encoder_2_Int_Handler, respectively), and replace the if statement with Encoder_X_Count++; where X is the number of the encoder.
__________________
Team 1219: 2009 - Mentor
Team 587: 2005 - Animator, 2006-2008 - Team Captain
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
Encoder Code Kevin Watson Programming 47 18-02-2008 12:56
Vex Encoder Code CircularLogic FIRST Tech Challenge 7 09-08-2006 22:12
Combining camera + encoder code kiettyyyy Programming 5 13-04-2006 09:39
Turning a gear-tooth sensor into a quadrature output encoder Jared Russell Programming 4 18-01-2006 22:19
Updated Encoder Code Available Kevin Watson Programming 2 04-01-2005 01:00


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

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