Steering left

The next MyBlock is fairly straightforward. It rotates the front wheels into the left position so that the Falcon will make a left turn.

Before the robot does anything, it needs to check the current position of the front wheels. Since cases in the full program can execute continuously for periods of time (for example, holding down the steering button on the remote to make a turn), the program needs to verify that the front wheels are not already in the left position. This makes sure that, after the wheels move into the left position, they stop and stay there. Otherwise, the steering will continue to turn left until it runs into a mechanical limit and locks up.

First, add a motor rotation block (Measure | Degrees, port A) and plug its output into the first input of a compare block. Set the compare state to less than (<) and change the comparison value (second input) to 45. Take the result from the compare block and plug it into the input of a switch set to logic. The switch is set to tabbed view to save space:

The true case of the switch executes if the degree value on the steering motor is less than 45, meaning the steering is not yet in the left position. Within the true case of the switch, we will add some code to move the wheels into the left position. Add a loop and set its exit case to Motor Rotation | Compare | Degrees. Set the threshold value to greater than or equal to (>=45 degrees and ensure that port A is selected. Within the loop, simply place a medium motor block (On, 100 percent power, port A):

The number  45 means that the steering motor turns  45 degrees from center to make the Falcon's front wheels rotate. This value is adjustable. Increasing this value would cause the Falcon to make sharper turns, while decreasing it would cause it to make smoother turns. Experiment with different values to see what you like best. When you change the values, make sure that you change it in both of the places that it appears in the MyBlock, as well as both the left and right MyBlocks.

The false case of the switch executes when the degree value of motor  A is equal to 45 degrees, which would indicate that the wheels are already in the left position, so no further action is required. Simply place a medium motor block that turns motor  A Off:

This is the completed code for the steerleft MyBlock. Save it using the MyBlock wizard following the steps outlined before, and name it steerLeft:

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

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