1 ,
Aritificial Intelligent Robot (AIBOT)
Project Report
www.aibot.co.in
Arunkumar R Bibin A Chundatt Jinu Jayachandran Vishnu Jayapal
Department of Electronics and Communication Engineering Amrita School of Engineering
Amrita Vishwa Vidyapeetham Amritapuri campus
1 ACKNOWLEDGEMENT
We offer our humble pranams at the lotus feet of our beloved Amma Satguru Sri Mata Amritandamayi Devi who is the guiding force and inspiration for us.
Artificial Intelligent Robot has been carried out as a part of the Bachelor of Tech-nology curriculum and is submitted with extreme pleasure and gratitude.
We make use of this opportunity to express our sincere gratitude to all those who have helped us to complete this project successfully. We would like to convey our sincere grat-itude to Dr. K Sankaran, Principal, Amrita School of Engineering and Mr. Suresh Kumar R, Chairman, Department of Electronics and Communication Engineering for pro-viding the necessary facilities towards the completion of the project.
We wish to express our gratitude to our Project Guides Br. Karthi Balasubrama-nian and Mr. Joshua David Freeman, Assistant Professor, Department of Electrical and Electronics Engineering for their valuable guidance and support. We are deeply in-debted for the valuable discussions we had at each phase of the project. We also express our gratefulness to all staff of the Department of Electronics and Communication.
Our sincere thanks to Br. Jayaraj, Br. Sriram and Br. Ranjith of Amrita Re-search Lab for helping us in completing the project successfully. We would also like to thank Dr. Ganesh Uduppa, Chairman, Department of Mechanical Engineering and Mr. Kanakaraj, Manufacturing lab, Department of Mechanical Engineering for the valuable support and help in building the mechanical parts of our project. We would also like to give a special thanks to Mr. Anish Mohan, Research Assistant, Robotics Lab for the motivation and help he provided at critical situations.
We also convey our deepest gratitude to our parents for their whole hearted cooperation. We also extend our sincere gratitude to all persons who were in one way or other involved directly or indirectly with our project. Last but not the least we would like to express our sincere thanks to all friends and class mates for their encouragement particularly Jeeth, Vipin Raj, Shyam, Rahul, Aneez and Prasanth who helped us in need.
Above all we are always thankful to God almighty for giving us good health and mental attitude for completing the project.
Contents
Abstract 7 1 Introduction 8 1.1 Overview . . . 8 2 Robot Architecture 9 2.1 Master PIC . . . 10 3 VIA CN700 Chipset 11 3.1 Key features . . . 114 Robotic Platform and Robotic Arm 14 4.1 Robotic Platform . . . 14 4.2 Wheel configurations . . . 14 Wheels . . . 14 Wheel geometry . . . 15 4.3 Selection of Motors . . . 15 Stepper Motors . . . 16 DC Motors . . . 16 DC Motor control . . . 16 4.4 Robotic Arm . . . 18 Servo Motors . . . 19
PWM generation for servo motor control . . . 20
5 Obstacle Avoidance 22 5.1 Sonar . . . 22
The working of SONAR . . . 22
Sonar Transmitter . . . 22
Sonar Receiver . . . 23
Distance Calculation Using PIC . . . 23
Receiver Circuit . . . 24
CONTENTS 3
6 System Communication 27
6.1 Serial Communication of the PIC with the PC . . . 27
PIC16F877A Microcontroller . . . 27
Serial port . . . 27
GUI using Visual Basic . . . 27
6.2 I2C Communication . . . 30
Transferring Data . . . 30
7 Machine Vision 36 7.1 Computer Vision . . . 36
7.2 Hough Transform . . . 36
Hough Linear Transform . . . 36
Hough transform for detecting circles . . . 37
Algorithm with matlab results . . . 38
7.3 Implementation in Java . . . 39
7.4 Technologies Used for Java Design . . . 39
7.5 Features of Java . . . 39
Java Virtual Machine(JVM) . . . 39
Java Packages . . . 39
7.6 Process Flow . . . 41
The Addressing Scheme . . . 42
8 Summary and Conclusion 49 8.1 Summary . . . 49
Robot platform . . . 49
Robotic arm . . . 49
Ultrasonic Sensing modules . . . 49
Computer Vision . . . 49
8.2 Conclusion . . . 50
9 Problems Faced 51
List of Figures
2.1 Project Block Diagram . . . 9
3.1 Mini ITX Motherboard mounted in the robot . . . 11
3.2 Power consumption report of Mini-ITX motherboard . . . 13
4.1 Four basic wheel types, a) Standard wheel: two degrees of freedom b)Caster wheel: two degrees of freedom c)Swedish wheel: three degrees of freedom d) Ball or Spherical wheel: realization technically difficult . . . 15
4.2 Three wheel configuration . . . 15
4.3 Zero radius turning . . . 16
4.4 Comparison of servo with stepper having same torque . . . 17
4.5 AIBOT platform . . . 17
4.6 H Bridge using switches . . . 18
4.7 H-Bridge circuit using Nmos . . . 18
4.8 H-Bridge with speed control ( IC specified) . . . 19
4.9 Servo control signal . . . 20
4.10 Servo motors connected to the PC . . . 21
4.11 A prototype of Robotic Arm . . . 21
5.1 Sonar Transmitter . . . 23
5.2 Sonar Receiver . . . 23
5.3 Sonar Amplification Circuit . . . 24
5.4 Sonar Detection Circuit . . . 25
5.5 Sonar Comparator Circuit . . . 26
6.1 Serial communication block diagram . . . 28
6.2 Graphical User Interface for servo control . . . 29
6.3 A typical example of I2C . . . 31
6.4 I2C Connection diagram . . . 32
6.5 A Complete Transfer . . . 33
6.6 Slave sending data 0x44 to slave address 0x02 . . . 33
LIST OF FIGURES 5
6.7 Screenshot of I2C simulation . . . 34
6.8 I2C Bus Analyser . . . 35
7.1 Two point in x-y plane . . . 37
7.2 Possible lines . . . 37
7.3 Mapping . . . 38
7.4 Matlab’s intermediate results . . . 44
7.5 Matlab output No.1 . . . 45
7.6 Matlab output No.2 . . . 46
7.7 Java program screen shot . . . 47
List of Tables
4.1 Motor control bits . . . 19
Abstract
Robotics is one of the fastest growing area in modern technology. The multi disciplinary view of robots make it more complicated and challenging field in engineering. Artificial Intelligent Robot (AIBOT) is one among them. AIBOT is a three wheeled autonomous navigational robot with image processing capabilities. It uses a Single Board Computer (SBC) mounted onto the robot for all image processing tasks. AIBOT uses a modular architecture which increases the flexibility and adaptability of the robot. Each module uses a seperate microcontroller which is connected using I2C protocol to the Master microcontroller which is connected to the SBC through the RS232 port. The robot platform has a robotic arm with five Degrees Of Freedom (DOF). The sensors for Obstacle Avoidance include three Ultrasonic sensors in the front. The Robot has two mode of operation - Manual mode and Autonomous mode. Manual mode uses a GUI developed using Visual Basic to control the robot. In autonomous mode a Java program will be running in the onboard computer. When the JAVA program starts running, AIBOT starts from the home position and if an obstacle is detected by the sensors within a specified distance, it stops. The web cam captures the image of the obstacle and process it to see if it is a specified coloured ball. If it is the specified ball the arm grabs the ball and bring back to home position, else move away from the obstacle and continue moving forward till another obstacle is detected.
Chapter
1
Introduction
Today, in almost all modern industries robots are used to overcome human limitations. Robots can work in hazardous environment like monitoring a nuclear power plant or explor-ing a volcano. Robots perform tasks more precisely than humans which make it ideal for medical applications. There are three basic laws of Robotics created by Isaac Asimov.
1. A robot must not injure a human being or through inaction, allow a human being to come to harm.
2. A robot must always obey orders given to it by a human being, except where it would conflict with the first law.
3. A robot must protect it’s own existence, except where it would conflict with the first or second law.
Autonomous robots have a more complex design than those controlled manually. An au-tonomous robot is said to have ’Artificial Intelligence’.
The aim of the project is to make an autonomous mobile robot that navigates on its own, avoiding obstacles and will locate, detect and pick up an object of our interest. If needed, the robot can also be operated manually. To connect the robot to the remote computer through a wi-fi connection, a Single board computer (SBC) having a ’VIA’ micro processor is mounted in the robot. This also helps in onboard image processing operations, without using a remote computer, thus reducing processing time delay.
1.1
Overview
The project can be broadly divided into three sections - Mobility, Obstacle Avoidance and Computer Vision. Mobility,which deals with AIBOT platform and a robotic arm, is discussed in section 4 and 4.4 respectively. Section 5.1 deals with obstacle avoidance systems using ultrasonic range finders. The computer vision mainly deals with the object identification techniques and is described in section 7.1. The overall block diagram of the project is shown in 2.1.
Chapter
2
Robot Architecture
Figure 2.1: Project Block Diagram
As shown by the block diagram in figure 2.1 the AIBOT consists of a VIA Motherboard with a wireless adapter, Web cam, a Master PIC, Slave PICs for individual modules, motors and sensors. There is also a remote machine that is primarily used for manual control, if needed and monitors the actions of the AIBOT through the remote desktop connection.
CHAPTER 2. ROBOT ARCHITECTURE 10
2.1
Master PIC
AIBOT uses a modular approach in its overall architecture. Each module of the robot ie. arm, base, ultrasonic sensors uses separate microcontrollers. These slave modules are connected to a master PIC through I2C protocol. The master microcontroller is connected to the onboard computer through the RS232 port.The master PIC thus acts as a router between the serial port of the Mini-ITX VIA Motherboard and the different modules. Whenever the onboard computer want to communicate with the master PIC it sends a 7 byte frame to it. The first byte denotes the slave address and the interpretation of rest of six bytes depends on the the module to which it communicates. As shown by the block diagram in figure 2.1, the Java program running in the motherboard will be continuously communicating with the master PIC through the serial port to control the individual mod-ules. The Java program sends the address and the data for the PICs it wants to control, to the Master PIC. The Master PIC route this data to the individual PIC based on this address through I2C communication channels. The Master PIC also gets the distance of the obstacle from the Sonar PICs and it will be sent to the Java program. The Java program uses this data to decide whether to stop and run image processing code or to move forward.
Chapter
3
VIA CN700 Chipset
The Single Board Computer[7] is used for image processing, controlling the AIBOT and for wireless transmission to the remote computer. The motherboard is shown in figure 3.1
Figure 3.1: Mini ITX Motherboard mounted in the robot
3.1
Key features
1. Mini ITX form factor 6 layers PCB size: 17.0 × 17.0cm 2. Embedded VIA CN700 NANO BGA processor
3. Memory Socket expandable to 1GB 11
CHAPTER 3. VIA CN700 CHIPSET 12 4. Expansion slot - 32 bit PCI
5. PS/2 keyboard and PS/2 mouse connectors 6. Hard disk connectors ×1
7. VGA ×1,serial port ×1 8. USB 2.0 connector ×2
9. Serial COM Port COM2 Pin-header ×1 10. Audio Connector
The processor runs Windows OS platform which is used mainly to run the java program and remotely monitor the system functions through Remote Desktop Connection. The PCI slot of the motherboard has NETGEAR wireless card with a transmission speed of 54Mbps, enables to monitor and debug if there is any error in functioning through the remote machine.The main advantage of the Mini-ITX Motherboard is its low power consumption. This is illustrated in figure 3.2
CHAPTER 3. VIA CN700 CHIPSET 13
Chapter
4
Robotic Platform and Robotic Arm
4.1
Robotic Platform
The Robotic platform consists of a base, with wheels and motors attached to it, so that it moves according to the controls given. Since the robot is autonomous, the number of wheels should be selected carefully. The main criteria for selecting a wheel configuration are stability and the ability to turn without displacement i.e. turning with zero radius. A three wheel configuration is implemented in AIBOT using PIC18F4431 microcontroller for controlling the motors. Criteria for selection of wheel configuration and motors are explained below.
4.2
Wheel configurations
The wheeled robots are designed so that all the wheels are in ground contact at all times. Hence balance is usually not a research problem for these robots[1]. However a good control system is necessary for robots using less than three wheels.
Wheels
There are four major wheel classes as shown in figure 4.1. The standard wheel and the caster wheel have a primary axis of rotation and are thus highly directional. To move in a different direction, the wheel must be steered first along a vertical axis. The key difference between these two wheels is that the standard wheel can accomplish this steering motion with no side effects, as the center of rotation passes through the contact patch with the ground, whereas the caster wheel rotates around an offset axis, causing a force to be imparted to the robot chassis during steering.The Swedish wheel1 and the spherical wheel designs are less constrained by directionality than the conventional standard wheel.
1
presently we are not using this wheel because of non availability
CHAPTER 4. ROBOTIC PLATFORM AND ROBOTIC ARM 15 Here, the AIBOT platform uses two standard wheels for rear drive and a swivel wheel in the front.
Figure 4.1: Four basic wheel types, a) Standard wheel: two degrees of freedom b)Caster wheel: two degrees of freedom c)Swedish wheel: three degrees of freedom d) Ball or Spherical wheel: realization technically difficult
Wheel geometry
Static stability requires a minimum of three wheels with the additional requirements that the center of gravity must be inside the triangle formed by the three wheels. A four wheel driving system which is commonly used in cars, buses etc cannot make zero radius turn like a three wheel configuration. A three wheel driving system is shown in figure 4.2.This type of driving system helps the robot to turn with zero radius as illustrated in figure 4.3.
Figure 4.2: Three wheel configuration
4.3
Selection of Motors
The main criteria for selecting motors for robot drive are good speed and torque. There are three types of motors available in the market - DC Motors, Stepper Motors and Servo Motors.
CHAPTER 4. ROBOTIC PLATFORM AND ROBOTIC ARM 16
Figure 4.3: Zero radius turning
Stepper Motors
A stepper motor is exclusively used for measured rotation. Its ability to hold the shaft at a particular position and high precision makes it ideal for many autonomous robotic applications. Torque decreases with increase in stepping frequency. However they have low torque to weight (see figure 4.4) ratio which makes it inappropriate for the arm applications.
DC Motors
A DC motor as the name suggests uses dc current for its operation. The direction can be changed by reversing the voltage and the speed can be controlled by controlling the average power fed into the motor. It has a low torque to weight ratio compared to a servo motor. However the torque can be increased using gear mechanisms at the cost of speed. A DC motor requires an external driver circuit which is essentially a current amplifying circuit (an H-bridge is commonly used). For position control an external feedback mechanism such as slotted disk or a hall effect sensor is required. A Pulse Width Modulated(PWM) signal is used to control the speed of a DC motor.
Geared DC motors which are readily available in the market proved to be good choice for driving wheels.
DC Motor control
A DC motor is an electromechanical device which can rotate on its axle using a DC power supply. When the polarity of the power supply is reversed, the direction of the motor re-verses. When the supply voltage is increased from 0 to its maximum rated voltage, the speed of rotation increases.
To have a control over the direction of the motor also, we have to use an H-Bridge cir-cuit. An H-bridge is shown figure 4.6 having four switches S1, S2, S3 and S4. When S1 and
CHAPTER 4. ROBOTIC PLATFORM AND ROBOTIC ARM 17
Figure 4.4: Comparison of servo with stepper having same torque
S4 are closed, the motor rotates in one direction and when S2 and S3 are closed, the motor runs in opposite direction. Semiconductor switches such as BJT or MOSFET can be used for these switches (see figure 4.7 and table 4.1).
In order to control the speed of the DC motor PWM signal is used. PIC18F4431 has four inbuilt PWM modules. The speed is directly proportional to the duty cycle of the PWM signal. Maximum speed is achieved at 100 % duty cycle and zero speed is achieved at 0% duty cycle.
CHAPTER 4. ROBOTIC PLATFORM AND ROBOTIC ARM 18
Figure 4.6: H Bridge using switches
Figure 4.7: H-Bridge circuit using Nmos
4.4
Robotic Arm
The robotic arm consists of seven servo motors and one DC motor providing 5 degrees of freedom. There are three servo motors in the fingers with which the robot can grab a ball comfortably. Two servos are used for palm and elbow and one servo is used for rotating the arm. A high torque geared DC motor with optical feedback is used for the shoulder part of the arm.
H-Bridge circuit using NMOS IRF3710 (Tested with IRF540 also) are used to control the DC motor. For the FET s1 (see Figure 4.8) to act as a switch the gate voltage should be 2V (threshold voltage of the MOSFET) more than the supply voltage ie. 14V. For using 5V signal to control the gate, a gate driver IC MAX62O is used. The output of MAX620 IC will be 11V more than the input voltage. The extra logic gates added to the circuit prevent
CHAPTER 4. ROBOTIC PLATFORM AND ROBOTIC ARM 19
Figure 4.8: H-Bridge with speed control ( IC specified)
Table 4.1: Motor control bits b1 b2 b3 b4 Motor
1 0 0 1 forward
0 1 1 0 reverse
1 1 0 0 brake
0 0 1 1 brake
s1 and S2 to close simultaneously thus avoiding short circuit between motor power supply and ground.
Servo Motors
A servo motor is basically a DC motor with a feedback circuit. It has speed reduction gears inside it to increase the torque. These motors have a potentiometer[11], which determines the angle of the motor shaft, and a servo controller chip that uses its associated peripheral components to take the commanded position in terms of a pulse and then drive the shaft to the commanded position in a feedback loop. The main advantage of a servo motor is its light weight and high torque. The servo motors exhibit good holding torque which makes them ideal for the robotic arm. Servo motors have three terminals, two terminals for power supply and ground and the third for the control signal. Here the control signal is provided by the microcontroller. Since the necessary current required for the motor operation is from the power supply, no driver circuit is needed for the controlling the servo motor. Different types of servos are available in the market. Some servos can rotate 90 degrees, some can rotate 180 degrees and some others can rotate 360 degrees. Continuous rotation servos are also available. In AIBOT all the servos except the microservos can rotate 180 degrees. The microservos(used for fingers) can rotate only 90 degrees.
CHAPTER 4. ROBOTIC PLATFORM AND ROBOTIC ARM 20
The control signal essentially consists of a Pulse Width Modulated (PWM) signal. When the duty cycle of the signal is varied from 5% to 10%, the shaft of the motor turns 0 to 180 degrees as shown in figure 4.9. The servos need to have a refresh rate of 20ms.
Figure 4.9: Servo control signal
PWM generation for servo motor control
PIC18F4431 microcontroller with four PWM generators is used to generate the PWM sig-nals. PIC 16f877 was discarded since it is difficult to get 20ms time period using the inbuilt PWM module. Moreover 16f877 has only two PWM generators compared to four in 18f4431. The time period and duty cycle are controlled by changing values in necessary registers of the PIC microcontroller.Three microservos are used to control the fingers of the robot. Since we need to move all the three fingers simultaneously for comfortable grabbing of the ball, all the three microservos are connected to the same PWM signal. Other three PWM signals are connected to the servo motors at the joints of the robotic arm providing the necessary degrees of freedom.
CHAPTER 4. ROBOTIC PLATFORM AND ROBOTIC ARM 21
Figure 4.10: Servo motors connected to the PC
Chapter
5
Obstacle Avoidance
5.1
Sonar
SONAR- Sound Navigation and Ranging, is the basic technique used in submarines and ships for measuring the depth of the sea. Sonar can also be used for finding obstacles in the path of a mobile machine.
The working of SONAR
Sonar unit mainly consists of an ultrasonic oscillator which produces sound waves at a partic-ular frequency. When these sound waves encounters an obstacle,it hits and reflectes back as echo. An ultrasonic receiver receives this echo. Under normal conditions the sound travels at 340ms. By calculating the time the sound wave took to reach the receiver as echo after it had been transmitted, the distance of the object from the transmitter can be easily calculated[2].
The distance of the obstacle is calculated as d = 340 ∗ t
2 (5.1)
where
1. d=distance of the transmitter from obstacle 2. t=time taken to get an echo
Sonar Transmitter
Sonar transmitter is a two pin module.One pin is connected to the body and is grounded. The other pin is given a 40khz pulse. The oscillator generates sound waves of 40khz fre-quency. The sonar transmitter is shown in the figure 5.1
CHAPTER 5. OBSTACLE AVOIDANCE 23
Figure 5.1: Sonar Transmitter
Sonar Receiver
Sonar Receiver is also a two pin module with one pin connected to ground. The receiver detects the 40khz sound wave transmitted and the output is taken from the second pin. The output of the sonar receiver is a distorted wave having 10-20mV peak to peak voltage. The received voltage vary proportionally to the strength of the signal. The sonar receiver is shown in figure 5.2
Figure 5.2: Sonar Receiver
Distance Calculation Using PIC
A square pulse of 40Khz to the transmitter module makes the ultrasonic oscillator to vibrate and producing sound waves of 40Khz, which is transmitted.The square wave of 40Khz is generated using the PIC 16F72 Microcontroller. After transmitting for 300us the input to the transmitter from the PIC is suspended.This is done to prevent any direct effect on the receiver, since the receiver and transmitter are placed close to each other. The 300us is calculated using the Timer0 module of the PIC. At this time, the receiver will be waiting for the echo. As soon as the 40Khz signal is detected, the signal from the output of the receiver is amplified and fed into the external interrupt pin of the PIC 16F72.
Sound requires 30us to travel 1cm. Sound travels twice the distance between sonar sen-sor and the obstacle i.e, first sound reaches the obstacle, reflects and again travels back the same distance in order to reach the receiver. Therefore, 60us means that there is a 1cm gap between the obstacle and the receiver. The PIC uses Timer0 for calculating every 60us till the echo is detected and each time a variable is incremented. Thus the distance is calculated in centimeter as the value of the variable and the motor will be given instructions to avoid
CHAPTER 5. OBSTACLE AVOIDANCE 24 the obstacle.
The PIC 16F72 microcontroller detects the echo through an external interrupt from the receiver. For the PIC to recognize the interrupt,the interrupt should have a swing of 0V to 5V. So the output of the sonar receiver should be modified accordingly to set the required voltage swing. This requires a receiver circuit.
Receiver Circuit
The sonar receiver circuit consists of three parts 1. Signal amplification circuit
2. Signal detection circuit 3. Signal comparator circuit Signal amplification Circuit
The output from the receiver is amplified in two stages as shown in figure ??.In the first stage, the amplifier is designed to have a gain of 40dB(amplified 100 times) and in the second stage it is designed to have a gain of 20dB(amplified 10 times). So the signal is amplified to 60dB(1000 times). As the micro controller needs a swing from 0V-5V, the negative terminal of the amplifier is connected to ground and is given a power supply of 9V. The amplifiers are biased about the quiescent point of 4.5V using a voltage divider circuit from the power supply. So both the negative and positive side of the alternating signal is amplified equally. LM324(Quad Comparator) is used as the amplifier. The signal amplification circuit is shown in figure 5.3
Figure 5.3: Sonar Amplification Circuit
Signal Detection Circuit
The sonar detection circuit uses the same principle as that of an AM envelope detector. The DC voltage according to the level of the detection signal is output to the capacitor behind the diode. Schottkey barrier diodes(1N5819) are used as its high frequency characteristics is
CHAPTER 5. OBSTACLE AVOIDANCE 25 good. The signal amplitude varies inversely with the distance. The signal detection circuit is shown in figure 5.4
Figure 5.4: Sonar Detection Circuit
Signal Comparator Circuit
The PIC identifies the obstacle by a transition in the external interrupt pin. So it is neces-sary that when the obstacle is detected there should be a change from high(5V) to low(0V) or vice versa from the output of hardware circuit. To accomplish this a comparator is used. The output of the detection circuit has 2V when no obstacle has been detected and 4V when an obstacle is detected. The signal from the detection circuit is fed to the negative terminal of the comparator(LM324). The positive terminal is biased with 3V using a voltage divider. The comparator is configured to have an infinite open loop gain. The comparator is given 9V supply and the negative terminal is grounded. So whenever the obstacle is detected the negative terminal has a value less than 3V and is negatively amplified 10000 times to 0V. Similarly when the obstacle is detected the signal is amplified to the same amount to 9V. The 9V output level is lowered using a resistance to 5V. This is a transition from high to low state when obstacle is detected. This will be recognized by the PIC as an interrupt and do the calculation.The capacitor is used to avoid DC noise.The signal comparator circuit is shown in figure 5.5
CHAPTER 5. OBSTACLE AVOIDANCE 26
Chapter
6
System Communication
6.1
Serial Communication of the PIC with the PC
PIC16F877A Microcontroller
The PIC microcontroller 16F877A is used as the main controller chip or the Master PIC. The easy availability, the presence of serial communication module of PIC 16F877A and sufficient memory(8K) made it an ideal choice for the design. The PIC has a RISC CPU with five I/O Ports and can operate at a maximum frequency of 20MHz. The timer module in the PIC has many features such as interrupt on overflow and programmable prescaler. The Universal Synchronous Asynchronous Receiver Transmitter (USART) module is used for the serial communication with the PC. Pins RC6(Receiver) and RC7(Transmitter) of Port C are the receiver and the transmitter pins of the PIC respectively[?].
Serial port
In the PC serial port, the data is transmitted sequentially. The following advantages of serial port over parallel port made serial communication an efficient choice for the design. Serial cables can be much longer that parallel cables since they have 24V swing compared to 5V swing in parallel port. Parallel port requires more number of wires for data transmis-sion compared to serial port. Moreover parallel port is slowly disappearing from modern computers.
Microcontrollers just need two pins (RXD and TXD) for serial communication. The serial port is connected to the PIC via MAX232 IC. In PIC logic 0 corresponds to 0V and logic 1 corresponds to 5V whereas in serial port logic 0 is +12V and logic 1 is -12V. Therefore MAX232 IC is used to bring down the serial output voltage from (-12V to +12V) to (0V to 5V) since the PIC can intake only up to 5V [8].
GUI using Visual Basic
The GUI (Graphical User Interface) made in Visual Basic is used for the manual control of AIBOT. VB is used to link the serial port of the computer with the USART module of the
CHAPTER 6. SYSTEM COMMUNICATION 28
Figure 6.1: Serial communication block diagram
PIC microcontroller. The serial port communication module is enabled using the ’Microsoft Comm Control 6.0’ component available in VB[10] [3]. The baud rate is set to 9600bps and no parity check is enabled. The VB GUI made for the manual control is shown in figure 6.2
The GUI is divided into four parts: Base, Hand, Sonar and Mode selection.
1. BASE: In the base part there are buttons for forward, reverse, right, left and brake. The distance to move can also be specified in terms of number of rotations to move. The speed of motors can also be selected.
2. HAND: The hand part consists of controls for all the six motors - four servos and one DC motor. Horizontal scroll bars are used to control the servo motors. Duty cycle value and degree of each motor is shown in the GUI. For the DC motor there are options like forward, reverse and brake. The number slots to move also can be specified for the DC motor.
3. SONAR: The GUI contains buttons to test each sonar sensor. The distance between the detected obstacle and AIBOT in centimeters is shown on the screen.
4. MODE: The mode consists of only two buttons which enables the user to select between manual and autonomous modes of operation. In the manual mode user can control the AIBOT using the buttons and scrollbars provided in the GUI. In the autonomous mode the AIBOT will move all by itself avoiding obstacles using ultrasonic sensors. The ’AUTO’ button is used to choose between automatic and manual reception from the serial port. In the manual reception the user has to click the ’RECEPTION’ button to see what is recieved whereas in the automatic mode there is no need to click the ’RECEPTION’ button, the GUI will automatically display whatever value it receives. The comm port can also be enabled or disabled using the GUI.
The GUI can also be controlled using the keyboard. The different keyboard keys assigned are given below.
CHAPTER 6. SYSTEM COMMUNICATION 29 w - forward s - reverse a - left d - right q - brake
e - select/deselect automatic reception
r - check the receive buffer(used in manual reception) t - transmit button(only for hand)
z - slow speed x - medium speed c - fast speed v - full speed , - left(servo 1) . - right(servo 1) i - up(servo 2) k - down(servo 2) p - up(servo 3) ; - down(servo 3) o - DC motor up l - DC motor down ] - finger close(servo 4)
CHAPTER 6. SYSTEM COMMUNICATION 30
6.2
I2C Communication
AIBOT uses individual microcontroller for each section i.e platform, arm, sonar etc. These microcontrollers are connected to a master bus. This kind of modular approach in robot design helps to add extra peripherals without disturbing the existing circuit. For connecting the microcontroller to the master bus, there were three options in 16F877A - Parallel Slave Port (PSP), Serial Peripheral Interface (SPI) and Inter Integrated Circuit (I2C). PSP and SPI needs atleast 11 and 4 lines respectively for PIC to PIC communication. In I2C it can be achieved by just two lines. Here I2C protocol is implemented for PIC to PIC communi-cation
The Inter-Integrated Circuit or I2C Bus specification was originally developed by Philips Inc. for the transfer of data between ICs at the PCB level[6]. Now it has become a world standard that is now implemented in many ICs. Many of today’s applications require a main bus for PCB level communications.
Features of the I2C Bus[6]
• Only two bus lines are required; a serial data line (SDA) and a serial clock line (SCL). • Each device connected to the bus is software addressable by a unique address and simple master/slave relationships exist at all times; masters can operate as master-transmitters or as master-receivers.
• It is a true multi-master bus including collision detection and arbitration to prevent data corruption if two or more masters simultaneously initiate data transfer.
• Serial, 8-bit oriented, bi-directional data transfer can be made at up to 100Kbits/s in the Standard-mode, up to 400 kbit/s in the Fast mode, up to 3.4 Mbit/s in the High-speed mode.
• On-chip filtering rejects spikes of the bus data line to preserve data integrity.
SDA and SCL are two bidirectional lines which are pulled to +5V using a pull up resistor. When the bus is free (ie when no data transfer is taking place) the two line will be in high state. The Clock is provided by the master and all the data transfer is initiated by the master.
Transferring Data
START and STOP condition
Each data transfer is initiated by a START Condition and terminated by a STOP Con-dition. Start and Stop condition are always generated by the master. A start condition is a high to low transition on the SDA line when SCL is high. A low to high transition on the SDA line when SCL is high indicates the stop condition.
CHAPTER 6. SYSTEM COMMUNICATION 31
Figure 6.3: A typical example of I2C
Byte Format
Data is transferred in units of byte. Any number of bytes can be transferred in a single transfer. Each byte should be followed by the acknowledgment bit from the receiver. After 8 clock pulses to send the data, the master send a 9th clock pulse to acknowledge the receiver and releases the SDA line for the receiver. In this clock pulse the receiver pulls the SDA line low indicating that the data was received correctly. If the receiver is busy servicing the interrupt, it can hold the clock low to keep the master in waiting state.
Slave Address Format
Slave address can have a 7-bit or a 10-bit format.Here 7-bit format is used. After the Start condition, the slave address is sent. This 7-bit long address which is followed by the eighth bit- a zero indicates a transmission (WRITE), a one indicates a request for data (READ). A data transfer is terminated by a stop condition. However if the master does not want to release the bus, it can generate repeated start condition without generating a stop condition For simulating the PIC assembly code for I2C protocols, Proteus VSM 1 is used. It has an ’I2C protocol analyzer’ which can capture the data frames in the bus. Two 16F877 PIC microcontrollers are connected to the I2C bus. An I2C bus analyser is connected to the bus. A screenshot of the layout is shown in figure 6.7
CHAPTER 6. SYSTEM COMMUNICATION 32
Figure 6.4: I2C Connection diagram
The address of the slave is set to 0x02. The master first sends a start condition and then the address of the slave to which it should communicate (see Figure 6.6). Here after sending a start condition, the address ’0x02’ is sent. The slave monitors the I2C bus and when it sees the address on the bus after the start condition, it responds with an acknowledgment. The eighth bit of the first byte transferred is reset indicating a write condition. It means that the next byte will be transferred from the master to the slave. Then the master send data (here it is 44) to the slave. When all the data bytes have been received correctly by the slave it sends an acknowledgment and then the master sends a stop bit and frees the bus. The simulation output and I2C protocol analyzer is shown figure 6.6 and figure 6.8 respectively
CHAPTER 6. SYSTEM COMMUNICATION 33
Figure 6.5: A Complete Transfer
CHAPTER 6. SYSTEM COMMUNICATION 34
CHAPTER 6. SYSTEM COMMUNICATION 35
Chapter
7
Machine Vision
7.1
Computer Vision
Computer vision is ability of machines to see and recognize objects. Image Processing , Pattern Recognition and Object Detection come under sub domains of computer vision. Several techniques can be used to detect objects of particular size and shape. In this project, Hough transform is used.
7.2
Hough Transform
Hough transform1 is extensively used in the computer vision community. It is primarily used for line detection. However generalized Hough transform can be used to detect any shape of interest[4].
Hough Linear Transform
Consider the equation for a line
y = mx + c (7.1)
where (x,y) is the co-ordinates of the points on the line. Here m and b are the parameters of the line which represent the slope and the y intercept respectively.
Consider another representation of a line y = −cosθ
sinθ x + r
sinθ (7.2)
where r is the perpendicular distance of the origin from the line and θ is the angle between x axis and the perpendicular line passing through the origin. We can observe that there will be only one (r, θ) for a particular line, which means that if we have a (r, θ) space a line will be mapped to a point in that space.
Consider two points p1 and p2 in an x-y plane as shown in figure 7.1. The following analysis
1The Hough transform universally used today was invented by Richard Duda and Peter Hart in 1972,
who called it a ”Generalized Hough Transform” after the related 1962 patent of Paul Hough
CHAPTER 7. MACHINE VISION 37 includes the Hough transform method to find the equation of the line connecting these two points.
Figure 7.1: Two point in x-y plane
Infinite number of lines can pass through a single point as shown in figure 7.2. Now when each line is mapped into (r, θ) space, a plot similar to that given in figure 7.3 is got.
Figure 7.2: Possible lines
In this figure, the two plots for point p1 and p2 are intersecting at a point (r0, θ0). If we plot a line with (r0, θ0) as parameters, we will get a line connecting p1 and p2 as shown in figure 7.3.
Hough transform for detecting circles
Consider the equation of a circle
(x − a)2+ (y − b)2 = r2 (7.3)
where (a,b) is the center and r is the radius of the circle. For a line, there are 2 parameters r and θ, wherein for a circle there are 3 parameters - a,b and r i.e here the accumulator is a 3 dimensional space.
CHAPTER 7. MACHINE VISION 38
Figure 7.3: Mapping
Algorithm with matlab results
1. Reduce the size of the image
The size of the image is decreased to reduce the processing time. In this section a value of each pixel is replaced by the average value of eight pixels adjacent to it. 2. Edge detection (using sobel filter)
Sobel fiter is used for edge detection. This section is tested with canny filter also. 3. Hough circle transform
Circles in the image is detected using Hough transform 4. Isolated a particular coloured ball
In this section the values of the pixels inside the detected circles are averaged. Then this averaged values are compared with values of a specific colour. If we need to isolate a yellow coloured ball, the averaged values are compared with values of yellow colour.
Matlab results
The output of the Matlab program is shown in figure 7.5. The time given is in seconds. Note that the time taken to process the image is considerably large.
CHAPTER 7. MACHINE VISION 39
7.3
Implementation in Java
Since MATLAB is a simulation software and as it consumes more time while processing the images, it can’t be used in real time systems. To increase the speed the program should be coded in any of the programming languages. As Java is fast and reliable, the basic platform for the system is changed from MATLAB to Java. Java is done in the IDE Eclipse provided as freeware by IBM.
7.4
Technologies Used for Java Design
Java is a language which can be used to develop any kind of applications. A Java program is created as a text file with the file extension .java. It is compiled into one or more files of byte codes with the extension .class. Byte codes are a set of instructions similar to the machine code instructions created when a computer program is compiled. The difference is that machine code must run on the computer system it was compiled for; byte codes can run on any computer system equipped to handle Java programs[5].
7.5
Features of Java
Java Virtual Machine(JVM)
The Java Virtual machine is a sort of interpreter that must be written for our particular computer. Byte code is a set of instructions to be run by the Java run-time system i.e the JVM. The security and portability of a Java program results from the fact that the output of a Java compiler is not an executable code; instead it is a byte code. It is this translation to byte code, which makes it very much easier to run a program in a wide variety of environments. This makes Java a platform independent language[9].
Java Packages
Packages in Java are a way of grouping together related classes and interfaces. The various classes used in this project are:
javax.media
This package is basically used for processing real time video and audio. It contains many classes which help in processing video frames such as FrameGrabbingControl, CaptureDe-viceManager etc. In our project, this package is used to grab the picture from the VGA web camera and convert it into frames taken over a fixed interval of time. These frames are then given to a ’ image processing ’ module for further processing.
javax.swing
Swing is a GUI toolkit for Java. Swing is one part of the Java Foundation Classes (JFC). Swing includes graphical user interface (GUI) widgets such as text boxes, buttons,
split-CHAPTER 7. MACHINE VISION 40 panes, and tables. Swing widgets provide more sophisticated GUI components than the earlier Abstract Windowing Toolkit(AWT). Since they are written in pure Java, they run the same on all platforms, unlike the AWT which is tied to the underlying platform’s windowing system. Swing supports a pluggable look and feel - not by using the native platform’s facilities but by roughly emulating them. This means it provides any supported look and feel on any platform. The disadvantage of lightweight components is possibly slower execution. The advantage is uniform behavior on all platforms.
java.awt
AWT stands for Abstract Window Toolkit. It contains all of the classes for creating user interfaces and for painting graphics and images. A user interface object such as a button or a scrollbar is called, in AWT terminology, a component. The AWT Event class and its subclasses are used to represent the events that AWT components can fire. A container is a component that can contain components and other containers. A container can also have a layout manager that controls the visual placement of components in the container. The AWT package contains several layout manager classes and an interface for building our own layout manager.
java.io
It includes the input and output classes for writing to, and reading from streams and for handling files. Java programs perform I/O through streams. A stream is an abstraction that either produces or consumes information. Java implements streams within class hierarchies defined in the java.io package.
java.lang
It includes classes that apply to the language itself which includes the object class, the string class and the system class. All Java programs automatically import this package. The class called System encapsulates several aspects of the run-time environment. Systems contain three predefined stream variables, in, out, and err.
javax.comm.CommPort
CommPort is an abstract class that describes a communications port made available by the underlying system. It includes high-level methods for controlling I/O that are common to different kinds of communications ports. SerialPort and ParallelPort are subclasses of CommPort that include additional methods for low-level control of physical communications ports.
After a communications port has been identified and opened it can be configured with the methods in the low-level classes like SerialPort and ParallelPort. Then an IO stream can be opened for reading and writing data. Once the application is done with the port, it must call the close method.
CHAPTER 7. MACHINE VISION 41 javax.comm.CommPortIdentifier
There are no public constructors for CommPort. Instead an application should use the static method CommPortIdentifier.getPortIdentifiers to generate a list of available ports. It then chooses a port from this list and calls CommPortIdentifier.open to create a CommPort object. Finally, it casts the CommPort object to a physical communications device class like SerialPort or ParallelPort.
The main function of this class is Communications port management. CommPortIden-tifier is the central class for controlling access to communications ports. It includes methods for:
1. Determining the communications ports made available by the driver. 2. Opening communications ports for I/O operations.
3. Determining port ownership.
4. Resolving port ownership contention.
5. Managing events that indicate changes in port ownership status.
An application first uses methods in CommPortIdentifier to negotiate with the driver to discover which communication ports are available and then select a port for opening. It then uses methods in other classes like CommPort, ParallelPort and SerialPort to communicate through the port.
7.6
Process Flow
The AIBOT is set in free running state when the program starts. The sonar detects the presence of any obstacle in line with the AIBOT. The Java program running in the com-puter collects the data from the Master PIC through the serial port. The java program sends a value 34(address of SONAR) continuously to the master PIC. If the SONAR finds an obstacle, the master PIC sends the distance back to the Java program. The program checks whether the distance obtained is between 20cm to 34cm, the program sends signals to the Master PIC for applying brake to DC motors in the base. When the base stops, the program captures frame using the web cam and the ball detection program is initiated.
The algorithm for ball detection and tracking implemented is basically inspired by Hough transform algorithm already explained. Algorithm was first coded in MATLAB and was later converted to java. Java processing took around 1 sec while MATLAB took around 3-4 minutes. In the program a video player is first created, from the player a frame is grabbed and the frame is converted to an image and is saved in the PC.
All the images can be converted to a one dimensional array in Java and from that one dimensional array we can find out the RGB values of each pixel. The image is then resized to half the original size and converted to gray scale form. Then edges are found out using
CHAPTER 7. MACHINE VISION 42 the SOBEL filter implemented in java.. This image is converted to one dimensional array. The one dimensional array is passed on to the Hough transform function to find out the circles present in the image. The possible circles with its centers and radius are achieved from this function. Then the average value of R, G and B in that circle are found out and the colour of the ball is found out.
If the obstacle is a white ball then the PIC sends values to the master PIC for the movement of hand. The Master PIC sends values to the PIC that controls the hand. The hand grabs the ball and brings it to a particular position. If the image captured does not contain the specfic coloured ball it takes a deviation from the obstacle and moves through its side. The Java program again checks for the obstacle and follows the above steps again. The algorithm is shown in figure 7.8
The Addressing Scheme
The whole system consists of several PIC microcontrollers. Unique addresses are given to each PICs so that the master PIC could communicate with all the slave PICs easily. Java program directly communicates with the master PIC only using its USART module. The java program sends a set of seven values for communicating with the corresponding slave PIC. In all the sets of seven, first value corresponds to the address of the PIC. Following are the different addresses given to each PIC and the remaining values of that set. For example the value for the DC motor in the hand are as follows
7 - byte Data Format for Base 1 - Base PIC Address
2 - DC Motor Number
3 - DC Motor direction =1-forward,2-reverse,3-brake 4 - PWM MSB
5 - PWM LSB 6 - DISTANCE MSB 7 - DISTANCE LSB
7 - byte Data Format for Hand 1 - Hand PIC Address
2 - DC Motor Number
3 - Hand movement direction =1-forward,2-reverse,3-brake 4 - Number of slots
5 - Not used 6 - Not used 7 - Not used
CHAPTER 7. MACHINE VISION 43 7 - byte Data Format for SONAR
1 - 0X34 Constant for SONAR Communication 2 - SONAR PIC Address
3 - Not used 4 - Not used 5 - Not used 6 - Not used 7 - Not used
CHAPTER 7. MACHINE VISION 44
CHAPTER 7. MACHINE VISION 45
CHAPTER 7. MACHINE VISION 46
CHAPTER 7. MACHINE VISION 47
CHAPTER 7. MACHINE VISION 48
Chapter
8
Summary and Conclusion
AIBOT has fully functional three wheeled platform, a robotic arm and SONAR sensing units.
8.1
Summary
Robot platform
The motor shaft was designed and fabricated using aluminum rod. The platform uses sheet metal and aluminum sheet for all its members. The platform was able to turn zero radius using its rear steering wheels. A swivel caster wheel was used as front wheel which helps in smooth turning.
Robotic arm
A Robotic arm with four degrees of freedom was designed using servo motors and a DC motor. A grabber using three fingers which is actuated using three micro servos placed at 120 degrees apart was able to grab a specified object of limited size. The prototype is shown in figure 4.11
Ultrasonic Sensing modules
Designed Ultrasonic sensing modules that can detect the distance from the obstacle to a precision of one cm. The minimum and maximum distance that can be detected is 9cm and 60cm respectively.
Computer Vision
The Java program running in the motherboard successfully identified the white coloured ball as per the Hough Algorithm. The output is shown in figure 7.5
CHAPTER 8. SUMMARY AND CONCLUSION 50
8.2
Conclusion
All modules i.e. robot base control board, arm control board and SONAR modules were connected to the master PIC using I2C protocol. The robot can be manually controlled using a remote computer through a GUI developed using Visual Basic Software. The MATLAB program was successfully simulated and can provide the radius and center of a specific coloured ball in any environment. The program was converted to Java program to decrease the processing time. The Java program running on the single board computer distinguished a white ball and a pink ball and grabbed the specified ball using the robotic arm.
Chapter
9
Problems Faced
1. The primary problem faced was in the architecture of the AIBOT. Which microcon-troller and how many microconmicrocon-trollers are needed? Should a motherboard be used or a microprocessor be used for image processing? How can it be controlled manually and autonomously?. Such questions needed to be answered before actually doing the project. This required a lot of research that formed a major part of the time invested. 2. As the AIBOT has mobility, motor controllers are an integral part of it. So an H-Bridge circuit for DC motor controller needed to be designed. Although initially it was designed with MOSFETs, later it was found that it could not supply the sufficient voltage for driving the motors. So MOSFETs were replaced by BJT. But it got heated up and damaged. Then it was found that MOSFETs can be used but only with a gate driver IC. Thus MAX620 was used as the gate driver and was successful. When the PCB was made and tested with the prototype, it was found that the PCB and the MOSFETs got damaged every now and then. Again the proper choice of MOSFETs was a problem. A large number of MOSFETs were looked upon and finally found the right one matching the system.
3. The ball detection was another challenging area. As Digital Image Processing was almost an unknown area for the AIBOT team, it needed a rigorous study to identify the algorithm and it’s implementation in MATLAB. Still the MATLAB was slow and needed to converted to Java which was another unknown area. Finally the detection algorithm was implemented in Java successfully.
4. Choice of a cheap and comfortable sensor for obstacle avoidance needed to be found out. Ultrasonics sensors were decided after thorough research and discussions. When Ultrasonic Sensors or SONAR was initially bought, there was no information about its specifications and characteristics. So it took a lot of time in its specifications. The output of the sensors is in millivolts. The design of amplification, detection and comparison needed a lot of research and it consumed time. There are also problems with the Sonar PCB which was rectified later.
CHAPTER 9. PROBLEMS FACED 52 5. Proper choice of motherboard, implementation of I2C communication in PIC, unavail-ability of components, Mechanical design of the AIBOT...etc are some of the other areas where problems had been faced.
Chapter
10
Future Enhancements
1. Changing from Serial Port communication between PIC and system to USB commu-nication which is faster.
2. Implementation of speech recognition.
3. Implementation of SLAM(Simultaneous Localization And Mapping). 4. Path Detection with feedback of current position in map.
5. Changing AIBOT to an All Terrain Robot.
Bibliography
[1] http://robots.mit.edu/. [2] http://www.hobby_elec.org. [3] http://www.vbhelper.com. [4] http://en.wikipedia.org/wiki/Hough_transform. [5] ’\bibitem{picdatasheet}{\emPIC16f877Adatasheet} www.microchip.com.[6] The I2C-Bus Specification, Version 2.1, January 2000. http://www.nxp.com/ acrobat_download/literature/9398/39340011.pdf.
[7] IPC BORAD User’s Manual Rev 5.0, 2007. [8] Jan Axelson. Serial Port Complete.
[9] Steve Holzner. Java Black Book. Coriolis Technology Press, 2001.
[10] Diamond Brumbaugh Harrington Spenik, Indovina. VisualBasic.6, An Interactive Course. SAMS Publications, 1984.
[11] Karl Williams. How to make Humanoid Robot.