Thread: Encoder Code
View Single Post
  #14   Spotlight this post!  
Unread 23-01-2008, 18:20
Steve_Alaniz Steve_Alaniz is offline
Registered User
FRC #2848 (All Sparks)
Team Role: Mentor
 
Join Date: Mar 2007
Rookie Year: 1997
Location: Dallas
Posts: 211
Steve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond repute
Re: Encoder Code

Ouch! That's rough! 3 weeks! You probably already know all this but just in case. Everything is overhead except for:
user_routines.h
user_routines.c
user_routines_fast.c

user_routines_fast executes once every 26.2ms (approx) and doesn't wait for the operator interface to send data. You can run the robot from this routine and in fact this is where you'd put code for the autonomous period, or any fast calculations from on board sensors without Operator Interface input.

user_routines Processes input (like joystick positions or pushbuttons or scaling the joysticks so they are not so sensitive on the low end) from the Operator Interface. most of the coding for actually operating the robot is in here, while the automatic stuff (an algorithm for keeping the robot running straight perhaps) Happens in user_routines_fast

user_routines.h describes itself:
Code:
* USAGE:
*  If you add your own routines to those files, this is a good place to add
*  your custom macros (aliases), type definitions, and function prototypes.
I am not a programming guru so I stay out of this one.

If you're looking for Encoder routines, Kevin Watson's is a quite elegant place to start. Downloading his code in the robot gives you on screen output of 6 encoders that use A & B phase direction/count inputs that are connected to the digital in/out on 1,11 2,12, 3,13, 4,14, 5,15, 6,16 positions.
You also get his interrupt driven serial port drivers. I didn't realize this at first, so I got confused until I finally figured it out. You disable unused encoders in encoder.h (I commented out the enable lines for the unused encoders).
I compared the encoder user_routines.c file with the default user_routines.c program to find out what I needed to leave in to allow the encoders to run and ended up adding my own joystick programs to the encoder user_routines.c and got it to work.
Really cool stuff and I have to thank Kevin for demystifying it. I'll be happy to send you MY files and you can see if they'll work on your VEX setup.

Best wishes
Steve