Centering the steering

The first MyBlock we will make runs once at the very beginning of the program. It centers the Falcon's steering mechanism so that driving is easier for the user. It also resets the rotation sensor after it centers the wheels, which is important because it defines the center as the zero position, from which all of the later steering commands will be based.

Start programming just as you normally would; we do not have to worry about making the MyBlock until we are finished with the chunk of code that we want to save.

To start programming the steering centering MyBlock, drag out a loop block and set its exit case to Motor RotationCompareCurrent Power. Set the threshold to < | 20 and make sure port A is selected. Within the loop, place a medium motor block (On, 25 percent power) and a wait block set to wait for  0.2 seconds.

This section of code turns the steering motor slowly in the positive direction. The loop block uses the built-in rotation sensor to check for a motor stall. The motor starts out at 25% power and, if the power drops below 20%, the program knows that the motor has stalled. The short wait block ensures that the motor has a chance to start moving and reach the target speed before the program starts looking for a motor stall:

After that, place a medium motor block (On for Degrees, -75 percent power, 105 degrees, port A) followed by a motor rotation block (Reset, port A). The completed centering code looks like this:

What is going on here? This code works by turning the steering mechanism in one direction until it cannot turn any more. At this point, the stall is detected, and the program rotates the motor back in the opposite direction for  105 degrees—the amount of rotation necessary to bring the steering back to the center position. Finally, it resets the rotation sensor on motor  A, making the center position the new zero position. This is a convenient method because the program will automatically bring the wheels into the center position no matter what position they started in. This block makes the program more precise and user-friendly.

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

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