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:

Let's take this information and think back to when we first programmed a motor 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.

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:

Quick Check!

  • 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:

Determining Power with the Joysticks

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

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=yxleftmotor=y+xrightmotor = y-x \\ leftmotor = y+x

Last updated