Go to Post IRI: Where the Egos Go to Tie. :ahh: - Ian Curtis [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 10-02-2007, 22:20
Ianuser Ianuser is offline
Registered User
FRC #0570
 
Join Date: Feb 2007
Location: new york
Posts: 64
Ianuser is an unknown quantity at this point
How do I program this sensor?

Hello everybody. I'm programming a "metal detector" on my robot so it can sense a small piece of aluminum tape that will be on a rope. The rope will go up and down (our version of an arm) and there will be (we haven't decided yet) appx. 4 pieces of tape on the rope. So, when the tape passes the sensor, I want the program to keep track so when it reaches a certain height it will automatically stop, so we dont have to manually stop the arm. So from the first four passes of the tape through the sensor, the rope will be moving up, and the next four (five to eight) will let us know that the rope is going down. Will this work? And is where in the code I'm placing this correct (in user_routines_fast.c Process_Data_From_Local_IO)? (I want to use the relay2 lights so I can see whether I'm going UP or going DOWN. at full up they are both on and at full down they are both off. red is going down and green is going up.)

Code:
void Process_Data_From_Local_IO(void)
{
	int count = 0;
	
	if(digital_io_04 == 1) //If sensor, which connects to Dig In/Out port 4, goes on...
	{
		count++; //Number of times tape passes through the sensor.
		Switch01_LED = 1; //Switch01 goes on when the tape passes the sensor.
	}
	else
	{
		Switch01_LED = 0;
	}


	if(count == 8) 
	{
		Relay2_green = 0;
		Relay2_red = 0;
		pwm03 = 127; //Motor stops when it retreats to ground level.
		//pwm03 = p3_y; //re-maps pwm03 to joystick
		count = 0;
	}
	else if(count == 7) 
	{
		Relay2_green = 0;
		Relay2_red = 1;
		pwm03 = 127; //Motor stops when it retreats to 1st level.
		//pwm03 = p3_y; //re-maps pwm03 to joystick
	}
	else if(count == 6) 
	{
		Relay2_green = 0;
		Relay2_red = 1;
		pwm03 = 127; //Motor stops when it retreats to 2nd level.
		//pwm03 = p3_y; //re-maps pwm03 to joystick
	}
	else if(count == 5) 
	{
		Relay2_green = 0;
		Relay2_red = 1;
		//pwm03 does not equal 127 because it must pass the tape in order to go beneath the top level.
	}
	else if(count == 4)
	{
		Relay2_green = 1;
		Relay2_red = 1;
		pwm03 = 127; //Motor stops when it reaches top level.
		//pwm03 = p3_y; //re-maps pwm03 to joystick
	}
	else if(count == 3)
	{
		Relay2_green = 1;
		Relay2_red = 0;
		pwm03 = 127; //Motor stops when it reaches 2nd level.
		//pwm03 = p3_y; //re-maps pwm03 to joystick
	}
	else if(count == 2)
	{
		Relay2_green = 1;
		Relay2_red = 0;
		pwm03 = 127; //Motor stops when it reaches 1st level.
		//pwm03 = p3_y; //re-maps pwm03 to joystick
	}
	//if count == 1 then that just means that it passed through the first piece of tape which will be used to show that it is in full DOWN position.
	
	/* Add code here that you want to be executed every program loop. */

}
So, First of all, if you noticed I put "//pwm03 = p3_y" in comments. This is because I'm not sure if I give pwm03 a number (127), if it will permenantly make it that number? So would I have to re-map it to the joystick? or would it do that automatically in the Default_Routine()? Also, does the first line of code with the sensor make sense? And I'm not sure if I put this code in the correct spot in the program. I'm sort of new to programming, just started late last year. Thanks in advance for your help!
 


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
Vex line follower sensor kit program jbill30 Programming 5 12-05-2006 14:43
What's happening to this program??? Weightmn General Forum 22 04-04-2005 15:40
TI Pressure Sensor this year? kmcclary Pneumatics 1 20-01-2005 20:53
This board is quiet-- so how bout this election?!?!? archiver 2000 19 24-06-2002 00:23
How do you connect optical sensor? archiver 2001 1 23-06-2002 23:05


All times are GMT -5. The time now is 04:44.

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