What the “Wait For Ultrasonic And Touch Sensor” brick does
![]() | The sensor will wait until either the Ultrasonic sensor has detected the selected range, or until the touch sensor is pushed. It will return the value 1 if the Ultrasonic sensor has detected the selected range, it will return the value 2 if the touch sensor was pushed, and it will return 3 if both events happened together. |
Configuring the brick
- You need to provide the ports to which the touch sensor and the ultrasonic sensor are connected.
- For the ultrasonic connector, you must also specify the trigger point. This is the distance that the ultrasonic sensor is responding to.
- If you want the ultrasonic to trigger when it comes too close to an obstacle, check the "Trigger If Closer Than Trigger Point" box. When this box is unchecked, the ultrasonic sensor will fire when there is no obstacle between the robot and the trigger point distance.
Sample Application
In this sample application, the robot has an ultrasonic sensor at the front, and a bumper at the back.
This application will drive forward until the ultrasonic sensor detects an obstacle closer than 30 cm. When that happens, it will drive backward and turn until the obstacle is further than 50 cm, or until it bumps into something with the rear bumper. Then it will start to drive forward again.
With this simple program, the robot can navigate the room and avoid obstacles and walls.
Sample Application 2
In this second sample application, we'll make things a little bit more complicated. This time, the bumper and the ultrasonic sensor are both at the front of the robot. When the bumper is pushed, then some obstacle did not get properly detected by the ultrasonic sensor.We want the robot to drive forward. When the ultrasonic sensor sees an object, then it should simply turn a number of degrees to avoid the obstacle. But if something hits the bumper, it may be blocking the robot. The robot may not be able to turn. Therefore, the robot should first drive backward, and then turn. Here's the program that does this:

Here's the setting of the switch (if-then) statement:

Notice that I have set the second option as the default option. That means that if both the ultrasonic and touch sensor fire at the same time, then we will respond to the bumper and ignore the ultrasonic sensor.

0 comments:
Post a Comment