View Single Post
  #4   Spotlight this post!  
Unread 12-02-2009, 10:14
sircedric4's Avatar
sircedric4 sircedric4 is offline
Registered User
AKA: Darren
no team (The SS Prometheus)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Lousiana
Posts: 245
sircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond repute
Re: chaging values on an axis/toogle switch

Quote:
Originally Posted by Alex_2487 View Post
we are using the throttle axis on the joystick so it will work program the second way


right now my code for a motor is this

if (Thirdjoystick->GetRawButton (2)==1 )
{
frontroller->set(-1.0);
}
else if (Thirdjoystick->GetRawButton (3)==1 )
{
frontroller->set(1.0)
}
esle
{
frontroller->set(0.0)
}

right now the motor is off when we turn on the robot and when we hold down button 2 it rruns backwards and button 3 runs forward. i want to be able to make it so the second driver doesnt need to hold down the button and can just press it to switch between forward and stop and on the other button switch between backward and stop.

In this case you'll need to set a flag up. This will be in psuedocode but it will be something like:

You need to set a flag when the button is pressed, the problem is that the button is in an endless loop so you'll have to make sure you only poll the Buttonflag once each time the button is held down, so you'll need another flag for that.

Define a ButtonFirstflag
Define a Button2flag
Initialize the variables at the beginning:
Button2flag=false;
ButtonHeldflag = true;


if (Button2) {
if (ButtonFirstflag) {
if (!Button2flag) {
Button2flag = true;
} else {
Button2flag = false;
}
ButtonHeldflag = false;
}
ButtonHeldflag = true;

If (Button2flag) {
Motor = forward
} else {
Motor = stop
}

There maybe an easier means to do what you are asking, but this is what I use when I want to do what you are talking about. I hope I've helped.
Reply With Quote