View Single Post
  #2   Spotlight this post!  
Unread 25-02-2007, 01:20
Stvn's Avatar
Stvn Stvn is offline
FIRST Competition Competer
AKA: Steven Rhodes
FRC #0100 (WHS/CHS - WildHats)
Team Role: Leadership
 
Join Date: Feb 2007
Rookie Year: 2004
Location: Woodside, CA
Posts: 90
Stvn is an unknown quantity at this point
Send a message via AIM to Stvn
Re: PROGRAMMING PNEUMATICS

Quote:
Originally Posted by dpick1055 View Post
It's actually fairly simple to have the trigger control an action with the pneumatics. What have you to do is declare some variable like handstate.

Then when your trigger is pressed changed the value of handstate to 1 or 0. Then when the trigger is pressed you know whether your hand is opened or closed and you can do an action based on it.
Code:
int handstate;
handstate = 0; //default position for whatever your using

if (p1_sw_trig == 1 && handstate == 0)
{
relay2_fwd = 1;
handstate = 1;
}
if (p1_sw_trig == 1 && handstate == 1)
{
relay2_rev = 1;
handstate = 0;
}
Wouldn't that code just rapidly switch between forward and reverse relays? The handstate would immediately change to 1 when the trigger is pressed, so the next if statement will be true and the relay will be set to reverse. You need to check when the trigger is depressed. Something like:
Code:
int handstate;
handstate = 0; //default position for whatever your using

if (p1_sw_trig == 1 && handstate == 0)
{
relay2_fwd = 1;
handstate = 1;
}
if (p1_sw_trig == 0 && handstate == 1)
{
handstate = 2;
}
if (p1_sw_trig == 1 && handstate == 2)
{
relay2_fwd = 1;
handstate = 3;
}
if (p1_sw_trig == 0 && handstate == 3)
{
handstate = 0;
}
I think. Please correct me if I am wrong.
__________________