 # RC Robot – Part 2 ## 22 May RC Robot – Part 2

Controlling your RC Robot – Part 2 – Doing the math

On this article I will discuss the mathematical implementation of the formulas discussed on Controlling your RC Robot â€“ Part 1 â€“ Intro.

``` X' = X Cos(theta) + Y Sin(theta) Y' = -X Sin(theta) + Y Cos(theta) ```
Where X & Y variables represents the reading from the X & Y axes consecutively, X’ & Y’represents the signals to the left and right motor, and theta should be 45 degrees or PI/4.

Let’s assume that the reading from X & Y axes range from 12 to -12, where Y is 12 when the RC stick is full forward and -12 when it’s full backward, and X is -12 when it’s full left and 12 when it’s full right.

And of course the stick by default rests at (0, 0).

Now we need to do some calculations, I used Excel to calculate the values. You can download the file from here (Axes Calculations).

Now, let’s have a look at the results, assuming that the correction angle equals 0, the result should look like this:

Inspecting the tables, you’ll notice that the values for X’ and Y’ range from 17 to -17. That’s because those values are the resultants of X and Y.

This raises a problem, assume that you put the stick in Full Forward position; from the tables, the Left motor speed should be 8.49 and the Right motor speed should be 8.49. Now if we move the stick to the Full Forward-Full Left position, according to the table the Left motor speed should be 0 and the Right motor speed should be 17. This means that when the vehicle is moving forward, the motors are not in full speed, yet when rotating due to a diagonal stick position, one motor is moving at full speed while the other one rests.

To solve this problem we can simply assume that 8.49 is the maximum motor speed and constrain the output of the formulas to 8.49, this can solve it on the software.

As shown in the figure, all most all joysticks’ motion limits form a square, but on some controllers then use a circular or an octagonal limiting frame, this is another way to solve the problem on the hardware level.