# Motor Power vs. Robot Movement

At the moment, our motors are set to power on to a full forward at the start of our program. For reference, the image below shows the full scale of movement between forward and reverse:

<figure><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUOOiQ4S2QcMWmVoSmeQ8%2Fuploads%2FOHC44sVseu4kkoyU5wYT%2Fsettingpower.png?alt=media&#x26;token=0cc480ca-0dfd-46ae-8246-7ba02159588f" alt=""><figcaption></figcaption></figure>

Let's take this information and think back to when we first[ programmed a motor](https://docs.revrobotics.com/duo-control/hello-robot-blocks/part-1/programming-motors/programming-a-motor-with-a-gamepad) to move with our gamepad. During that section our motor was able to rotate at different power levels depending on how far and in which direction our joystick moved. However, do you recall the problem we had with this set up?

While using our previous code our motor only spun when the joystick was moved along the y-axis. Moving to the left or right did not ask the motor to power on, but it would begin to stutter some at the diagonals.&#x20;

This is where adding some math to our code comes into play. Remember on an arcade drive both motors are being controlled by a single joystick. We need our robot to be able to calculate for both motors how much they should power on and in which direction. Thankfully, once we have it all set up our robot will be able to handle the calculations itself as the program runs!

By the end, we should be able to create situations like the following charts where the motors respond to create different forms of motion:

<figure><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUOOiQ4S2QcMWmVoSmeQ8%2Fuploads%2FISMTUORunrcAVdun7vug%2Fimage.png?alt=media&#x26;token=0101eaad-eba3-4ed9-9a23-0fc9f4a52c09" alt=""><figcaption></figcaption></figure>

### Quick Check!

How our robot moves is dependent on how much power each motor is receiving. Before continuing, we can explore with our current program how the robot reacts when changing the values in our ![](https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUOOiQ4S2QcMWmVoSmeQ8%2Fuploads%2FMveYfLz2GCOnNLcObaAH%2Fimage.png?alt=media\&token=0bdb8934-fdf0-4f92-83d8-ce4ce9ac1b6f) block.

* What happens when we set the power of the rightmotor to 0.3 and leftmotor to 1?
* What happens when we set the power of the leftmotor to 0.5 and rightmotor to 1?
* What happens when we set the power of the leftmotor to -0.4 and rightmotor to 0.4?

After testing different combinations, let's look at a quick breakdown of how power between the motors effects movement:

| Power Comparison                   | Robot Movement              |
| ---------------------------------- | --------------------------- |
| rightMotor power = leftMotor power | Straight Forward or Reverse |
| rightMotor power > leftMotor power | Left Turn                   |
| rightMotor power < leftMotor power | Right Turn                  |

### Determining Power with the Joysticks

Rather than setting a static numerical value for our motors, the <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MVIIB5oT9i9P2l29VHj%2F-MVY92VNjdfeFbgTDbty%2FGamepad%20-%20Joytstick%20x%20axis.svg?alt=media&#x26;token=1cc6c4e0-fee2-42a7-b8ba-66aad22b12a3" alt="" data-size="original"> and <img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-MVIIB5oT9i9P2l29VHj%2F-MVY90hzKehu4L9uGscf%2FGamepad%20-%20Joytstick%20y%20axis.svg?alt=media&#x26;token=b47cfd05-1252-45b8-a1f9-03662db45d62" alt="" data-size="original"> blocks will help our robot to translate the motion of the joysticks into a power level. &#x20;

For our arcade drive, the goal is for our joystick inputs to calculate to the following motor outputs:

<table data-header-hidden><thead><tr><th width="223">Joystick Direction</th><th>(  ,  )</th><th width="124">rightmotor</th><th>leftmotor</th><th></th></tr></thead><tbody><tr><td>Joystick Direction</td><td>( <span class="math">x</span> , <span class="math">y</span> )</td><td>rightmotor</td><td>leftmotor</td><td>Movement</td></tr><tr><td><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-Mefge4HnWzFYZVV8De2%2F-Mefhx7EWkkmadU6LW8V%2FGamepad%20-%20forward%20simple.svg?alt=media&#x26;token=ea9e8593-204d-4c38-b370-52f1450bd996" alt="" data-size="original"></td><td>(0,1)</td><td>1</td><td>1</td><td>Forward</td></tr><tr><td><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-Mefge4HnWzFYZVV8De2%2F-MefhzwimOC2m68IoDSE%2FGamepad%20-%20reverse%20simple.svg?alt=media&#x26;token=9ff3f6ce-370a-47b4-9928-b5c475aa0d66" alt="" data-size="original"> </td><td>(0,-1)</td><td>-1</td><td>-1</td><td>Reverse</td></tr><tr><td><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-Mefge4HnWzFYZVV8De2%2F-Mefi1rcj_EIfo6ZRW2u%2FGamepad%20-%20left%20simple.svg?alt=media&#x26;token=79ed0be9-83f2-41b4-988f-4b78b2474a22" alt="" data-size="original"> </td><td>(-1,0)</td><td>1</td><td>-1</td><td>Turn left</td></tr><tr><td><img src="https://1359443677-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4_pJHI8HTuZFQTNfcy%2F-Mefge4HnWzFYZVV8De2%2F-Mefi4IQJxLAupAhBq8Y%2FGamepad%20-%20right%20simple.svg?alt=media&#x26;token=c0141307-dc28-46f2-8097-bd7b719b0968" alt="" data-size="original"> </td><td>(1,0)</td><td>-1</td><td>1</td><td>Turn right</td></tr></tbody></table>

To get the outputs expressed in the table above, the gamepad values must be assigned to each motor in a meaningful way. To do so we are going to set up two equations in our code using the variables we have already established:

$$
rightmotor = y-x \\
leftmotor = y+x
$$
