View Single Post
  #1   Spotlight this post!  
Unread 29-02-2004, 21:36
ErichKeane ErichKeane is offline
Registered User
FRC #3210
Team Role: Mentor
 
Join Date: Nov 2003
Rookie Year: 2004
Location: Hillsboro, OR
Posts: 113
ErichKeane is just really niceErichKeane is just really niceErichKeane is just really niceErichKeane is just really niceErichKeane is just really nice
Send a message via AIM to ErichKeane
Re: Optical Sensors Used as Encoders?

Really, the code to this is not that hard. I would not use interrupts, only because getting them to interface correctly with the code can sometimes be a problem. Now, i forget whether the Banner sensors Run at full speed or not, but this is how i would code this segment. Note: If banner sensors do run correctly In FAST mode, place this code in the user_routines_fast.c, otherwise, just put it in your regular segment

Assumes banner sensors are wired as Normally Closed, and are wired to rc_dig_in01&02, and pwm01&pwm02 are the left and right wheels respectively. If you got questions, ask away.

FIRST: at the header (for variable data)
Code:
int leftcount=0,rightcount=0;//note, is signed to care for backward variables
unsigned char leftlast=0,rightlast=0,roundcount=0;//only cause we dont have a bool class
Secondits kinda apparent)

Code:
void Process_Data_From_Local_IO(void)
{
	if(rc_dig_in01==1 &&leftlast==0)//left wheel counter 
		if(pwm01>127)
			leftcount++;
		else if(pwm01<127)
			leftcount--;
	leftlast=rc_dig_in01;		


	if(rc_dig_in02==1 &&rightlast==0)//right wheel counter
		if(pwm02>127)
			rightcount++;
		else if(pwm02<127)
			rightcount--;
	rightlast=rc_dig_in02;

	if(roundcount>12)
	{
		if(leftcount>rightcount)
			//whatever you want
		else if(rightcount<leftcount)
			//whatever you want
		else
			//take a guess?
		
		rightcount=leftcount=roundcount=0;
	}



	roundcount++;

}
Thats the quick, easy, and fun way to do it.



side note, i wrote this just right now, so if you find a problem with it, just post a correction below. Anyone may use this however they want, think of it as a mixture between the OpenSource in me and the Gracious Professionalism. As another side note, if anyone else needs coding help, i have become quite good at it, just send your questions my way.