Here is a quick and dirty way to do it.
What this code will do: While you are pressing a joystick trigger, the respective motor will spin at full speed. If you are not pressing the trigger, it will drive like normal tank drive.
The first thing you'll see is that I made 2 float variables, starting at 0.0. These will be passed into the TankDrive function.
The next thing is the "if" statement. If you are pressing the trigger on stick OR stick2, you then check to see which stick is being pressed, and assign 1.0 to the respective float values.
If you are NOT pressing the joysticks trigger, then the float values will be determined by the Y axis of the joystick.
Finally, those float values will be passed to the TankDrive method.
Forgive any formatting, I wrote it all in here. Also you might have to make one of the values negative, depending on how your motors are set up.
Code:
while (IsOperatorControl() && IsEnabled())
{
float leftValueToUse = 0.0; //2 values that will
float rightValueToUse = 0.0; // be passed to TankDrive
if(stick.GetRawButton(1) || stick2.GetRawButton(1) )
{
if(stick.GetRawButton(1))
{
leftValueToUse = 1.0;
}
if(stick2.GetRawButton(1))
{
rightValueToUse = 1.0;
}
}
else
{
leftValueToUse = stick.GetY();
rightValueToUse = stick.GetY();
}
myRobot.TankDrive(leftValueToUse,rightValueToUse);
Wait(0.005); //Wait for a motor update time
}
Also, this isn't the best way to do it. There is a problem with this way. Think about what will happen if you are driving like normal, and then press and hold one of the joystick triggers. What will happen to the motor you are NOT pressing the respective joystick for? How can you fix that?