Go to Post I am as certain as can be on this issue ... believe me. - Paul Copioli [more]
Home
Go Back   Chief Delphi > Technical > Technical Discussion
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #8   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.
 


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
Q&A Discuss: Optical sensors with EduBot CD47-Bot Extra Discussion 2 01-03-2003 18:37
Q&A Discuss: optical sensors CD47-Bot Extra Discussion 0 15-02-2003 22:58
optical sensors great_one411 General Forum 1 15-02-2003 19:54
optical sensors acting strangely rosebud Electrical 10 03-02-2003 00:29
optical sensors majormusic2005 General Forum 1 28-01-2003 20:37


All times are GMT -5. The time now is 06:09.

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