Distance measurement, the ultrasonic sensor
Distance measurement is very important in robotics. Distance is most often measured using laser beams or ultrasonic sound waves. This lecture explains the most important terms in distance measurement, and shows you how to use the ultrasonic sensor on your Lego robot.
The simplest way to connect the sensor
Lego Mindstorms Ultrasonic Sensor can be easily connected to the 1, 2, 3 or 4 ports of the Brick. You can find these ports on the bottom of the Brick. Users can luckily detect all input or output devices with the Brick's microcontroller and let Ozeki 10 simply reach those devices via Bluetooth. All ports can easily accept the EV3 Ultrasonic sensor. You can see an example of connection below.
Figure 1 - Plugging the ultrasonic sensor to the Brick with an EV3 cable
- Lego Mindstorms EV3 Brick
- EV3 Ultrasonic sensor
- EV3 cable
- Ozeki 10 installed: http://www.ozeki.hu/index.php?owpn=6066
- Connect Brick via Bluetooth: http://www.ozeki.hu/index.php?owpn=6065
- Lego connection installed: http://www.ozeki.hu/index.php?owpn=6067
Video tutorial: 'How to use the Lego Ultrasonic sensor in Ozeki 10'
Start the Control Panel application!
Open Ozeki 10 in your browser client running on the same machine you have previously paired the Brick if you have followed the guide at http://www.ozeki.hu/index.php?owpn=6065. Log in with the user credentials provided during the installation and start the 'Control Panel' from the GUI (Figure 2), which will let you control every Lego connection through a chat panel. In this guide it will get distance from any object in centimeters or inches using the ultrasonic sensor.
Figure 2 - Opening the Control Panel through the GUI
Select the ultrasonic sensor from the connection list!
The first table you can see on the Control Panel is the connection list, so you can watch all available or offline Ozeki 10 connections. The integrated connections on the Lego Brick should be available if you have followed the guide on http://www.ozeki.hu/index.php?owpn=6067. This is a simple guide that explains how to connect your Lego Mindstorms Lego Brick to Ozeki 10. But now you can see an example screenshot on Figure 3 to see how does the 'Ultrasonic_Sensor_1' appear in the list. Click on it, so you can read measurements, configure it or check the device event history.
Figure 3 - This is how you can detect all Lego Mindstorms EV3 devices wired to your Brick
Chat with the sensor to measure distance!
Ozeki 10's device chat is the best solution to test all commands available for each device. You can easily ask the list of available commands by typing 'help' and hitting enter. Type 'subscribe' to get all incoming messages that are sent as events from the device. The sensor is most effective if the object position is in a square angle to the ultrasonic waves. Figure 4 shows how to subscribe and read distance from any sensor head. 'read' returns the range between the head and the object.
Figure 4 - Measure distance with your ultrasonic sensor through Ozeki 10's chat interface
Change the sensor mode to measure distance in inches!
Under the 'Configure' tabpage you can select whether you wish to see the distance from object in centimeters or inches. The default unit is in centimeters. For the result of the 'read' command, the distance will appear in the selected unit. Figure 5 shows how to change sensor mode from centimeters to inches. This setting applies to all measurement data arriving from the sensor.
Figure 5 - Selecting sensor mode of the Ultrasonic
You can see how to read sensor data in inches. It works exactly the same way as you have done it before with centimeters. After you have configured the measuring mode to 'Inches', all messages routed or used in program codes will be received in inches like Figure 6 demonstrates.
Figure 6 - Measuring in inches
Check Ultrasonic Sensor events!
Besides chat and configuration, the GUI contains an 'Events' tabpage that stores measurement data in rows. In Figure 7 the fourth and fifth rows show that the admin has 'successfully subscribed for events'. You can read both centimeter or inch events depending on your configuration. You can also see that the last two rows show that the 'read' command was sent from your Ozeki 10, and the answer for it was a 3 cm distance range measured. These commands can be easily understood and will be described on the table just below the screenshot. If you do not remember what your device previously did, you can re-check the 'Events' tabpage anytime. In Ozeki 10 all devices have an events tabpage and additionally a toolbar page in the Control Panel for all device events.
Figure 7 - Look at all sensor events you have previously used
The EV3 Ultrasonic sensor controller command set in Ozeki 10
The Ultrasonic sensor's command set is one of the easiest to understand. They contain both sensor specific and basic commands, that are generally used. All texts in these tables can be sent towards the EV3 Ultrasonic Sensor connection. The most common message used on all sensors is the 'read' command, which receives the actual sensor measurement as a response in cm or inch.
|read||get the measured distance value|
Commands Table - Read data from your Lego Ultrasonic Sensor
|help||request the command set|
|subscribe||subscribe to device messages|
|unsubscribe||unsubscribe from device messages|
|subscribers||shows the list of subscribers|
Basic commands Table - General commands for all devices
- The touch sensor and sensor messaging
- Capturing infrared signals using the IR sensor
- How to measure light intensity and how to capture color information
- Using motors and rotary encoders
- Orientation in space, the gyroscope sensor
- Using the LCD display
- Using indicator leds on the Lego Brick
- Power management and working with the brick battery
- Playing sounds on the Lego speaker