resetting the motor position
Forward:
Backward:
Figure 9-2: If you program a Large or Medium Motor to go forward, it turns in the direction of the blue arrow and the Rotation Sensor value becomes positive.
Now suppose you want to repeat the actions in the HandRotate program with a Loop block so that the sound plays again when you rotate the wheel another 180 degrees. The first sound plays when you rotate the motor forward by 180 degrees. But during the second run of the loop, the sound would play immediately because the sensor value is already greater than 180 degrees, which is not what you want. The solution is to reset the Rotation Sensor value to 0 at the beginning of the Loop, using a Motor Rotation block in Reset mode, as shown in Figure 9-4. (You’ll explore the other features of this block and the other Sensor blocks later in Chapter 14.) Run the program and verify that you hear the sound once each time you rotate the wheel 180 degrees forward.
rotational speed Output port
Motor Rotation – Compare – Degrees
Figure 9-3: The HandRotate program makes the robot say “Okay” once you
The Rotation Sensor calculates how fast a motor turns as a value between −100% and 100% based on the rate at which the motor position changes. The value is positive when the motor turns forward (blue arrow in Figure 9-2), negative when the motor turns backward (green arrow), and 0 when the motor is not turning. For the Large Motor, a Current Power sensor value of 50% corresponds to a rotational speed of 85 rotations per minute (rpm). You can reach this speed by rotating a motor with your hands or by using any of the Move blocks with its Power setting at 50%.
rotate motor B forward by 180 degrees. Note that the Wait block would do the same thing if you used Motor Rotation – Compare – Rotations mode with a threshold value of 0.5.
N o t e Current Power mode measures rotational speed; it does not measure current or power consumption!
Reset
Figure 9-4: The HandRotateReset program sets the sensor value to 0 at the beginning of each loop with the Rotation Sensor block in Reset mode. Note that the Play Type setting in the Sound block is Play Once (1) so that the program doesn’t wait for the sound to finish.
using the brick buttons and rotation sensors 99