Users Manual

CLASS 4
124
Now let’s create a script called ‘check_Ultrasonic’ that we broadcasted earlier. Compare it to the script you’ve
created and see what’s different! The scripts needed for sampling the ultrasonic sensors are shown below. Go
ahead and make it!
When it gets 'check_Ultrasonic', it runs backwards for half a second, and broadcast 'move_stop' and wait. After
that, it starts the sampling with the servo motor angle right. The ultrasonic sensor value at this time is accumulated
three times in the 'Ultrasonic_R_value' variable. Then divide the accumulated value in this variable by 3, average it
down, and save it back in the 'Ultrasonic_R_value' variable.
So, this variable stores the value that the ultrasonic sensor samples the rightward direction three times and the
average is reduced. The 'Ultrasnoic_R_value' value at this time will be the filter value in the right direction. Now,
with the servo motor angle left to the same exactitude, broadcast the "Detect_Ultrasonic" script to determine how
the action should be done.
Sampling with an ultrasonic sensor
Commentary