View Single Post
  #1   Spotlight this post!  
Unread 11-02-2007, 22:51
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
Limit Switches help

Hi, I'm new at this sort of thing, and with a week left I could use some help with my forklift. I want to make it so it stops at each level. First level is the starting position, almost at the ground. 2nd level is the first level of the rack (the lowest level...24 inches i think). 3rd level in the programming will be the 2nd level on the rack (middle level). And the 4th level in the programming will be the highest level of the rack. Now, there aer a few ways I could do this I've heard. One is a metallic sensor which produces 1 if metal passes by it (a small piece of metal tape on the rope that we are using for the winch system) and 0 if its not. Here is the code I made for that:

Code:
void Default_Routine(void)
{
 	int count = 0;
	int now;
	int last;
	now = last;
	rc_dig_in04 = now;
blah blah blah...map joystick stuff..

Code:
/***************
                  * Sensor Code *
                  ***************/
 
 	if((pwm03 < 125) || (pwm03 > 129))
 	{
 		if((now == 1) && (last == 0)) //If sensor, which connects to Dig In/Out port 4, goes off...
		{
			count++; //Number of times tape passes through the sensor.
			Switch1_LED = 1; //Switch01 goes on when the tape passes the sensor.
		}
		else
		{
			Switch1_LED = 0;
		}
	
	
		switch(count)
		{
			case 2:
		
				Relay2_green = 1;
				Relay2_red = 0;
				pwm03 = 127; //Motor stops when it reaches 1st level.
				break;
			
			case 3:
			
				Relay2_green = 1;
				Relay2_red = 0;
				pwm03 = 127; //Motor stops when it reaches 2nd level.
				break;

			case 4:
					
				Relay2_green = 1;
				Relay2_red = 1;
				pwm03 = 127; //Motor stops when it reaches top level.
				break;

			case 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.
				break;

			case 6:
			
				Relay2_green = 0;
				Relay2_red = 1;
				pwm03 = 127; //Motor stops when it retreats to 2nd level.
				break;
			
			case 7:
			
				Relay2_green = 0;
				Relay2_red = 1;
				pwm03 = 127; //Motor stops when it retreats to 1st level.
				break;

			case 8:
			
				Relay2_green = 0;
				Relay2_red = 0;
				pwm03 = 127; //Motor stops when it retreats to ground level.
				count = 0;
				break;

		//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.
		}
	}
Another way that someone told me about is using Limit Switches. Honestly I don't even know what they are, so if somebody could explain that to me it'd help a lot. Would that be the easiest thing to do? I want to make pwm03 (the motor for the winch system) to stop at each of the four levels (1st level being ground level so it doesnt run into the floor or break the rope).

The line of code pwm = 127; that is in each of the cases I don't think will work because pwm03 is mapped to the joystick so in the next loop (26 ms later) it will keep going the direction that the joystick was going.

So, using limit switches could help me maybe? I've never used them before. help would be greatly appreciated! Only 4 days left befoer we have to ship our robot!!