task shooterInput()
{
int dB = 15; // dead zone for joystick input
while(true){
//This Section deals with the commands to the shooter from the controler
// this enables the user to modify the power setting
//the buttons on the right pad are as follows, up = +1 FPS power increase
//down = -1 FPSpower decrease, left = zero power, right = 15 FPSpower
//The right Joystick will slowly increase or decrease the power value
// POWER IS IN FPS OF THE WHEEL EDGE
if(vexRT[Btn8UXmtr2] == 1){// gradual power increase
power = power+(1);
wait10Msec(30);
}
else if(vexRT[Btn8DXmtr2] == 1){
power = power-(1);
wait10Msec(30);
}
else if(vexRT[Btn8LXmtr2] == 1){
power = 0;
wait10Msec(30);
}
else if(vexRT[Btn8RXmtr2] == 1){
power = 15;
wait10Msec(30);
}
else if(abs(vexRT[Ch2Xmtr2]) > dB){
power = power + (vexRT[Ch2Xmtr2])/(127*2) ;
wait10Msec(10);
}
if(power > 50){
power = 50;
}
if(power < 0){
power = 0;
}
if(vexRT[Btn7RXmtr2] == 1){
motor[shot1] =motor[shot2] = motor[shot4] = motor[shot3] = 0;
}
//This Displays the Current power setting to the Shooter
displayLCDNumber(1,0,power,4);
}
}
this is the code that allows me to update the power settings of my shooter during driver control
my problem is that the right joystick is supposed to allow me to adjust the power setting as well, but it doesn’t work, everything else works fine, the joystick bit doesn’t
Is power an integer or a float or what because with the joystick you are increasing it by 1/2 at most?
I would check the power variable because it only increases by 1/2 at the most. If it were an int, then it wouldn’t be able to hold decimal values.
EDIT:
I was a little too late.
EDIT2: An easy fix would be to change to a float as Highwayman has mentioned
What’s funny is a friend of mine had a similar problem with his code for ramping up/down the flywheel speed. Otherwise, I doubt I would have caught this.
So, yeah, watch out for your integers getting truncated when you are integrating/summing.
The problem lies in line 38:
Your variable “power” may be a float, but the equation “((vexRT[Ch2Xmtr2])/(127*2)” contains only int and word types, and thus will return an int. This is a problem, because the maximum value that can be added is (127)/(254), or 0.5, which as an int would become 0. You need to make your equation evaluate as a float. The easiest way to do that would be to change the line to be:
power = power + (vexRT[Ch2Xmtr2])/(127*2.0) ;
that did it, Awesome, and thanks for the help guys.
just learned something new about robot C.
No problem! As a good rule of thumb, any time an equation is done, the return value will only be as “complex” as the most “complex” value in the equation. Keep in mind that if you were to do something such as:
float var = ((1 / 2) * (3 * 4.0));
It will not set var to the desired value (6). Even though the right half of the equation will evaluate to be a float, the left half (which is evaluated first) will not, causing the value to be 0. However, if you were change which side has a float, such as:
float var = ((1 / 2.0) * (3 * 4));
Then, var would have a value of 6. Just remember your order of operations, and when in doubt, use casting or the trick I used in my examples.