It really is up to us to stand up for these principles so when we sell it to the general public we're not just feeding them some line because if we don't believe it, why should they? - Koko Ed [more]
 Chief Delphi Limit Switches
 User Name Remember Me? Password
 CD-Media CD-Spy
 portal register members calendar search Today's Posts Mark Forums Read FAQ rules

#1
01-25-2008, 05:37 AM
 ChrisR_522 Registered User FRC #0522 (Robo Wizards) Join Date: Apr 2006 Rookie Year: 2005 Location: Staten Island, New York Posts: 20
Limit Switches

How can we go about thoroughly programming the limit switches to control a specific motor using MPLab,
ex: if ((dig_in03)) { pwm03 = p3_y; } else { pwm03 = 127; }
Is that the correct way?

Any help would be greatly appreciated, Thanks!
__________________
http://robowizards.com/
#2
01-25-2008, 06:10 AM
 Roger Registered User FRC #1153 Join Date: Jan 2006 Rookie Year: 1900 Location: Walpole MA Posts: 677
Re: Limit Switches

You're up a bit late, aren't cha? (Or early? Do programmers ever get to see the sun?)

I think it's rc_dig_in03.

Here's some code we had from last year, using joystick 2 y-axis to move the grabber arm up or down (like your lower arm with the motor at the elbow). We had a limit switch (LS) at the top and bottom to stop the motor, but allows it to go the other way even if it reaches the limit switch.
Code:
```   //-------------------------- ARM WORK 3 -------------------------------------
//Arm desired direction is from JoyStick2, Y-axis. UP goes fwd, DOWN is back.
//pwm05 is the motor. LimitSwitch 5 and 7 is fwd and back stop points.
//Change pwm numbers of motor, LS, and Joystick as need be.
if (p2_y >(127+50))                          //If Joystk2 Y pushed up - arm forward
{
if (rc_dig_in05 == 0)                     //is LS5 not pressed?
{ pwm05= 127+3; }                     //  No- turn motor on!
else
{ pwm05= 127; }                        // Yes- turn motor off!
}
else if (p2_y < (127-50))                    //If Joystk2 Y pulled back - arm backwrd
{
if (rc_dig_in07 == 0)                     //is LS7 not pressed?
{ pwm05= 127-3; }                     //  No- turn motor on!
else
{ pwm05= 127; }                        // Yes- turn motor off!
}
else
{ pwm05= 127; }                           //Turn motor off```
Of course if you're doing autonomous, don't use the joystick! Just remember to cover all possibilities (all if/ifelse/else's) so you know at the end the motors are on or off.

This wasn't our final code, but it did work at the time. As always YMMV.
______________________
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.
#3
01-25-2008, 07:04 AM
 ChrisR_522 Registered User FRC #0522 (Robo Wizards) Join Date: Apr 2006 Rookie Year: 2005 Location: Staten Island, New York Posts: 20
Re: Limit Switches

Hey, thank you so much! It worked!
__________________
http://robowizards.com/

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     User Announcements FIRST     General Forum         FIRST E-Mail Blast Archive     Rumor Mill     Career     Robot Showcase Technical     Technical Discussion     Robotics Education and Curriculum     Motors     Electrical         CAN     Programming         NI LabVIEW         C/C++         Java         Python     Control System         FRC Control System         Sensors     Pneumatics     Kit & Additional Hardware     CAD         Inventor         SolidWorks         Pro ENGINEER / Creo     IT / Communications         3D Animation and Competition         Website Design/Showcase         Videography and Photography         Computer Graphics     National Instruments LabVIEW and Data Acquisition         LabView and Data Acquisition Competition     Awards         Chairman's Award     Rules/Strategy         Scouting         You Make The Call     Team Organization         Fundraising         Starting New Teams         Finding A Team         College Teams     Championship Event     Regional Competitions     District Events     Off-Season Events     Thanks and/or Congrats     FRC Game Design     OCCRA         OCCRA Q&A         OCCRA Programming Other     Unsung FIRST Heroes     Chit-Chat         Games/Trivia             Fantasy FIRST     Car Nack's Corner     College & University Education     Dean Kamen's Inventions     FIRST-related Organizations         Western Region Robotics Forum         Southern California Regional Robotics Forum         FIRST Interactive Rural SupporT         FIRST Scouting Network         FIRSTwiki         The Blue Alliance             Video Archives     FIRST In the News...     FIRST Lego League         Lego Mindstorm Discussion     FIRST Tech Challenge     VEX         VEX Robotics Competition         VEX IQ     Televised Robotics     Math and Science         NASA Discussion ChiefDelphi.com Website     CD Forum Support     Extra Discussion Old Forum Archives     1999     2000     2001

 Similar Threads Thread Thread Starter Forum Replies Last Post Alternative to limit switches? RbtGal1351 Electrical 27 12-10-2005 02:30 PM limit switches stephenthe1 Programming 28 05-11-2005 03:37 PM Limit Switches help. Xufer Programming 9 04-21-2004 08:21 PM Limit switches Team168 Programming 8 02-10-2003 03:22 PM Limit Switches/Pots Brett W Technical Discussion 3 01-28-2003 01:25 PM

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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.

 -- English (12 hour) -- English (24 hour) Contact Us - Chief Delphi - Rules - Archive - Top