You can use the information that the rotation sensor gathers about the car’s position
to control the car’s speed and direction. Let’s label the current position of the car c.
Then, at any point, the car’s distance from its desired stopping point is (360 – c),
since one complete rotation equals 360 degrees on the rotation sensor. We can
multiply this quantity by a feedback gain, k, and use k(360 – c) as the input for our
motor power. That way, the closer the car is to the desired stopping point, the smaller
k(360 – c) will be and the more slowly the motor will run. If the car overshoots, then
k(360 – c) becomes negative and the motor reverses.
To vary a motor’s speed and direction in your program, use Motor On. The Motor On
icon will run the motor at a speed between 1 and 100, either forward (positive
numbers) or backward (negative numbers). For example, if you wired in a power
input of -100, the motor would run backwards at full power.
Use the information above to write a program. Your program will take input from the
rotation sensor, use it to adjust the motor speed, and then jump back to take new
input from the rotation sensor. Set the gain, k, equal to one. (You will experiment with
other values of k later.)