# HELP Arcade style program for first Robot

How do you get the robot to run off of a single stick arcade style drive? Please help!!!:ahh:

There’s a couple ways to do it, you have to figure out which is most intuitive.

One example:

``````
DRIVE_L = (int) STICK_Y + ((int) STICK_X - 127);
DRIVE_R = (int) STICK_Y - ((int) STICK_X - 127);
DRIVE_L = (DRIVE_L<0)?(0):((DRIVE_L>254)?(254):(DRIVE_L));
DRIVE_R = (DRIVE_R<0)?(0):((DRIVE_R>254)?(254):(DRIVE_R));

``````

The easiest way to get started is to install yourself a copy of easyC.

Open a new project, and open the operator control block.
Create a While(1) loop, with an Arcade drive block inside. Compile and download to the robot.

-Jacob

The code works for left and right, but what about diagonals and other in-betweens.

Notice how the various joy sticks are subtracted from each other in the code sample. This allows for arcade control in the diagonal etc. (At least that is my understanding).

Put the robot up on blocks, so the wheels can spin freely as you test your program.

In a loop, read the joystick fwd/reverse axis into an unsigned char variable called ucjoyfwd. Print it so you can see the value. Copy ucjoyfwd to PWM outputs for both wheels. If one wheel runs backward, reverse the wiring on the Victor so that both run the same way.

In your printout, you see that ucjoyfwd ranges from 0-254 as you move the joystick to change the wheel speeds. I would like you to also load this to an integer variable called ispeed like this:

ispeed = (int) ucjoyfwd - 127

If you print ispeed too, you will see that it ranges from -127 to +127, as ucjoyfwd ranges from 0 to 255. In this new range, you can think of 0 as “stopped”, -127 as “full speed reverse”, 127 as “full speed forward”.

Now instead of copying ucjoyfwd to the PWM outputs, copy (ispeed + 127) to them instead … which converts ispeed back to the 0-254 range for the purposes of controlling the PWM Victors. The wheels should still turn the same ways and same speeds as before.

ispeedleft = ispeed + 127
ispeedright = ispeed + 127

Now for rotation, we want the wheels to spin at different speeds. So we want to take ispeed and add speed to one wheel, and take it away from the other.

So read the joystick left/right axis value into a different variable ucleftright, and convert it to the +/- 127 range using the same method. Print ucleftright and irotate, to see what they are doing as you move the joystick.

irotate = (int) ucleftright - 127

Now we’re coming to the good part.

ispeedleft = ispeed - irotate;
if (ispeedleft > 127) ispeedleft = 127
if (ispeedleft < -127) ispeedleft = -127

ispeedright = ispeed + irotate
if (ispeedright > 127) ispeedright = 127
if (ispeedright < -127) ispeedright = -127

Send ispeedleft + 127 to one PWM Victor, ispeedright + 127 to the other.

Now the fwd/rev motion of the joystick controls your base speed, and the left/right motion controls the difference in speed between left and right motors (ie: the robot turns).