Log in

View Full Version : One joystink drive


bronxbomber92
16-02-2008, 15:47
Hi,

I'm trying to get something better than the default one joystick drive, but I don't really understand the concept of turning the x and y joystick values into values for each wheel motor (2 motors).

I'm planning on doing something along the lines of using a lookup table to make the robot more handlable, using thisa function instead of a look up table:

long ramping (unsigned char ramp)
{
long answer = 0;
answer = ((long)ramp - 127);
answer = ((answer) * (answer) * (answer));
answer = ((answer) / (128 * 128));
answer = (answer) + (127);
return answer;
}

Can someone explain the concept for turning the joy stick values on each axis into something for each motor?

Thanks

edit - sorry for the typo in the name of the thread, I can't change it.

cmptrgy412
16-02-2008, 22:41
Sure. What you should end up having is code that looks like this:


// on our joystick the x values were inverted
int nTurn = ramping(128 - p1_x) + 127;
int nSpeed = ramping(p1_y - 127) + 127;

int left = (int)Limit_Mix(2000 + nSpeed + nTurn - 127);
int right = (int)Limit_Mix(2000 + nSpeed - nTurn + 127);

// pwm01/pwm02 corresponds to motor PWMs.
pwm01 = left;
pwm02 = 255 - right;



The nTurn and nSpeed will be adjusted based off your ramping.
the left and right values go through a typical 1-joystick function.

Then you just assign those values to your motors.

Steve_Alaniz
17-02-2008, 00:37
DO you want the explanation of the one joystick formula... how they are derived? It's a bit long winded but not complicated. If that's what you want I can post it.
The function you are showing creates a curve based on the cubic values of the inputs. This makes the joystick less sensitive to start up and more sensitive once the bot is going.
Not sure you can "improve" on the one joystick formulas but you can customize them.

jacobhurwitz
17-02-2008, 11:57
DO you want the explanation of the one joystick formula... how they are derived? It's a bit long winded but not complicated. If that's what you want I can post it.
The function you are showing creates a curve based on the cubic values of the inputs. This makes the joystick less sensitive to start up and more sensitive once the bot is going.
Not sure you can "improve" on the one joystick formulas but you can customize them.

The ramping function that BronxBomber gives just cubics the input. This means that a little push from neutral doesn't move the motors too much. Otherwise, your motors will start moving too quickly too soon.

Next you need to know what Limit_Mix function does. It takes a value and bounds it to be between 2000 and 2254, the subtracts 2000, and returns a value from 0 to 254.

The first call to Limit_Mix is
int left = (int)Limit_Mix(2000 + nSpeed + nTurn - 127);
You add 2000 because of the nature of the Limit_Mix function. If p1_x and p1_y are both neutral, then you get 2000+nSpeed+nTurn which is 2254, so you need to subtract 127 to make it 2127 (neutral). Finally, if the y-axis is near 255 (going forward), you want the left wheels forward, so you add nSpeed. If if the x-axis is near 0 (turning right), then nTurn is near 255 so you add nTurn since you want the left wheels going forward as well.

The next call to Limit_Max is
int right = (int)Limit_Mix(2000 + nSpeed - nTurn + 127);
If both axes are neutral, this becomes 2000+127-127, so you have to add 127 to make it 2127. For the same reason described above, you add nSpeed. And for the opposite reason of above, you subtract nTurn.

I know this was complicated, but does it sort of make sense?

bronxbomber92
17-02-2008, 12:21
That makes perfect sense! After running that Limit_Mix logic through my head with the joystick in each direction it's really quite simple :)