Gyro Sensor

In Chapter 4, Sensors and Control, when we introduced the Gyro Sensor, we wrote a program that stopped the rotation of the robot when the Gyro Sensor reached a certain value. As we noticed, the robot always overshot this value. In Chapter 7, Advanced Programming, we tried to compensate for the overshooting with a two-level controller. Here we show a program where the measurement from the Gyro Sensor goes into a proportional controller.

You will find that this method is significantly more precise and useful in making exact turns.

Gyro Sensor

The preceding program asks the robot to rotate through a given angle and slow to a stop. If we used a smaller gain constant, we could avoid using a loop. However, this can take more time and runs the risk of never reaching your setpoint. This is similar to approaching a set distance from a wall using the motion or proximity sensors. Again, we start out by resetting the Gyro.

A more interesting use of the Gyro Sensor will be to drive in a straight line under constantly changing conditions. This algorithm is akin to line tracking along a curving line. Suppose you are attempting to drive straight while pushing an object (such as a LEGO car or truck with wheels). There will be a lot of friction, which will easily push your robot off course. The following program will allow the robot to constantly correct itself, so it maintains a course direction given by the Gyro.

We begin the program by defining values for our speed, gain, and set point variable blocks. Inside of the loop, the second line of our program calculates a proportional correction to how far off the robot is from the setpoint angle. We then add this correction to one wheel and subtract from the other wheel. Notice that to reduce the number of blocks in this case, I used a Move Tank block with each correction connected to a different wheel. In a Move Tank block, the power level for each wheel has its own input plug.

In a Move Steering block, there is one input plug for power and one input plug for direction.

Gyro Sensor

If the robot is not pushing a load, you will find it drives straight easily. As it drives, give it a push and you will find it will correct its course.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.214.215