Go to Post you don't need a fancy workshop to build a good robot, just determined people. - pacoliketaco [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
  #1   Spotlight this post!  
Unread 25-02-2004, 13:01
BobcatProgramer BobcatProgramer is offline
Registered User
AKA: Brian
FRC #0758 (Roboticats)
Team Role: Mentor
 
Join Date: Dec 2003
Rookie Year: 2002
Location: University of Western Ontario
Posts: 12
BobcatProgramer is an unknown quantity at this point
Send a message via MSN to BobcatProgramer
Question Button Programing

I have a relay programed to a button but now I want it to be a press to be forward and then press again to reverse. For example, I am using a selanoid and i want to press the button to have the cylinder go out then the next time i press it the cylinder go in. I can do this easilly in p-basic but I have tried to do it in C and I can't get it to work right. Could anyone give me a hand with this by posting code. It would be appreciated. Thanks
  #2   Spotlight this post!  
Unread 25-02-2004, 13:14
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: Button Programing

Put something this in your user_routine, substituting appropriately for switch_value and relay_fwd/rev:

Code:
static char relay_state = 0; /* 0 means forward, 1 means reverse */
static char last_switch_value = 1; /* will remember the last state of the switch */


if ((last_switch_value == 0) && (switch_value == 1))
{
    // here is where you toggle the relay state
    relay_state = 1-relay_state;
    if (relay_state == 0)
    {
        relay_fwd = 1;
        relay_rev = 0;
    }
    else
    {
        relay_fwd = 0;
        relay_rev = 1;
    }
}
last_switch_value = switch_value;
  #3   Spotlight this post!  
Unread 25-02-2004, 15:53
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Button Programing

Quote:
Originally Posted by Alan Anderson
Put something this in your user_routine, substituting appropriately for switch_value and relay_fwd/rev:

Code:
static char relay_state = 0; /* 0 means forward, 1 means reverse */
static char last_switch_value = 1; /* will remember the last state of the switch */


if ((last_switch_value == 0) && (switch_value == 1))
{
    // here is where you toggle the relay state
    relay_state = 1-relay_state;
    if (relay_state == 0)
    {
        relay_fwd = 1;
        relay_rev = 0;
    }
    else
    {
        relay_fwd = 0;
        relay_rev = 1;
    }
}
last_switch_value = switch_value;
Can't you do:
Code:
//...
//Init Relays
relay1_fwd = 1;
relay1_rev = 0;
//...
if (OI_Switch)
{
 relay1_fwd = !relay1_fwd;
 relay1_rev = !relay1_rev;
}
Just be sure to only do it again after a certain time. 26.2 ms is still fast, 38 hz fast.
  #4   Spotlight this post!  
Unread 25-02-2004, 16:01
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: Button Programing

Quote:
Originally Posted by Astronouth7303
Can't you do:
Code:
//...
//Init Relays
relay1_fwd = 1;
relay1_rev = 0;
//...
if (OI_Switch)
{
 relay1_fwd = !relay1_fwd;
 relay1_rev = !relay1_rev;
}
Just be sure to only do it again after a certain time. 26.2 ms is still fast, 38 hz fast.
Clever. That would work. Just make sure to have the variables static.
__________________

  #5   Spotlight this post!  
Unread 25-02-2004, 16:37
Phil_Lutz's Avatar
Phil_Lutz Phil_Lutz is offline
Phil Lutz
#0851 (Froggers)
Team Role: Mentor
 
Join Date: Jan 2004
Location: El Segundo, CA
Posts: 67
Phil_Lutz is on a distinguished road
Send a message via Yahoo to Phil_Lutz
Re: Button Programing

We coded buttons/triggers to only activate on release, that helps control the longggggggggg button push

Phil
  #6   Spotlight this post!  
Unread 25-02-2004, 16:43
JoshJ JoshJ is offline
Registered User
#0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Salem County
Posts: 44
JoshJ is on a distinguished road
Send a message via AIM to JoshJ
Re: Button Programing

I would do this so your relays dont pulse 40x a second I don't know whose code I just added to tho... sorry

int flag=0;
//...
//Init Relays
relay1_fwd = 1;
relay1_rev = 0;
//...
if (OI_Switch && !flag)
{
relay1_fwd = !relay1_fwd;
relay1_rev = !relay1_rev;
flag=1;
}
if (!OI_Switch)
{
flag=0;
}
  #7   Spotlight this post!  
Unread 25-02-2004, 16:43
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Button Programing

Quote:
Originally Posted by Phil_Lutz
We coded buttons/triggers to only activate on release, that helps control the longggggggggg button push
Double clever!

[edit]
My code (With suggestion):
Code:
//...
//Init Relays
relay1_fwd = 1;
relay1_rev = 0;
//...
static char SwitchVals = 0;
if (OI_Switch)
{
 SwitchVals = 1;
}

if (!OI_Switch & SwitchVals)
{
 relay1_fwd = !relay1_fwd;
 relay1_rev = !relay1_rev;
 SwitchVals = 0;
}
Of course, you still have to integrate it.

Last edited by Astronouth7303 : 25-02-2004 at 16:52.
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
pnumatic programing jacob_dilles Programming 8 24-02-2004 21:49
which button machine do you use and do you like it? KenWittlief General Forum 10 16-10-2003 00:01
Who is doing the programing for team 61 Walter_Jr Programming 5 25-01-2003 00:31
Select button and user mode n[ate]vw Programming 2 20-01-2003 16:33
Programing of controller DLyons Robotics Education and Curriculum 2 02-12-2002 00:16


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

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