Math Block and Random Number Block
|
Example 1: Math Block |
Example 2: Random Number Block |
Example 1 - Possibly used to detect a spinning or stuck wheel
This code runs motors B and C until they stall.
The code takes two rotation sensor readings,
with a very short delay in between them.
The loop exits when the difference between the
two readings becomes less than a certain threshold.
So if a motor slows down because it encounters
an obstacle, the code will stop running the motors.
A short delay in the beginning is necessary so
that the motor can start moving before the rotation sensors start taking
readings.
Note that if the speed of the motor is
decreased, the threshold for the difference needs to be lowered as well.

Example 2: Possibly used to simulate random movements or other actions in an area...avoiding another robot's gripper..."rope a dope"
This code creates a wait for loop that will wait for a random
amount of time.
The code uses the random number generator and a loop that
waits for the timer to equal the generated value.
The random number is set between 500 and 5000, which causes
the loop to wait for 500 and 5000 milliseconds.
