|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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" ) ;
}
}
Please, any comments will help me, especially since I need to get this working by tomorrow... Thanks ![]() |
|
#2
|
||||
|
||||
|
Re: Using Limit Switches with the Arm
We've had similar problems with understanding what certain parts are supposed to do - it can get very confusing. Just tonight i tried a different tactic with one of the students and it seemed to make everything a LOT clearer. Set everything up in a big truth table, and then build your conditionals from that. I'm not sure i understand your situation well enough to help with a truth table for you specifically, but here's the situation that we have:
two buttons on the controller: B1 spins a wheel in to suck up a ball, while B2 spins it out to spit out a ball. In both cases, we only want the wheel spinning as long as the button is pressed. If both buttons are pressed at once, we don't care what is happening. a limit switch: When the ball hits the limit switch, we know the ball is in our traveling position, so we don't want the motors to be able to spin inwards anymore (but they CAN spin outwards). so the truth table would be: Code:
B1 | B2 | S1 | wheels ---------------------- T | T | T | (not in) T | T | F | (don't care) T | F | T | stop T | F | F | in F | T | T | out F | T | F | out F | F | T | stop F | F | F | stop Code:
if (B1 is pressed and S1 is not pressed)
spin the wheels in //this happens for lines 2 and 4
else if (B2 is pressed)
spin the wheels out //this happens for lines 1, 5, and 6
else
stop the wheels //this happens for lines 3, 7, and 8
|
|
#3
|
||||
|
||||
|
Re: Using Limit Switches with the Arm
have you considered just using an encoder?
|
|
#4
|
|||
|
|||
|
Re: Using Limit Switches with the Arm
Thank you both for your help. I'm pretty sure that I have a working limit switch code now
![]() I took your eagle and made a truth table. This helped me out a lot while I was coding... L1|L2|L3|L4|Disallow| --------------------- T F F F Retraction - CHECK T T F F Retraction - NOT INCLUDED T F T F Retraction - NOT INCLUDED T F F T Extention, Retraction, Rotation from where it came F T F F Forward Rotation, Extention - CHECK F F T F Reverse Rotation, Extention - F F F T Extention, Retraction, Rotation from where it came F F F F Allow all movement - NOT INLCUDED I also found that my code was overcomplicated, and could have been simplified to the ones posted here: http://www.chiefdelphi.com/forums/sh...ad.php?t=60186 And popo, yeah I could have probably used an encoder, but this is my first year in FIRST (lol) and it is my team's second year, so we've not yet had to chance to use those, and with one day left we probably won't get to this season. I also didn't want to let my team down, they did a lot of work cutting stuff to hold the limit switches in place ![]() With every year comes advancement... |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |