Go to Post FIRST should come with a warning label. - Tim Sharp [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

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #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!!
  #2   Spotlight this post!  
Unread 11-02-2007, 23:17
mluckham's Avatar
mluckham mluckham is offline
Registered User
FRC #0758 (Sky Robotics)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2006
Location: Ontario, Canada
Posts: 116
mluckham will become famous soon enoughmluckham will become famous soon enough
Re: Limit Switches help

A limit switch is any kind of switch that closes when your mechanism reaches a "limit" of travel.

We use microswitches (some were included in the KOP), you could use anything including optical detector that you are using, bumper switch, etc.

They are easiest to use when there are only two "limits" (eg: - fully clockwise, fully counter-clockwise). When you have intermediate positions (as in your case) you have to be creative in how and where to place the switches. There would normally be two "limits" (bottom-most position, top-most position) and then a detector for intermediate position.

Hope this is clear - it's been a long day.

Last edited by mluckham : 11-02-2007 at 23:20.
  #3   Spotlight this post!  
Unread 11-02-2007, 23:21
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
Re: Limit Switches help

Thanks. How would I program pwm03 to stop when the switch goes on? I'm using a joystick to control pwm03, so when I set it to 127 if the switch is open wont it still not work because during the next loop (26 milisec later) pwm03 is still mapped to p3_y and thers not enough time for the joystick to go back to neutral position. they conflict dont they?
  #4   Spotlight this post!  
Unread 12-02-2007, 00:01
Shinigami2057 Shinigami2057 is offline
Slackware Is Your New God (Mentor)
AKA: Harry Bock
FRC #1350 (Rambots)
Team Role: Programmer
 
Join Date: Oct 2006
Rookie Year: 2006
Location: Johnston, RI
Posts: 106
Shinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really nice
Re: Limit Switches help

Quote:
Originally Posted by Ianuser View Post
Thanks. How would I program pwm03 to stop when the switch goes on? I'm using a joystick to control pwm03, so when I set it to 127 if the switch is open wont it still not work because during the next loop (26 milisec later) pwm03 is still mapped to p3_y and thers not enough time for the joystick to go back to neutral position. they conflict dont they?
Yes, but you can use the limit switch as a condition to whether or not you will actually map p3_y to pwm03, like so:

Code:
if( rc_dig_in01 == OPEN ) {
    pwm03 = p3_y;
} else { /* The limit switch is closed (tripped), force neutral */
    pwm03 = 127;
}
__________________
One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
  #5   Spotlight this post!  
Unread 12-02-2007, 04:40
Japper's Avatar
Japper Japper is offline
Registered User
FRC #3692 (RocknRobots)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Rutland Wisconsin
Posts: 147
Japper has a spectacular aura aboutJapper has a spectacular aura about
Re: Limit Switches help

I am trying to get the micro switches to work as limit switches also and I am not sure if I am doing this right as it isn't working at all and could use some help...


I have connected these switches to digital input 01 & 02 normally open with the signal and ground from each respective input and I am relying on the internal pullups on the RC inputs to give me a "1" condition if the switches are not activated.

We noticed that the joystick wheel is at a value of 43 if untouched (neutral) and in the down position is ~ 148 and in the up position is ~ 255, hence the loose values in my code below.

When connected to the dashboard viewer, the switch 1 and switch 2 leds light when I close my switches so I know that electrically these are working but I must have my logic wrong.

Here is my code:

Quote:
if ((p3_wheel > 240) && (rc_dig_in01 = 1)) /* jaw close */
{
relay1_fwd = 0; /* FWD only if switch1 is not closed. */
relay1_rev = 1;
}
else
{
if ((p3_wheel < 200) && (rc_dig_in02 = 1)) /* jaw open */
{
relay1_fwd = 1; /* REV only if switch2 is not closed. */
relay1_rev = 0;
}
}

if ((p3_wheel < 50) || (rc_dig_in02 = 0) || (rc_dig_in01 = 0))
{
relay1_fwd = 0; /* don't move jaw if p3 wheel is not pressed */
relay1_rev = 0;
}
This code works just fine if I do not include the rc_dig_in01 and rc_dig_in02 conditions in my if statements.

What am I doing wrong here?

Thanks!
  #6   Spotlight this post!  
Unread 12-02-2007, 05:17
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: Limit Switches help

= is an assignment operator.
== is the logical operator.
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #7   Spotlight this post!  
Unread 12-02-2007, 09:10
Japper's Avatar
Japper Japper is offline
Registered User
FRC #3692 (RocknRobots)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Rutland Wisconsin
Posts: 147
Japper has a spectacular aura aboutJapper has a spectacular aura about
Re: Limit Switches help

Ah yes... how silly of me to forget that...

been a while since I wrote anything in C...

thanks for the reminder.
  #8   Spotlight this post!  
Unread 12-02-2007, 23:36
steve d steve d is offline
Registered User
FRC #1277
 
Join Date: Jan 2007
Location: Groton, ma
Posts: 38
steve d is an unknown quantity at this point
Re: Limit Switches help

we have limit switches wire to the digital in/outs. The motor turns untill a certian pattern of switches open/clsed is reached, To make an integer from 4 digital i/os do this:
word = dig_in01<<3
word+= dig_in02<<2
word+= dig_in03<<1
word+= dig_in04

Say dig_01 & dig_03 were closed, making "0", the 4 bit word would be 0110 or 6.
Remember, inside the digital_in/outs are tied high, they read 1, you need to ground it to read 0.

Turn the motor until the number is the lift state you want. Think "state machine".
Closed Thread


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
Alternative to limit switches? RbtGal1351 Electrical 27 10-12-2005 15:30
limit switches stephenthe1 Programming 28 11-05-2005 16:37
Limit Switches help. Xufer Programming 9 21-04-2004 21:21
Limit switches Team168 Programming 8 10-02-2003 16:22
Limit Switches/Pots Brett W Technical Discussion 3 28-01-2003 14:25


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

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