Robot Competition

The competition  was the final assessment of the course I took at the university on Robotics and automation. There were several tasks to be completed in the competition with three rounds.

The task


The track

The robot had to follow the track with which was designed with a black line. The track had a section with arrows pointing the directions. So robot should be able to identify the direction pointed out by the arrows. The track has red and green colored crossed lines. The robot should be able to identify these colored signals. There was a broken fence beside the track and the robot had to map the fence. And the robot should produce a graph which contains the accuracy of the line following. 


The robot

The participants had to make a robot car using two driving wheels using arduino nano. And the coding had to be done using the C language instead of using he arduino IDE. And any method could be used in the communication with the robot.

Driving the robot

L298N


The robot was driven using a an H bridge and PWM (Pulse width modulation). To control the rotating direction of a DC motor we should be able to control the direction of the current flow. The H bridge is a circuit which controls the direction of the current flow using 4 switching elements. L298N is a dual H bridge motor driver module. It has four ports to take inputs which corresponds to the two directional movements of the two motors. However there are only two PWM pins in arduino nano. Therefore the method used was to for each motor a PWM pin and a normal GPIO pin was connected. To move the motor forward the normal GPIO pin was set to logic one. So this gives the motor 100% power. To move it backward the first pin was set to logic 1 and the PWM pin was also set to logic one. Now according to the H bridge setting, the motor gets 100% power to go backward and 50% power to go forward(say the PWM is set to be 50%). Then the motor actually moves backward with 50% power. 

In the code separate functions were written to move forward, backward, turn left, turn right and get a 90 degree turn and was tested for each function.

Line following 


The IR sensor array

To do the line following an IR array sensor was created. The circuit was designed with 8 IR couples for a better line following. A circuit was designed, a pcb was printed and the circuit was soldered. IR couples work by emitting an IR ray and capturing its reflection. There only a white surface will reflect the array while a black surface will absorb the ray. So these outputs are amplified through an op amp (LM324n was used) and then fed to the arduino nano. The movement of the robot was altered based on this input.

In code implementation an algorithm written in a way that all the eight logic inputs were assigned a digit ranging from +4 to -4. And the algorithm always tries to make the sum of the inputs to 0. For example if the 2nd and 3rd pins are set to be logic one, then the sum becomes +5(sum of +3 and +2). Then the robot turns to the right side and makes the sum 0. (sum of +1 and -1 is zero). In this way it will be assured that the robot will always try to keep the black line in the middle of the IR sensor.

The color sensor


                   The color sensor


The color sensor was created on a basic theory in optics. How we see certain colors is determined by the wavelength of the light that particular color reflects. For example if we consider a red apple, it reflects the light with the corresponding wavelength of the red color. So in this sensor an RGB LED (an LED which can be lit in red, green and blue) is blinked respectively with the three colors. Based on the amount of the light reflected by each color is taken and compared. This was done by getting the voltage across an LDR. Based on these voltages the color of the target object is identified. The circuit was made on a PCB.

Ultrasonic sensor


Ultrasonic sensor

To map the broken fence beside the track an ultrasonic sensor was used. In the first stage the ultrasonic sensor was interfaced to measure the actual distance. The code was written in a way that at the moment when the sensor is triggered, a timer counter was started and it keeps checking the the signal has been reflected. At the moment the capture becomes positive the time is stopped and based on the time, the distance is calculated. Since the required information was binary, i.e. whether there is a fence or not, a threshold was given to the distance measurement. 

Utilization of timers

Though each of the sensors and functionalities of the robot were developed and tested separately at the end of the project the whole thing had to be run as a whole system. At the first phase most of the coding was done using the timer1 in Atmega328p. In Atmega328p microcontroller which is inside the arduino nano, there are three timers namely timer0, timer1 and timer2. Timer1 is a 16 bit timer and the other two are 8 bit timers. Therefore timer1 was used in PWM in driving the motors. Timer0 was used with the ultrasonic sensor. 

There was a requirement to sound a buzzer whenever the robot detects a red color signal. At first the buzzer was sounded using a basic delay statement. However when this was implemented in the driving robot, it was observed that because of this delay the accuracy of the line following is highly affected. Basically the robot was shaking then and there instead of a smooth driving. Therefore the delay statement was replaced by a toggle statement based on timer2.

Serial communication

At the competition it was expected to produce three graphs.

  • The accuracy of line following
  • Map of the fence
  • The positions of the green colored cross signals on the track.
Therefore these information was sent from the robot using serial communication. The robot was connected to a computer with the use of a Bluetooth module which was interfaced to the robot.

The corresponding information was transmitted in the code of the robot and was received from the other end using a python program. By using python packages such as numpy, matplotlib the data was visualized. 

For an efficient serial communication data was sent using an encoding method. A serial data byte packet contains 8 bits. However there were 8 IR inputs, three color sensor inputs and the ultrasonic sensor input to be transmitted. So an algorithm was written in a way that the first two bits of the packet has an identification code and the rest contains information. 

00xxxxxx - 6 IR sensor inputs
01xxxxxx - 2 IR sensor inputs and ultrasonic sensor input
10xxxxxx - Color sensor information
11xxxxxx - Check whether all 4 packets are received

In the python program this was decoded to get the necessary information.

Plotting all three at the same time was a challenge. This task was achieved by writing the incoming data into a text file and plotting. However it is not considered a good practice to read ad write data at the same time rather than storing data in the memory and performing tasks. 














Share:

No comments:

Post a Comment