Simulating Radars with Ultrasonic Technology

Grant Ou

Grade 7 | Markham, Ontario

INTRODUCTION

Just before the Second World War, the great powers of the world were racing to develop a device that would be far greater than anyone could ever imagine. Some might have said that it was a waste of time, while others said that it was impossible. In 1935, British innovators Watson Watt, Wilkins, and Bowen made the breakthrough in ballistic missile detection, collision avoidance, and obstacle identification (Raney, 2006). The Radar was one of the most revolutionary inventions of the 20th century.

Fast forward 85 years and a curious Middle-School student named Grant Ou has developed the finest solution to the problem of demonstrating how a radar works which, seemingly simple, is quite difficult to tackle. In his inventory is an enormous barrage of Lego Technic Bricks, which are both recreationally satisfying and can be easily constructed and programmed to behave like a device, which was made nearly a century ago. Utilizing the Lego Technic Bricks, Grant has created an Ultrasonic Lego Technic Radar.

The Ultrasonic Radar looks like a radar, moves like a radar, and acts as a radar. Rather than broadcasting radio waves, it uses ultrasonic waves, which is similar in principle. The distance readings from the ultrasonic sensor are then mathematically graphed onto the screen, from which the distance of an object in any given direction can be seen.

Visualizing the ultrasonic sensor readings on the screen consists of graphing a line in the direction at which the radar is currently facing. Then, by reading the distance, it can accordingly graph how far away an obstacle in that direction is.

MATERIALS

The Ultrasonic Lego Radar requires the following materials:

  • EV3 Intelligent Brick

  • Lego Technic Material

    • Ultrasonic Radar

    • 2 Lego Compatible wires

    • Lego Mini Motor

    • Gears, beams, pins, and axles (all technic compatible)

CONSTRUCTING THE RADAR

Designing
The design for the radar consists of a structure that can hold the weight of the ultrasonic radar. For convenience, Lego Technic Bricks were adopted to construct the structure. A single medium motor with a small gear attached to its axle is connected to an orthogonally positioned medium gear on another axle that rotates the ultrasonic sensor while it simultaneously takes distance readings and regulates its speed at a moderate velocity.

Programming and Interpreting
The code is integral to the radar's operation. This radar uses two working threads, i.e. concurrent processes.  The first thread constantly gets the readings from the ultrasonic sensor at a rate of five times per second. The second thread processes the readings from the other thread and graphs them on the screen after converting the Polar coordinates to Cartesian coordinates based on the LCD's native grid system.

The Java code used to leverage the graphing and object detection functionality includes: 

The scan() method, which uses the sensor to scan for objects.

private int scan(final long start, final int scan0) {
        int scans = scan0;
        long prevTime = System.currentTimeMillis();
        while (head.isMoving() && !stop) {
            try {
                final long now = System.currentTimeMillis();
                scans++;
                final int tachoCount = head.getTachoCount();
                final int angle = Math.round(tachoCount * gearRatio);
                final float range = rangeFinder.getRange();
                final RangeMessage msg = new RangeMessage(range, angle);
                messageQueue.add(msg);
                final long beforeEndMs = System.currentTimeMillis();
                final long scanCycleTookMs = beforeEndMs - now;
                final int queueLength1 = this.messageQueue.size();
                if (scanCycleTookMs > this.scanIntervelMs) {
                    final long delayBeforeNextScanMs = this.scanIntervelMs - scanCycleTookMs + 5;
                    Delay.msDelay(delayBeforeNextScanMs);
                }
                int queueLength2 = this.messageQueue.size();
                while (queueLength2 > 1) {
                    Delay.msDelay(waitingQueueDelayMs);
                    queueLength2 = this.messageQueue.size();
                }
                prevTime = now;

            } catch (Throwable t) 
            
        
        return scans;
    }

The run() method, which interprets the scan and graphs it onto the screen

    public void run() {
        int prevX = 0;
        int prevY = 0;
        final List<DetectedObject> previousObjects = new ArrayList<>(500);
        long prevTime = System.currentTimeMillis();
        while (!stop) {
            try {
                final RangeMessage message = messageQueue.poll(500, TimeUnit.MILLISECONDS);
                if (message == null || stop) {
                    continue;
                }
                long now = System.currentTimeMillis();
                prevTime = now;
                graphics.setColor(GraphicsLCD.WHITE);
                final int x0 = width / 2;
                final int y0 = height;
                final int x1 = width / 2 + prevX;
                final int y1 = y0 - prevY;
                graphics.drawLine(x0, y0, x1, y1);
                graphics.drawLine(x0, y0, x1 - 1, y1 - 1);
                DetectedObject previousObject;
                for (final Iterator<DetectedObject> it = previousObjects.iterator(); it.hasNext();) {
                    previousObject = it.next();
                    final int x = previousObject.getX();
                    final int y = previousObject.getY();
                    int age = previousObject.getAge();
                    graphics.setColor(GraphicsLCD.WHITE);
                    final int dx0 = width / 2 + x;
                    final int dy0 = y0 - y;
                    graphics.drawRoundRect(dx0, dy0, 5 - age, 5 - age, 5 - age, 5 - age);
                    previousObject.incrementAge();
                    if (!previousObject.shouldBeDisposed()) {
                        graphics.setColor(GraphicsLCD.BLACK);
                        graphics.drawRoundRect(dx0, dy0, 5 - ++age, 5 - age, 5 - age, 5 - age);
                    } else {
                        it.remove();
                    }
                }
                final float range;
                if (Float.isInfinite(message.getRange()) || (message.getRange() * 100) > radius) {
                    range = radius;
                } else {
                    range = message.getRange() * 100;
                }
                final float pixels = convertToPixels(range);
                final int angle = 90 - message.getAngle();
                final double r = angle * Math.PI / 180.0;
                final int y = (int) Math.floor(pixels * Math.sin(r));
                final int x = (int) Math.floor(pixels * Math.cos(r));
                final int factor = 1;
                graphics.setColor(GraphicsLCD.BLACK);
                final int drx1 = width / 2;
                final int dry1 = height;
                final int drx2 = width / 2 + factor * x;
                final int dry2 = height - y;
                graphics.drawLine(drx1, dry1, drx2, dry2);
                graphics.drawLine(drx1, dry1, drx2 - 1, height - y - 1);
                if (message.getRange() * 100 <= radius) {
                    graphics.drawRoundRect(width / 2 + x, dry2, 5, 5, 5, 5);
                    previousObjects.add(new DetectedObject(x, y, DetectedObject.INITIAL_AGE));
                }
                prevX = x;
                prevY = y;
                graphics.refresh();
            } catch (Throwable t) 
            
        
    }

Testing
Testing the radar to identify and eradicate bugs is a critical step in the experiment to verify that the results are accurate.  The testing process for this experiment involved ensuring that the radar detects obstacles and comparing the distance calculated by the radar to the actual distances in reality.

I tested the radar by placing bottles in front of the radar in specific locations. If the radar detects the bottle, it would be visible on the screen. If the radar fails to detect the bottle, this indicates that there are defects in the code or the radar. This process of testing and correcting is a fundamental step in creating any program.

RESULTS

The radar works by graphing a line, which represents the distance of an obstacle in that particular direction. The graphs provide an accurate representation of how far an obstacle is in a particular direction to which the radar is pointing.  Furthermore, the graph is completely to scale in accordance with the distance and the length of the obstacle.

A visual representation can be found at https://www.youtube.com/watch?v=dtl-g1__DNA.

DISCUSSION

Since ultrasound radars can have the same functionality as a regular radar commonly used today, the question has to be asked - which one is superior? 

The most important difference between the two are the waves that they utilize. Ultrasonic radars use ultrasonic waves (as the name suggests), while regular radars use electromagnetic waves. Both waves travel at a fixed speed (the electromagnetic waves travel faster than ultrasonic waves) and by calculating the time it takes for one wave to be sent out and return, we can easily calculate how far the nearest obstacle is.

Ultrasonic radars are less expensive, so it is much more economical to use an ultrasonic radar, especially if the goal is to calculate the distance between the radar and the obstacle. However, ultrasonic waves can be affected by temperature, pressure, vapours, dust, and tiny obstructions existent in the air. This could cause fluctuations and inaccuracies in the ultrasonic readings.

Electromagnetic waves are relatively unimpacted by changes in temperature, pressure, the introduction of vapours dust, and tiny obstacles in the mediums they travel in. This makes electromagnetic radars more useful in applications where there are constant changes in the environment around them. However, radar waves don't bounce off objects with a low dielectric (the ability to transmit electric force without conducting or insulating) and will generally pass right through them. It should also be noted that radar waves are usually used to detect metallic objects.

Ultrasonic radars are used for applications where the surrounding environment is relatively stable. Electromagnetic radars operate better than Ultrasonic radars in applications, where the surrounding environments are undergoing constant transformation. But both radars have their advantages and disadvantages. Ultrasonic radars are more economical, but their ultrasonic waves are more commonly disrupted. Radars utilizing Electromagnetic waves are less sensitive to changes in their surrounding environment but can be astronomically expensive.  The determinant for deciding which radar is optimal for your application is based on the surrounding environment.

CONCLUSION 

Understanding how a radar works doesn't need to be complicated. A simple example can help an individual grasp the fundamental concepts of a radar's architecture and functionality.

Science plays a critical role in society and provides many answers as to how we can improve our lives. What we call 'modern civilization' is the result of accumulated knowledge applied to practical life.  Science affects the way we survive and live our lives. We use science to develop exponential technologies such as radars and medicines that greatly enhance humanity's future.

This experiment will serve as a good demonstration of how a radar works and inspire people to understand the importance of science. The young generation must appreciate the impact of science and hence allow their imaginations to create innovations that will shape our future for the better.

SOURCES

Bouwmeester, A. (Nov. 15, 2015). Class EV3UltrasonicSensor JavaDocs. Retrieved from: http://www.lejos.org/ev3/docs/lejos/hardware/sensor/EV3UltrasonicSensor.html

Raney, R.K. (February 7, 2006). Radar. Retrieved from: https://www.thecanadianencyclopedia.ca/en/article/radar

Skolnik, M.I. (May 07, 2020). Radar. Retrieved from: https://www.britannica.com/technology/radar

Wilde, E. (May 20, 2020). The difference between ultrasonic and radar level sensors. Retrieved from: https://www.apgsensors.com/about-us/blog/radar-and-ultrasonic-sensors

Tischler, G. (November 4, 2019). 80 GHz radar vs. ultrasonic: Non-contact Level Measurement Technology Com. Retrieved from: https://www.vega.com/en/home_ca/company/blog/2019/80-ghz-radar-vs-ultrasonic

ABOUT THE AUTHOR