Go to Post Let's see. There's the Dean of Students, the Dean of Admissions, The Dean of Engineering, and the Dean of Kamen? Sometimes known as the Denim Dean. - Bill_B [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #16   Spotlight this post!  
Unread 28-04-2005, 12:26
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,113
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 switches

Quote:
Originally Posted by stephenthe1
actually, limit switches are the opposite of that. They are normally 0, or true, then once pressed, turn to 1...
Using the word "pressed" when talking about how the RC digital inputs work is probably a bad idea. Some switches are normally open and close the contacts when activated, while others are normally closed and open the contacts when activated. Some are built with both options at the same time, and you can choose which contacts to use when you connect the wires. They give different results when "pressed", and can be a source of great confusion for people trying to understand how to program for the digital inputs.

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   Spotlight this post!  
Unread 28-04-2005, 12:44
eugenebrooks eugenebrooks is offline
Team Role: Engineer
AKA: Dr. Brooks
no team (WRRF)
 
Join Date: Jan 2004
Rookie Year: 2001
Location: Livermore, CA
Posts: 601
eugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond repute
Re: limit switches

Quote:
Originally Posted by MikeWasHere05
Try adding a printf to your code, see what it puts out.

printf("Limit Switch: %f \n", rc_dig_in08);
printf("Limit Switch: %d \n", (int)rc_dig_in08);

Both the %d and (for our RC compiler) the cast to int are important...
  #18   Spotlight this post!  
Unread 28-04-2005, 19:04
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
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.
__________________
http://www.mikesorrenti.com/
  #19   Spotlight this post!  
Unread 29-04-2005, 01:06
CyberWolf_22's Avatar
CyberWolf_22 CyberWolf_22 is offline
Programming and Electrical Mentor
AKA: Allen Gregory
FRC #2587 (Afrobots)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Houston, Texas
Posts: 227
CyberWolf_22 is just really niceCyberWolf_22 is just really niceCyberWolf_22 is just really niceCyberWolf_22 is just really nice
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   Spotlight this post!  
Unread 05-05-2005, 11:45
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
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   Spotlight this post!  
Unread 10-05-2005, 13:10
Gamer930's Avatar
Gamer930 Gamer930 is offline
Team 930 and 171 Alumni
AKA: Justin
no team
Team Role: Alumni
 
Join Date: Mar 2002
Rookie Year: 2002
Location: New Berlin, WI
Posts: 388
Gamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to behold
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>
__________________
2010 to Present, Scorekeeper/Field Power Volunteer for FRC/FTC/FLL
2005 - 2010, Team 171 College Mentor
2002 - 2005, Team 930 Student
  #22   Spotlight this post!  
Unread 10-05-2005, 14:45
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: limit switches

Quote:
Originally Posted by Gamer2028
...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:
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. */
/* T state variable. */
int intTState = 0;
...
I'd try something like this:

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
Somewhere in main loop:
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;
}
Be advised that I have the code run the motor full speed. If there's no sort of cushion, you could break something. Slow it down if appropriate.
__________________

  #23   Spotlight this post!  
Unread 10-05-2005, 15:17
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
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   Spotlight this post!  
Unread 10-05-2005, 17:28
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
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;
Somewhere in main loop:
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;
}
I'm pretty sure that works... hasn't been compiled, but hey, I'm perfect.
__________________


Last edited by Ryan M. : 11-05-2005 at 13:40.
  #25   Spotlight this post!  
Unread 11-05-2005, 07:26
Gamer930's Avatar
Gamer930 Gamer930 is offline
Team 930 and 171 Alumni
AKA: Justin
no team
Team Role: Alumni
 
Join Date: Mar 2002
Rookie Year: 2002
Location: New Berlin, WI
Posts: 388
Gamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to beholdGamer930 is a splendid one to behold
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??
__________________
2010 to Present, Scorekeeper/Field Power Volunteer for FRC/FTC/FLL
2005 - 2010, Team 171 College Mentor
2002 - 2005, Team 930 Student
  #26   Spotlight this post!  
Unread 11-05-2005, 11:44
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: limit switches

Quote:
Originally Posted by Gamer2028
One question: When you say SWITCH_OFF that isn't defined. Is that suppose to be RC_SWITCH_OFF??
Good catch...lost track of constant names. I'll update my post to reflect this. It's good to see that you aren't just trying to drop the code in without reading through it. Hopefully you were able to get an understanding of what is being done and can expand it and reuse it in the future.
  #27   Spotlight this post!  
Unread 11-05-2005, 13:40
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: limit switches

Quote:
Originally Posted by Gamer2028
One question: When you say SWITCH_OFF that isn't defined. Is that suppose to be RC_SWITCH_OFF??
Yep... good catch. I've updated my second post as well.
__________________

  #28   Spotlight this post!  
Unread 11-05-2005, 15:56
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,113
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 switches

Y'all need to change !SWITCH_ON to !RC_SWITCH_ON as well.
  #29   Spotlight this post!  
Unread 11-05-2005, 16:37
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: limit switches

Quote:
Originally Posted by Alan Anderson
Y'all need to change !SWITCH_ON to !RC_SWITCH_ON as well.
You are correct, however, I can't seem to edit my original post...
Closed Thread


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
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


All times are GMT -5. The time now is 20:47.

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