OpenVex  0.5.0
Functions
Arcade Drive

Functions

status_t arcade_drive (signed char joy_x, signed char joy_y, signed char power_max, signed char *left_power_ptr, signed char *right_power_ptr)
 

Detailed Description

These functions provide a convenient interface for arcade drive programs, where a single joystick is used to maneuver the robot (as opposed to tank drive, where two joysticks are used).

Function Documentation

◆ arcade_drive()

status_t arcade_drive ( signed char  joy_x,
signed char  joy_y,
signed char  power_max,
signed char *  left_power_ptr,
signed char *  right_power_ptr 
)

Convert joystick x and y coordinates (-JOY_MAX to +JOY_MAX) to left and right motor speed (-power_max to power_max) for use in skid (differential) steering.

Parameters
joy_xJoystick horizontal position
joy_yJoystick vertical position
left_power_ptrAddress of variable to receive left motor power
right_power_ptrAddress of variable to receive right motor power
power_maxMaximum absolute value for motor power (up to 127 on Vex)
Returns
OV_OK on success, OV_BAD_PARAM on failure

Joystick position to power mapping:

Below is a partial map of the joystick Cartesian plane, showing the desired left and right motor speeds (left,right) for each position on the plane. This map was designed by first defining vehicle behavior at the center position (x,y = 0,0) and at the extremes, where x or y is -JOY_MAX or JOY_MAX. Power values between are linearly interpolated along the x and y axes (not diagonally).

Note: Linear interpolation does not work well for all systems. For example, the nxtremote command for remote control of Lego NXT robots (part of roboctl) warps the mapping of joystick to power using 4th root to compensate for the large dead-band of Lego NXT motors (it takes about 30% power to get a typical robot to start moving at all). See the source code for details. Linear mapping works well for Vex robots, however.

For example, assuming JOY_MAX = 100:

x,y = 0,0:      Vehicle is motionless.
x,y = 0,100:    Full speed straight ahead.
x,y = 100,0:    Full speed turning clockwise about center.
            (Left motor full speed ahead, right full speed reverse)
x,y = 100,100:  Full speed turning about right wheel/track.
            (Left motor full speed, right motor stopped.)
all x>0:        Vehicle is turning clockwise.
all x<0:        Vehicle is turning counter-clockwise.

    0,100       50,100      100,100     100,50      100,0

    -50,100     0,75        50,50       75,0        100,-50

    -100,100    -50,50      0,0         50,-50      100,-100

    -100,50     -75,0       -50,-50     0,-75       50,-100

    -100,0      -100,-50    -100,-100   -50,-100    0,-100

The formula for any single quadrant is simple. A general formula for the entire plane would be ugly. ( Observe how the value of "left" varies across the top of the plane (where y=100), increasing from 0 to 100 over x from -100 to 0, and then becoming a constant 100 for x from 0 to 100. )

However, the values are highly symmetric between adjacent quadrants. left and right are swapped going from any x to -x, and swapped and negated for any y and -y. Hence, we start by computing (left,right) for (|x|,|y|) using the simple formula for quadrant 1, and then for:
2nd quadrant: swap
3rd quadrant: negate
4th quadrant: swap and negate