Go to Post Ah, free slave labor. One of the many benefits of being a mentor - Ari423 [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
  #5   Spotlight this post!  
Unread 18-12-2007, 00:44
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Using a limit switch to limit motion

It's possible it's a gravity thing, but if not:

Code:
If (input > 127 && limit == 1)
motor = 127;

else
motor = input;
This code simply stops the motor from going forward once it hits its limit.

replace "input" with your input, "limit" with your limit switch and "motor" with the pwm to the motor

If you want to take it to the next step, you could use a potentiometer to keep track, with the use of a variable, what the location of arm is and automatically have it slow down when it reaches a certain point, and stop when it reaches tht limit. Assuming the pot had a range of 0 to 255, the code would look something like this:

Code:
#define Upper_Value 225 //This will slow the motor once the arm reaches within 30 of its max
#define Lower_Value 30  //This will slow the motor once the arm reaches within 30 of its minimum
#define Slow_Speed //The speed in either direction which you want the motor to slow to once it reaches either value
unsigned short Pot_Value; //Declare a variable to keep track of your potentiometer value
Put these #defines at the top of your code. Wherever the name is used in the code, the value will be stubstituted in. Also declare a variable called Pot_Value to keep track of your potentiometer value

Code:
Pot_Value = pot_input; //Update the potentiometer value

if (input > 127 && Toplimit == 1) // If the top limit switch is pressed and the joystick is being pressed forward
	motor = 127;  //Stop the motor, regardless of input

else if (input < 127 && Bottomlimit == 1) // If the bottom limit switch is pressed and the joystick is being pressed forward
	motor = 127;  //Stop the motor, regardless of input

else if (Pot_Value => Upper_Value && input > 127) //If the arm is at or past the upper value and joystick is pressing upward
	motor = 127 + Slow_Speed; //Set the arm to forward slow speed

else if (Pot_Value =< Lower_Value && input < 127) //If the arm is at or below the lower value and joystick is pressing down
	motor = 127 - Slow_Speed; //Slow the arm to reverse slow speed

else //If the arm is between the limits
	motor = input; //assign the motor directly to your input
Again, replace "input" with your input, "motor" with the pwm to the motor, Toplimit with the top limit switch, Bottomlimit with the bottom limit switch and "pot_input" with your potentiometer input

Feel free to PM me if you have any questions.
__________________
 


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
Using a limit switch thunderbolt Programming 1 02-04-2007 19:36
limit switch wedellm Electrical 4 16-02-2007 13:01
Limit Switch Basics JWSnedden Programming 6 30-11-2006 19:48
Limit switch in easy c? chadbarbe Programming 6 02-02-2006 09:51


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

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