|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
|||||
|
|||||
|
Re: limit switches
Quote:
The RC digital inputs have a pullup resistor to +5 volts. Reading them will return a 1 when the switch is open, and a 0 when the switch is closed to ground. |
|
#17
|
|||
|
|||
|
Re: limit switches
Quote:
Both the %d and (for our RC compiler) the cast to int are important... |
|
#18
|
|||||
|
|||||
|
Re: limit switches
Heh, yeah sorry about that. It is %d not %f. It's little (seemingly) trivial things like that that always get me.
eugene: I've never used (int) before, and my printf's work fine. |
|
#19
|
|||||
|
|||||
|
Re: limit switches
I am not sure if the question has been answered or not but I can't really diagnose the problem with out the code but what my first idea would be is that there is not an else statement following his if statement to turn the motor off when the switch is not pressed.
if (button8 == 1) {pwm01 = 254;} else {pwm01 = 127;} Wait, after rereading some of the posts maybe this is not the problem. Please post your code so we can further diagnose it. Last edited by CyberWolf_22 : 29-04-2005 at 01:09. |
|
#20
|
|||
|
|||
|
Re: limit switches
thanks for all your help. I've got it working now. the problem was just in how I was accessing the limit switch in the code. there was a variable that wasn't being reset when the switch changed its state. thanks for all your help. Originally, this wasn't the only problem, we had problems wth our buttons that kept messing me up too. but now that's all solved. thanks for the help!!!
the code you posted worked fine. thanks again. |
|
#21
|
|||||
|
|||||
|
Re: limit switches
I searched and couldn't find and couldn't think through the code for:
I have a motor and 2 Limit Switches that sets the upper and lower limits of an arm from our 2003 Robot. I want to have it so when I hit a Trigger on the joystick it sends the motor forward until it hits the Top limit switch or if it is already at the top to reverse the motor until it hits the Bottom Limit Switch. I have: #define T_DRIVE pwm01 #define Up_T_Limit rc_dig_in01 /* Limit Switch on Full Up Set */ #define Down_T_Limit rc_dig_in02 /* Limit Switch on Full Down Set */ #define T_BUTTON_BTN p2_sw_trig /* Button to change T state. */ /* T state variable. */ int intTState = 0; Thanks in advance <slightly off topic> This is for an off season project to convert our PBASIC 2003 robot into a vision robot for presentations </slightly off topic> |
|
#22
|
||||
|
||||
|
Re: limit switches
Quote:
Somewhere at top of file: Code:
// Your stuff #define T_DRIVE pwm01 #define Up_T_Limit rc_dig_in01 /* Limit Switch on Full Up Set */ #define Down_T_Limit rc_dig_in02 /* Limit Switch on Full Down Set */ #define T_BUTTON_BTN p2_sw_trig /* Button to change T state. */ int intTState = 0; /* T state variable. */ // My stuff #define RC_SWITCH_ON 0 #define RC_SWITCH_OFF !SWITCH_ON #define OI_SWITCH_ON 1 #define OI_SWITCH_OFF !OI_SWITCH_ON #define T_STATE_UP 1 #define T_STATE_DOWN !T_STATE_UP Code:
if(T_BUTTON_BTN == OI_SWITCH_ON)
{
// Switch states. We could do it with intTState = !intTState,
// but just for clarity...
if(intTState == T_STATE_UP)
{
intTState = T_STATE_DOWN;
}
else
{
intTState = T_STATE_UP;
}
}
if(intTState == T_STATE_UP && Up_T_Limit == SWITCH_OFF)
{
// We need to go up more
T_DRIVE = 255;
}
else if(intTState == T_STATE_DOWN && Down_T_limit == SWITCH_OFF)
{
// We need to go down more
T_DRIVE = 0;
}
else
{
// We are at our goal. Stop motor
T_DRIVE = 127;
}
|
|
#23
|
||||
|
||||
|
Re: limit switches
Ryan, I don't think that your code is going to do what was requested. With your code, every time it gets called you will change your intTState. I think what you're trying to do is as follows...(This is uncompiled and untested, so be sure to understand the code before trying to run it)
Code:
#define T_DRIVE pwm01
#define Up_T_Limit rc_dig_in01 /* Limit Switch on Full Up Set */
#define Down_T_Limit rc_dig_in02 /* Limit Switch on Full Down Set */
#define T_BUTTON_BTN p2_sw_trig /* Button to change T state. */
//NOTE: THIS VALUE MAY CHANGE IF YOUR SWITCH IS NORMALLY OPEN
#define RC_SWITCH_ON 0
// Added parens around the operation to be safe
#define RC_SWITCH_OFF (!SWITCH_ON)
#define OI_SWITCH_ON 1
// Added parens around the operation to be safe
#define OI_SWITCH_OFF (!OI_SWITCH_ON)
#define T_STATE_UP 1
// Added parens around the operation to be safe
#define T_STATE_DOWN (!T_STATE_UP)
// Depending on where this is you'll probably want to make it static
// Also I changed this from a hardcoded 0 to a constant (assuming it starts at the bottom)
static int intTState = T_STATE_UP; /* T state variable. */
...
if(T_BUTTON_BTN == OI_SWITCH_ON)
{
// The button is pressed, let's move the motor
if(intTState == T_STATE_UP)
{
// Currently moving up
if(Up_T_Limit == RC_SWITCH_OFF)
{
// We need to go up more
T_DRIVE = 255;
}
else
{
// We were moving up and hit the upper switch
// Stop the motor and change the state
initTState = T_STATE_DOWN;
T_DRIVE = 127;
}
}
else if(intTState == T_STATE_DOWN)
{
// Currently moving up
if(Down_T_Limit == RC_SWITCH_OFF)
{
// We need to go down more
T_DRIVE = 0;
}
else
{
// We were moving down and hit the lower switch
// Stop the motor and change the state
initTState = T_STATE_UP;
T_DRIVE = 127;
}
}
else
{
// We are in a bad state, stop the motor
T_DRIVE = 127;
}
}
Last edited by Dave Scheck : 11-05-2005 at 11:45. |
|
#24
|
||||
|
||||
|
Re: limit switches
Yep, you're right. I didn't think to include a "the press is from the last time through!" check. Your code should work, but just for the sake of completeness...
(new stuff in bold)Somewhere at top of file: Code:
// Your stuff #define T_DRIVE pwm01 #define Up_T_Limit rc_dig_in01 /* Limit Switch on Full Up Set */ #define Down_T_Limit rc_dig_in02 /* Limit Switch on Full Down Set */ #define T_BUTTON_BTN p2_sw_trig /* Button to change T state. */ int intTState = 0; /* T state variable. */ // My stuff #define RC_SWITCH_ON 0 #define RC_SWITCH_OFF !SWITCH_ON #define OI_SWITCH_ON 1 #define OI_SWITCH_OFF !OI_SWITCH_ON #define T_STATE_UP 1 #define T_STATE_DOWN !T_STATE_UP int buttonPressedLastTime = 0; Code:
if(T_BUTTON_BTN == OI_SWITCH_ON)
{
// Switch states only if this button press isn't from a loop before
// (the user held it down).
if(buttonPressedLastTime == 0)
{
if(intTState == T_STATE_UP)
{
intTState = T_STATE_DOWN;
}
else
{
intTState = T_STATE_UP;
}
}
buttonPressedLastTime = 1;
}
else
{
buttonPressedLastTime = 0;
}
if(intTState == T_STATE_UP && Up_T_Limit == RC_SWITCH_OFF)
{
// We need to go up more
T_DRIVE = 255;
}
else if(intTState == T_STATE_DOWN && Down_T_limit == RC_SWITCH_OFF)
{
// We need to go down more
T_DRIVE = 0;
}
else
{
// We are at our goal. Stop motor
T_DRIVE = 127;
}
![]() Last edited by Ryan M. : 11-05-2005 at 13:40. |
|
#25
|
|||||
|
|||||
|
Re: limit switches
Thanks for the help. I partly finished rewiring and converting it to 2004 last night. I will finish up this weekend and let you all know.
One question: When you say SWITCH_OFF that isn't defined. Is that suppose to be RC_SWITCH_OFF?? |
|
#26
|
||||
|
||||
|
Re: limit switches
Quote:
|
|
#27
|
||||
|
||||
|
Re: limit switches
Quote:
|
|
#28
|
|||||
|
|||||
|
Re: limit switches
Y'all need to change !SWITCH_ON to !RC_SWITCH_ON as well.
|
|
#29
|
||||
|
||||
|
Re: limit switches
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Common Ground on Limit Switches | Gary Bonner | Electrical | 4 | 18-02-2005 13:24 |
| Robot Controller File Size Limit ?? | RoboGeek | Programming | 1 | 17-01-2005 19:59 |
| material cost limit | haverfordfords | Fundraising | 3 | 06-12-2004 19:21 |
| Limit Switches help. | Xufer | Programming | 9 | 21-04-2004 21:21 |
| Need help with custom switches | archiver | 2001 | 3 | 24-06-2002 00:35 |