The trick with designing a controller this robot is figuring out how a joystick should control the two wheels.

The wheels on our robot do not pivot left and right like the wheels of your car.

Ackerman_Steering_Linkage.gif

So this means that we need to use "differential steering" (sometimes referred to as "skid steering", but this term is more common in construction equipment). So we change the direction and speed that each of the wheels rotates in order to make the robot move the way we want.

But the joystick gives us X and Y coordinates. So how do we translate these coordinates into the movements of the motors?

When the joystick is pointing straight forward, both left and right wheels need to turn forward.

wfKRxtr.png

When the joystick is pointing straight backward, both left and right wheels need to turn backward.

TT5ZcGB.png

When the joystick is pointing directly to the right, the left wheel needs to move forward and the right wheel needs to move backward.

kLalkQc.png

When the joystick is pointing directly to the left, the left wheel needs to move backward and the right wheel needs to move forward.

p2LOCAq.png

These 4 positions make sense. But what about when the joystick is pointed diagonally? How should the wheels respond? I spent many late nights trying to figure this out. There are a few other blog posts that cover different takes, and each has its own advantages.

For the simplest approach, I found a setting on my RC airplane controller for "elevon" control. This sets the power and direction to the left and right wheels as a simple linear function of the X and Y coordinates of the joystick.

leftSpeed = Y - X
rightSpeed = Y + X

This was super easy to translate into Arduino code. Here is a JavaScript tool I built with P5.js to demonstrate how this works. Drag your mouse cursor around the box to see how different joystick positions translate to left and right wheel movements.

This approach works reasonably well, but it has a few issues. Most importantly, when you point the joystick forward or backwards, it doesn't move at its full speed. (Notice how the arrows get longer at the corners than when pointed forward.) So we'll have to find a way to fix that, but it works for a quick solution.