Go to Post Its not really a robotics competition. The robots are merely vehicles used to make society a better place, and to inspire the youth of the world to help one another, and to become more united. - Amanda M [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 17-02-2008, 22:30
iwin2000 iwin2000 is offline
Registered User
no team
 
Join Date: Dec 2007
Rookie Year: 2008
Location: CT
Posts: 23
iwin2000 has a spectacular aura aboutiwin2000 has a spectacular aura about
Using Limit Switches with the Arm

This is a little urgent because the robot needs to be shipped tomorrow and it would be ideal to have a working code before that...
I am coding in EasyC and I'm having some problems with coding the limit switches to limit the arm movements so it doesn't hit the bottom of the robot when extended.

This image will provide you with more information about what we want:


When our Limit Switches equal 1, it is pushed down. Otherwise, they equal 0.
The rotator motor of the arm is a PWM. The extender is a relay switch.

VARIABLES USED:
Code:
unsigned char LimitSwitch1;
unsigned char LimitSwitch2; 
unsigned char LimitSwitch3; 
unsigned char LimitSwitch4; 
unsigned char YAxisInputArmRotation;
Code:
// Joystick Y-Axis Movement controls Arm Rotation Motor Forward / Backward PWM 
// Joystick Aux1 and Aux2 Movement controls Arm Extender Motor Forward / Backward 
// 
// Get Joystick Input for Aux1 and Aux2 
LimitSwitch1 = GetDigitalInput ( 5 ) ; 
LimitSwitch2 = GetDigitalInput ( 6 ) ; 
LimitSwitch3 = GetDigitalInput ( 7 ) ; 
LimitSwitch4 = GetDigitalInput ( 8 ) ; 

if ( LimitSwitch1 == 1 ) 
{ 
// If the Arm Extention Switch is DOWN (ON HOME POSITION) then only allow EXTRACTION and ROTATION MOVEMENT. 
// Up / Down Arm Rotation Movement -- Get Joystick Y-Axis Input 
OIToPWM ( 3 , 2 , 3 , 1 ) ; // Out Extender Arm Movement
OIToRelay ( 3 , 4 , 1 , 2 ) ; 
PrintToScreen ( "Limit Switch ONE is pushed down -- RETRACTION NOT ALLOWED.\n" ) ; 
} 

if ( LimitSwitch1 == 1 && LimitSwitch2 == 1 ) 
{ 
// If Limit Switch 2 ( ARM ROTATION -- FRONT ) is down and LimitSwitch1 is down ( ARM IS RETRACTED ) then ALLOW ALL MOVEMENT. 
// Up / Down Arm Rotation Movement -- Get Joystick Y-Axis Input 
OIToPWM ( 3 , 2 , 3 , 1 ) ; // In / Out Extender Arm Movement 
OIToRelay ( 3 , 3 , 1 , 1 ) ; 
OIToRelay ( 3 , 4 , 1 , 2 ) ; PrintToScreen ( "Limit Switch ONE and Limit Switch TWO are down -- ARM IS RETRACTED, ALLOW ALL.\n" ) ; 
}

if ( LimitSwitch1 == 0 && LimitSwitch2 == 1 ) 
{ 
// If Limit Switch 2 ( ARM ROTATION -- FRONT ) is down BUT Limit Switch 1 (ARM EXTENTION -- HOME ) IS NOT DOWN then ONLY ALLOW REVERSE ROTATION AND RETRATION 
// Up / Down Arm Rotation Movement -- Get Joystick Y-Axis Input 
YAxisInputArmRotation = GetOIAInput ( 3 , 2 ) ; 

if ( YAxisInputArmRotation <= 127 ) 
{ 
SetPWM ( 3 , YAxisInputArmRotation ) ; 
} 
// In Extender Arm Movement 
OIToRelay ( 3 , 4 , 1 , 2 ) ; 
PrintToScreen ( "Limit Switch TWO is down, ONE is NOT. -- RETRACTION AND REVERSE ROTATION ¬ ALLOWED\n" ) ; 
} 

if ( LimitSwitch1 == 1 && LimitSwitch3 == 1 ) 
{ 
// If Limit Switch 3 ( ARM ROTATION -- BACK ) is down and LimitSwitch1 is down ( ARM IS RETRACTED¬ ) then ALLOW ALL MOVEMENT. 
// Up / Down Arm Rotation Movement -- Get Joystick Y-Axis Input 
OIToPWM ( 3 , 2 , 3 , 1 ) ; 
// In / Out Extender Arm Movement 
OIToRelay ( 3 , 3 , 1 , 1 ) ; 
OIToRelay ( 3 , 4 , 1 , 2 ) ; 
PrintToScreen ( "Limit Switch ONE and THREE are pushed down -- ARM IS RETRACTED, ALLOW ALL.\n" ) ; 
} 

if ( LimitSwitch1 == 0 && LimitSwitch3 == 1 ) { 
// If Limit Switch 3 ( ARM ROTATION -- BACK ) is down and LimitSwitch1 is up ( ARM IS EXTENDED ) then only allow forward rotation and retraction 
// Up Arm Rotation Movement -- Get Joystick Y-Axis Input 
YAxisInputArmRotation = GetOIAInput ( 3 , 2 ) ; 
if ( YAxisInputArmRotation >= 127 ) { 
SetPWM ( 3 , YAxisInputArmRotation ) ; 
} 
// In Extender Arm Movement 
OIToRelay ( 3 , 4 , 1 , 2 ) ; 
PrintToScreen ( "Limit Switch THREE is down, ONE is not -- ALLOW RETRACTION and FORWARD ROTATION.\n" ) ; } 

if ( LimitSwitch4 == 1 ) { 
// If Limit Switch 4 is down then move the opposite direction you were going. 
// Arm Rotation Movement is opposite what it was originally going... 
YAxisInputArmRotation = GetOIAInput ( 3 , 2 ) ; 

if ( YAxisInputArmRotation >= 127 ) 
{

} 

PrintToScreen ( "Limit Switch FOUR is pushed down.\n" ) ; 
} 

if ( LimitSwitch1 == 0 && LimitSwitch2 == 0 && LimitSwitch3 == 0 && LimitSwitch4 == 0 ) 
{
// If Limit Switches are not down then DO WHATEVER YOU WANT. 
// Up / Down Arm Rotation Movement -- Get Joystick Y-Axis Input 
OIToPWM ( 3 , 2 , 3 , 1 ) ; 
// In / Out Extender Arm Movement 
OIToRelay ( 3 , 3 , 1 , 1 ) ; 
OIToRelay ( 3 , 4 , 1 , 2 ) ; 
PrintToScreen ( "NO Limit Switches are PUSHED DOWN. ALL MOVEMENT ALLOWED\n" ) ; 
} 
}
I am just generally very unsure about my code and we've run into a problem while testing it: If the arm is moving in any way and one of the switches gets pressed, it totally ignores all user input and keeps turning that way with the last input that was recieved, until the switch is let go, which is TOTALLY not what we want. Is there any way I can reorganize it so that it works the way I need it to? I need it to make the arm STOP when the switch is toggled. Afterwards, I need it to only be able to turn or retract the OPPOSITE way it came from.

Please, any comments will help me, especially since I need to get this working by tomorrow... Thanks
 


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
Limit Switches ChrisR_522 Programming 2 25-01-2008 08:04
Using a limit switch to limit motion ManicMechanic Programming 16 20-12-2007 00:54
How to connect limit switches with pwm cables?????!!!!! jesusescobar Kit & Additional Hardware 4 18-02-2007 18:15
Using Switches on the Operator Interface CronosPrime1 Programming 41 16-02-2006 11:43
Limit switches Team168 Programming 8 10-02-2003 16:22


All times are GMT -5. The time now is 08:59.

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