chaging values on an axis/toogle switch

is thier a way to change the values that an axis gives out. right now i am using this code

BeaterBars->Set(GetZ());

and it gives out values -1.0 to 1.0. and we have no need for our system to run backwards. how would i change it to values 0.0 to 1.0.

also does anyone know how to program a toogle switch so we don’t have to keep a button held down.

You can clamp the joystick values from the joystick pretty easily.

float inputZ = stick->GetZ();
if(inputZ < 0.0)
inputZ = 0.0;

motor->Set(inputZ);

As for the toggle switch, what exactly are you using it for? If you are wanting to use a toggle switch that you on the driver station digital IO, you can just check the driver station inputs with driverStation->GetDigitalInput(channel);

EDIT: The above method for clamping would disregard anything below 0. If you want -1 to equal 0, 0.0 to equal 0.5, and 1.0 to equal 1.0, you can do this (although it would be very unintuitive for the driver):

motor->Set((stick->GetZ()+1.0)/2);

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.