View Single Post
  #3   Spotlight this post!  
Unread 22-02-2011, 14:04
Straberrie's Avatar
Straberrie Straberrie is offline
The Plague
AKA: Rebecca
FRC #0375 (Robotic Plague)
Team Role: Programmer
 
Join Date: Feb 2008
Rookie Year: 2007
Location: New York
Posts: 59
Straberrie will become famous soon enough
Re: limit switch problem

Quote:
Originally Posted by Alan Anderson View Post
If the motor is forced to stop whenever a limit switch is pressed, it will stick at the end of its travel and never be able to leave.

One easy way to do it "right" is to use the "top limit" switch to turn off the motor only if it's being commanded up, and use the "bottom limit" switch to turn off the motor only if it's being commanded down.

Code:
  // use operator console buttons to decide which way to run the motor
  if (ds->GetDigitalIn(3) != 1)
    motorvalue = 1;
  else if (ds->GetDigitalIn(4) != 1)
    motorvalue = -1;
  else
    motorvalue = 0;
  // stop motor from being commanded forward if at lower limit
  if (Carriage_down->Get() == 0 &&  motorvalue > 0)
    motorvalue = 0;
  // stop motor from being commanded backward if at upper limit
  if (Carriage_up->Get() == 0 && motorvalue < 0)
    motorvalue = 0;
  Carriage_motor->Set(motorvalue);

I deleted my post, it was wrong, thank you for correction! =D
__________________
Team 375: The Robotic Plague
Current Robot: I-Chihuahua
Last Event: Big Apple Breakaway
Reply With Quote