Go to Post It's like FIRST saying "Well it was too hard, so we give up. Lets give the kids something easier to do." How is that supposed to inspire kids? - Mike [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-02-2011, 09:41
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
limit switch problem

After 16 hour of working on two limit switches, they still won't work. I wrote a code for our limit switches that when our top limitswitch is pressed it would stop the motor from going up so the motor can only go down, and when the bottom one is pressed it stops the motor from going down so the motor can only go up. The problem is that I does not do any of that. Can any one please review this code an tell me where I went wrong?

Code:
		    if (ds->GetDigitalIn(3) != 1 || ds->GetDigitalIn(3) != 1 && Carriage_down->Get() == 0)
		    {			    
			    Carriage_motor->Set(1.0);
			    while(Carriage_down->Get() == 0)
			    {
			    	Carriage_motor->Set(0.0);
			    }
		    }
		    else if(ds->GetDigitalIn(4) != 1 || ds->GetDigitalIn(4) != 1 && Carriage_up->Get() == 0)
		    {
		    	Carriage_motor->Set(-1.0);
			    while(Carriage_up->Get() == 0)
			    {
			    	Carriage_motor->Set(0.0);
			    }
		    }
		    else
		    {
		      	Carriage_motor->Set(0.0);
		    }

Last edited by krudeboy51 : 22-02-2011 at 09:55.
Reply With Quote
  #2   Spotlight this post!  
Unread 22-02-2011, 13:55
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: limit switch problem

Quote:
Originally Posted by Straberrie View Post
From what I understand, you just want your motor to stop if it reaches any of the above. Your code seems a little too complex for something that should really only be a few lines.
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);
Reply With Quote
  #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
Reply


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


All times are GMT -5. The time now is 12:35.

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