MATLAB/LEGO MINDSTORMS Exercise #5 Object Scanning With the LEGO Ultrasonic Sensor

This exercise is intended to help students to understand how to scan the absolute distance of a 3D object from a ultrasonic sensor.

  1. Build a four-wheeled vehicle on rails with a sensor facing to the side moving up and down.
  2. Scan the absolute distance of a 3D object in front of the moving ultrasonic sensor. For this purpose, the vehicle drives along a vertical wall in front of which a 3D object is standing halfway away from the vehicle.
  3. Display the absolute distance measures graphically and discuss the result with respect to the spatial resolution of the sensor.

Solution

  1. First you have to build the vehicle according to the LEGO building instructions. The building instructions are in a LXF file which can be opened with the free LEGO Digital Designer software, which is available for computers running macOS or Windows. After launching the software you can use the view menu to switch from the construction mode to the building instructions mode.
  2. Your MATLAB script creates connections to the motor and the sonic sensor, moves the vehicle and the sensor in small steps and measures the absolute distance (in meters). It then displays the distance in a 2D graphics using a coordinate grid that you need to define. As you can see the sensor integrates over a relatively large area and therefore smooths the result. See the LEGO Developer Kit for the specs of the sensor.

LEGO building instructions and MATLAB script to run the experiment

Download the building instructions and MATLAB script. The LXF file contains the building instructions to be used with the free LEGO Digital Designer software available for macOS and Windows.