Below we described steps needed to understand how the solution has been programmed to create a wall-following robot. However, if you just want to get the result of programming, download GreenPAK™ software to view the already completed GreenPAK Design File. Plug the GreenPAK Development Kit to your computer and hit the program to design the solution.
The GreenPAK IC can be used to implement autonomous vehicles. In this project, we will explain how to design an obstacle detection and avoidance system using a GreenPAK along with a few external ultrasonic and infrared (IR) sensors. This design will introduce some topics that are required for autonomous and artificially intelligent robotic systems.
There has recently been renewed interest in artificial intelligence, and much of that interest is directed towards fully autonomous and intelligent machines. Such robots can minimize human liability and extend automation to fields like civil services and defense. AI researchers are attempting to automate services like firefighting, medical care, disaster management, and lifesaving duties through autonomous robotic vehicles. One challenge that these vehicles must overcome is how to successfully detect and avoid obstacles such as rubble, fire, pitfalls, etc.
In this project, we will be using an ultrasonic sensor, a pair of IR obstacle detection sensors, a motor driver circuit (L298N), four DC motors, wheels, a 4-wheel drive car skeleton, and a GreenPAK SLG46620V chip.
A digital output pin of the GreenPAK controller is used to trigger the ultrasonic sensor (aka sonar), and a digital input pin is used to collect the resultant echo from the obstacles ahead for analysis. The output of the IR obstacle detection sensor is also observed. After applying a set of conditions, if an obstacle is too near, the motors (connected to each of the 4 wheels) are adjusted to avoid the collision.
The autonomous obstacle avoidance robot must be capable of both detecting obstacles and avoiding collisions. The design of such a robot requires the integration of different sensors, such as bump sensors, infrared sensors, ultrasonic sensors, etc. By mounting these sensors on the robot, it can get information about the surrounding area. An ultrasonic sensor is suitable for obstacle detection for a slow-moving autonomous robot, as it has a low cost and relatively high range.
An ultrasonic sensor detects objects by emitting a short ultrasonic burst, and then listening for the echo. Under the control of a host microcontroller, the sensor emits a short 40 kHz pulse. This pulse travels through the air until it hits an object and then is reflected back to the sensor. The sensor provides an output signal to the host that terminates when the echo is detected. This way, the width of the returned pulse is used to calculate the distance to the object.
This obstacle avoidance robotic vehicle uses an ultrasonic sensor to detect objects in its path. The motors are connected through a motor driver IC to the GreenPAK. The ultrasonic sensor is attached to the front of the robot, and the two IR obstacle detection sensors are attached on the left and right sides of the robot to detect side obstacles.
As the robot moves on the desired path, the ultrasonic sensor continuously transmits ultrasonic waves. Whenever an obstacle is in front of the robot, the ultrasonic waves are reflected back from the obstacle, and that information is passed to the GreenPAK. Simultaneously, the IR sensors are emitting and receiving IR waves. After interpreting the inputs from the ultrasonic and IR sensors, the GreenPAK controls the motors for each of the four wheels.
At startup, the four motors are turned on simultaneously, causing the robot to move forward. Next, the ultrasonic sensor sends out pulses from the front of the robot at regular intervals. If an obstacle is present, the sound pulses are reflected and are detected by the sensor. The reflection of pulses depends upon the physical state of the obstacle: if it is irregular in shape, then the pulses reflected will be fewer; if it is uniform, then most of the transmitted pulses will be reflected. The reflection also depends upon the direction of the obstacle. If it is slightly tilted, or placed in parallel with the sensor, then most of the sound waves will pass unreflected.
When an obstacle is detected in front of the robot, then the side outputs from the IR sensors are observed. If an obstacle is detected on the right side, the left side tires of the robot are disabled, causing it to turn towards the left, and vice versa. If an obstacle is not detected, then the algorithm is repeated. The flow diagram is shown below.
Ultrasonic Sensor HC-SR04
An ultrasonic sensor is a device that can measure the distance to an object by using sound waves. It measures distance by sending out a sound wave at a specific frequency and listening for that sound wave to bounce back. By recording the elapsed time between the sound wave being generated and the sound wave bouncing back, it is possible to calculate the distance between the sonar sensor and the object. Sound travels through air at about 344 m/s (1129 ft/s), so you can calculate the distance to the object using this formula:
The HC-SR04 ultrasonic sensor consists of four pins: Vdd, GND, Trigger, and Echo. Whenever a pulse from the controller is applied to the Trigger pin, the sensor emits an ultrasound wave from a “speaker.” Reflected waves are detected by the “receiver,” and are transmitted back to the controller via the Echo pin. The longer the distance between the sensor and an obstacle, the longer the pulse at the Echo pin will be. The pulse remains on for the time it takes the sonar pulse to travel from the sensor and return back, divided by two. When the sonar is triggered, an internal timer starts and continues until the reflected wave is detected. This time is then divided by two, because the actual time it took the sound wave to reach the obstacle was half the time that the timer was on.
The operation of the ultrasonic sensor is illustrated below.
In order to generate the ultrasonic pulse, you need to set the Trigger to a HIGH state for 10μs. That will send out an 8-cycle sonic burst, which will reflect off of any obstacle in front of the device and be received by the sensor. The Echo pin will output the time (in microseconds) that the sound wave traveled.
Infrared Obstacle Detection Sensor Module
Like the ultrasound sensor, the basic concept of infrared (IR) obstacle detection is to transmit an IR signal (in the form of radiation) and observe its reflection. The IR sensor module is shown below.
- There is an obstacle indicator light on the circuit board
- Digital output signal
- Detection distance: 2 ~ 30 cm
- Detection Angle: 35°
- Comparator chip: LM393
- Adjustable detection distance range via potentiometer:
- Clockwise: Increase detection distance
- Counterclockwise: Reduce detection distance
- Working voltage: 3 – 5 V DC
- Output type: Digital switching output (0 and 1)
- 3 mm screw holes for easy mounting
- Board size: 3.2 x 1.4 cm
Control Indicator Description
Motor Driver Circuit L298N
The motor driver circuit, or H-Bridge, is used to control the speed and direction of the DC motors. It has two inlets that must be connected to a separate DC power source (motors draw heavy current, and can’t be supplied directly from the controller), two sets of outputs for each motor (positive and negative), two enable pins for each set of outputs, and two sets of pins for the direction control of each motor outlet (two pins for each motor). If the leftmost two pins are given logic levels HIGH for one pin and LOW for the other, the motor connected to the left outlet will rotate in one direction, and if the sequence of logic is reversed (LOW and HIGH), the motors will rotate in the opposite direction. The same applies to the rightmost pins and right outlet motor. If both the pins in the pair are given logic levels HIGH or LOW, the motors will stop.
This dual bi-directional motor driver is based on the very popular L298 Dual H-Bridge Motor Driver IC. This module allows you to easily and independently control two motors in both directions. It uses the standard logic signals for control, and it can drive two-phase stepper motors, four-phase stepper motors, and two-phase DC motors. It has a filter capacitor and a freewheeling diode that protects devices in the circuit from being damaged by the reverse current of an inductive load, enhancing reliability. The L298 has a driver voltage of 5-35 V and a logic level of 5 V.
The function of the motor driver is described in the table below.
The block diagram showing the connections among the ultrasonic sensor, the motor driver, and the GreenPAK chip is shown below:
In Matrix 0, the trigger input for the sensor was generated using CNT0/DLY0, CNT5/DLY5, INV0, and the oscillator. The input from the ultrasonic sensor’s Echo pin is read using Pin3. Three inputs are applied at 3-bit LUT0: one from Echo, another from the Trigger, and a third that’s the Trigger input delayed by 30 us. The output from this look-up table is used in Matrix 1. The output from the IR sensors is also taken in Matrix 0.
In Matrix 1, ports P1 and P6 are OR’d together and connected to Pin17, which is attached to Pin1 of the motor driver. Pin18 is always at a logic LOW and is connected to Pin2 of the motor driver. Likewise, ports P2 and P7 are OR’d together and connected to the GreenPAK’s Pin20, which is attached to P3 of the motor driver circuit. Pin19 is connected to Pin4 of the motor driver and is always at logic LOW.
When the Echo pin is HIGH, it means that an object is in front of the robot. The robot then checks for left and right obstacles from the IR sensors. If an obstacle is also present on right side of the robot, then it turns left, and if an obstacle is present on the left side, then it turns right. In this way, the robot avoids obstacles and moves without collision.
In this project, we created a simple automatic obstacle detection and avoidance vehicle using the GreenPAK SLG46620V as the main controlling element. With some extra circuitry, this design could be enhanced to perform other tasks such as finding a path to a specific point, a maze solving algorithm, a line following algorithm, etc.