Logo

Westside Robotics FTC Java Programming Guide

Use Proportional Control to Turn Accurately

Until now we have been assuming that our robot responds more like a video game than an actual physical robot. We assume the robot does what we want it to immediately and exactly. What our actual robot does is a little different. The actual robot will spin its wheels when the motors go from 0 to 100%, and when we turn the motors off the robot continues to move while it is slowing down to stop.

To better understand what we want our robot to do, imagine how a person would do the same task. If you asked a person to run as quickly as they could to a wall and stop 100mm away from the wall without touching the wall. Would they run as fast as they could (100% speed) until they were 100mm from the wall and then stop (0% speed)? Would they run at 100% speed until they were say 500mm away from the wall and then stop, hoping they end up at 100mm from the wall?

If you said that a person slows down as they get closer to the wall, that is exactly what we want our robot to do. When we use RUN_TO_POSITION the internal controls do that for us. While RUN_TO_POSITION may work well for driving forward or to the side, it is an inaccurate way to rotate precisely. To rotate precisely we will want to use the gyroscope to control how far we rotate.

When we talk about controls, it is better to think in terms of target value, actual value and error from target value. Target value is where we want the robot to be, actual value is where the robot is currently, and error is the difference between the two values. (This is why when we use RUN_TO_POSITION we set a target value.) For example: If we are starting from 0 and we want to be at 100, our target value is 100, our current value is 0 and our error is 100. As the current value gets closer to the target value, the error decreases.

Using error to control our power gives us the right behavior, but it doesn’t necessarily give us the right value. For example, if the units of error are in mm, you would need to be less than 1mm away from your target before you begin decreasing power. To resolve this, we may need to multiply the error by an additional value Kp.

P = Kp * error

Using proportional control, create a method to turn 90 degrees using the gyroscope.