Robotics Workshop I The New Beginning
Question # 1 What is a robot??
An entity designed for some specific ‘Task’ In other words – Your imagination
copyright© IIT Guwahati Robotics Club
Machines v/s Robots Sensing
information about the environment
Planning
Acting
action on the environment
copyright© IIT Guwahati Robotics Club
Question # 2 What is ROBOTICS ???
The science of making a robot But is it a Science or an Art ?? copyright© IIT Guwahati Robotics Club
How Much Time do You Think A robot Requires ??? Depends on what everyone says
copyright© IIT Guwahati Robotics Club
What does a Robot consists of ?? • Mechanical Hardware • Electronics Hardware • Software And the toughest part is ?? Why ?
copyright© IIT Guwahati Robotics Club
Classification of Robotics Three types:• Manual Robotics • Semi-Autonomous Robotics • Autonomous Robotics
copyright© IIT Guwahati Robotics Club
Any thoughts about how tuff is making an autonomous or semi-autonomous robot??? Or which one is more tuff???
copyright© IIT Guwahati Robotics Club
The Components of Robot Motor/Locomotion system
Power Management
ROBOT
Control System
Sensors
copyright© IIT Guwahati Robotics Club
Power - The Need
In any robotic system the basic need to drive it is Power. Can be obtained from: • DC battery • AC Mains • IC Engines Here we wont talk about IC engines for now
copyright© IIT Guwahati Robotics Club
Power Management One can use battery directly or use an adapter/SMPS as the situation demands. For Manual – Adapter if wired remote – Battery if radio controlled For Semi – Autonomous SMPS if you can’t manage on a battery For Autonomous You have to manage on Battery
copyright© IIT Guwahati Robotics Club
Power Management For Battery the options available are • Ni-Cd rechargeable batteries providing around 700mA-hr each with 1.2V output. • Emergency light battery 6V, 4A-hr, a heavy option though confirms you heavy duty.
copyright© IIT Guwahati Robotics Club
Power Management To operate the motors you will need higher voltage supply than what is required by general IC’s. To derive all those voltage values from a given voltage supply • LM317, 7805 5V voltage regulator • PT5048C, PT5049 12V voltage regulator
copyright© IIT Guwahati Robotics Club
Moving a Robot How will a robot move??? • Wheels • Legs • Wings All these run on motors powered by battery or IC engines. copyright© IIT Guwahati Robotics Club
Types Of Motors • • • • •
DC Motors AC Motors Stepper Motors Servo Motors IC Engines
copyright© IIT Guwahati Robotics Club
DC Motors • Run on DC power supply • Can rotate in both directions • To handle one has to control the speed
copyright© IIT Guwahati Robotics Club
DC Motors • DC motors are low torque and high speed devices • Gear set can be used to increase torque at the cost of speed • The movement of the shaft is smooth • Easiest to operate
copyright© IIT Guwahati Robotics Club
Working of DC motor • Direction of rotation of a dc motor can be controlled by changing the direction of voltage applied to the motor
copyright© IIT Guwahati Robotics Club
Working of DC motor • How to drive a dc motor without using a remote? to drive a motor we need certain circuits called Driver Circuits. Driver Circuits act as an interface by providing a link to main power supply based on input signal Readymade IC’s are available. copyright© IIT Guwahati Robotics Club
Working of DC motor H-Bridge It’s a circuit to allow the rotation of motor in both the direction
copyright© IIT Guwahati Robotics Club
Working of DC motor Driving and Braking using H Bridge
copyright© IIT Guwahati Robotics Club
Working of DC motor H-Bridge in short
copyright© IIT Guwahati Robotics Club
Working of DC motor The Required IC – L293D (Quad Half H-Bridge)
copyright© IIT Guwahati Robotics Club
H bridge using L293D
copyright© IIT Guwahati Robotics Club
Working of DC motor
copyright© IIT Guwahati Robotics Club
Working of DC motor • Speed control can be managed by controlling the Voltage across the motor in other words by controlling average power fed to the motor
copyright© IIT Guwahati Robotics Club
Working of DC motor • Voltage across a motor can be changed using a resistor as a potential divider But is energy inefficient as a lot of useful power is wasted in resistor • A better method is PWM (Pulse Width Modulation) copyright© IIT Guwahati Robotics Club
Working of DC motor PWM - It means to change the width of a pulse train depending on the control signal
copyright© IIT Guwahati Robotics Club
Working of DC motor How does PWM help in controlling speed? It can be understood as using a typical average speed problem. Technically the average power fed to the motor is reduced thereby decreasing the speed copyright© IIT Guwahati Robotics Club
Stepper Motors Widely use in Robotics ---why?? • Because More precise than DC motor • Measured rotation and can be held at a particular position- U can rotate the stepper motor with an accuracy of 0.9 degree!!!!!! • Alignment is much better... copyright© IIT Guwahati Robotics Club
Stepper Motors contd..
copyright© IIT Guwahati Robotics Club
Types of Stepper Motors • Mainly 2 types: – Unipolar- Current can flow only in one direction in the coils – Bipolar- Current can flow in both the directions
copyright© IIT Guwahati Robotics Club
Comparison • Unipolar
• Bipolar
3.
3. Current flow in both direction 4. Complicated drive Circuit 5. High Torque
Current flow in one direction 4. Simple drive circuit 5. Less torque
copyright© IIT Guwahati Robotics Club
Modes of Operation • Single Coil Excitation: Only one out of the 4 coils is excited at a given time • Double Coil: Two adjacent coils are excited at a given time • Single and Double: It’s a hybrid of both..(refer diagram for details) copyright© IIT Guwahati Robotics Club
Stepper Motor basics • The stepper motor contains a permanent magnet which is attached to the shaft at centre and there are 4 coils on the 4 sides • Actually the stator contains 100 teeth to get a step angle of 360/(2*100)=1.8degrees. But here for the sake of simplicity, we are showing only one tooth of stator. So don’t get misled into believing that it’s step angle is 90 degrees copyright© IIT Guwahati Robotics Club
Single Coil Mode
copyright© IIT Guwahati Robotics Club
Single coil Excitation Note that until the next coil is switched on, the stator remains in it’s position only. And as we can control when to switch on a particular coil thru software, we can rotate it by exactly the angle we wish.. Compare this with DC motor where the shaft keeps on rotating as soon as the current is switched on copyright© IIT Guwahati Robotics Club
a. Single-Coil Excitation Each successive coil is energized in turn.
copyright© IIT Guwahati Robotics Club
Double coil Excitation
copyright© IIT Guwahati Robotics Club
b. Two-Coil Excitation Each successive pair of adjacent coils is energized in turn.
copyright© IIT Guwahati Robotics Club
Single and Double coil Excitation
copyright© IIT Guwahati Robotics Club
Interleaving the two sequences will cause the motor to half-step
copyright© IIT Guwahati Robotics Club
Comparison • Single coil
• Double coil
2. Low torque 3. Consume less energy 4. Settling time is more
2. High torque 3. Consume double energy 4. Settling time is less
Note: The advantage of hybrid mode is that the step angle gets halved.. So we can control the rotation with double precision
copyright© IIT Guwahati Robotics Club
Circuit Diagram
copyright© IIT Guwahati Robotics Club
Controlling motors thru Computer • Parallel Ports: It’s the easiest way to control the motors from computer. No complicated intermediate circuits are required • Serial/USB ports • Bluetooth * The last 2 modes are beyond the scope of this workshop copyright© IIT Guwahati Robotics Club
25-way Female D-Type Connector
copyright© IIT Guwahati Robotics Club
The pin configuration of the other end of parallel port connector
copyright© IIT Guwahati Robotics Club
Pin details
copyright© IIT Guwahati Robotics Club
Pin details contd.....
copyright© IIT Guwahati Robotics Club
Pin Details • D0-D7 are the data pins(used for output) • C0-C3 are control pins. Note that C1 and C3 are hardware inverted. They can be used for both input and output • S3-S7 are status pins. They are used for taking input from external circuit copyright© IIT Guwahati Robotics Club
PC parallel Port • The PC's Parallel Printer Port had a total of 12 digital outputs and 5 digital inputs accessed via 3 consecutive 8-bit ports in the processor's I/O space. • 8 output pins accessed via the DATA Port • 5 input pins (one inverted) accessed via the STATUS Port • 4 output pins (three inverted) accessed via the CONTROL Port • The remaining 8 pins are grounded copyright© IIT Guwahati Robotics Club
Controlling pins thru program
• Almost every programming language has commands to control the ports. For example in Turbo C, we can use the ‘outportb’ function defined in dos.h outportb(0x378,5) 0x378 is the address of the data pins of the parallel port. The binary form of 5 will appear as an output in the data pins i.e the binary of 5 is 00000101. Therefore D0 and D2 are on and rest pins are off. The ouput can be upto 2^8-1=255
copyright© IIT Guwahati Robotics Club
Control pins • The address for control pins can be obtained by adding 2 to the address of data pins. For eg, here the address of control pins will be 0x378+0x2=0x37a • Therefore the command outportb(0x37a,3) will make both the 1st 2 control pins(C0,C1) low! Because 3=0011 and C0 and C1 are hardware inverted
copyright© IIT Guwahati Robotics Club
Controlling DC motors by H-Bridge
copyright© IIT Guwahati Robotics Club
Implementation of H bridge
copyright© IIT Guwahati Robotics Club
Driving the DC motor
copyright© IIT Guwahati Robotics Club
Connections for a stepper motor
Data Port1
Data Port2
Motor 1
Motor 2
Note –connect a 15v zener diode to pin 10 of IC as shown to prevent damage to the IC due to "back emf" when loads such as motors switch on and off
copyright© IIT Guwahati Robotics Club
Driving the Stepper Motor • In the following slides, we discuss the code for driving the stepper motor in various modes – Single coil mode – Double coil mode – Hybrid mode
copyright© IIT Guwahati Robotics Club
Single Coil Mode The order of the values to be written to parallel port(data pins) 00000001 – (1st coil is on) = 1 00000010 – (2nd coil is on) = 2 00000100 – (3rd coil is on) = 4 00001000 – (4th coil is on) = 8 For 2nd motor 00010000 – (1st coil is on) = 16 0010000 – (2nd coil is on) = 32 0100000 – (3rd coil is on) = 64 1000000 – (4th coil is on) = 128
copyright© IIT Guwahati Robotics Club
Double Coil Mode The order of the values to be written to parallel port(data pins) 00000011 – (1st & 2nd coils are on) = 3 00000110 – (2nd & 3rd coils are on) = 6 00001100 – (3rd & 4th coils are on) = 12 00001001 – (4th & 1st coils are on) = 9 For 2nd motor 00110000 – (1st & 2nd coils are on) = 48 01100000 – (2nd & 3rd coils are on) = 96 11000000 – (3rd & 4th coils are on) = 192 10010000 – (4th & 1st coils are on) = 144
copyright© IIT Guwahati Robotics Club
Hybrid mode The order of the values to be written to parallel port(data pins) 00000001 – (1st coil is on) = 1 00000011 – (1st & 2nd coil is on) = 3 00000010 – (2rd coil is on) = 2 00000110 – (2nd & 3rd coil is on) = 6 00000100 – (3st coil is on) = 4 00001100 – (4th & 3nd coil is on) = 12 00001000 – (4rd coil is on) = 8 00001001 – (1st & 4th coil is on) = 9 The values for the other coil can be determined by shifting the binary representation by 4 places left or multiply the decimal values by 2^4=16
copyright© IIT Guwahati Robotics Club
Sample codes to rotate in ccw drn //single coil mode #include <stdio.h> #include <dos.h>
//double coil #include <stdio.h> #include <dos.h>
main() main() { char a[]={3,6,12,9}; { char a[]={1,2,4,8}; for (int for (int i=0;i<=100;i++) i=0;i<=100;i++) { outportb(888,a[i%4]); delay(10);
}
//hybrid mode #include <stdio.h> #include <dos.h> main() { char a[]={1,3,2,6,4,12,8,9}; for (int i=0;i<=100;i++) { outportb(888,a[i%8 ]); delay(10);
{outportb(888,a[i% 4]); delay(10);
} outportb(888,0);
}
} outportb(888,0);
}
} outportb(888,0);
copyright© IIT Guwahati Robotics Club
Sample codes to rotate in cw drn //single coil mode #include <stdio.h> #include <dos.h> main() { char a[]={1,2,4,8}; for (int i=100;i<=0;i--) { outportb(888,a[i%4]); delay(10); } outportb(888,0); }
//double coil #include <stdio.h> #include <dos.h>
//hybrid mode #include <stdio.h> #include <dos.h>
main() { char a[]={3,6,12,9}; for (int i=100;i<=0;i--)
main() { char a[]={1,3,2,6,4,12,8,9}; for (int i=100;i<=0;i--)
{outportb(888,a[i% 4]); delay(10);
}
} outportb(888,0);
{ outportb(888,a[i%8 ]); delay(10);
}
} outportb(888,0);
copyright© IIT Guwahati Robotics Club
Sample codes to move the robot backward //single coil mode #include <stdio.h> #include <dos.h> main() { char a[]={1,2,4,8}; char b[]={16,32,64,128}; for (int i=100;i<=0;i--) { outportb(888,a[i%4]| b[i%4]); delay(10); } outportb(888,0); }
//double coil #include <stdio.h> #include <dos.h> main() { char a[]={3,6,12,9}; char b[]={48,96,192,144};
for (int i=100;i<=0;i--)
{outportb(888,a[i% 4]|b[i%4]); delay(10);
}
} outportb(888,0);
//hybrid mode #include <stdio.h> #include <dos.h> main() { char a[]={1,3,2,6,4,12,8,9}; char b[]={16,48,32,96,64,19 2,128,144};
for (int i=100;i<=0;i--)
{ outportb(888,a[i%8 ]|b[i%8]); delay(10);
} outportb(888,0);
copyright© IIT Guwahati Robotics Club }
Sample codes to move the robot forward //single coil mode #include <stdio.h> #include <dos.h> main() { char a[]={1,2,4,8}; char b[]={16,32,64,128}; for (int i=0;i<=100;i++) { outportb(888,a[i%4]| b[i%4]); delay(10); } outportb(888,0); }
//double coil #include <stdio.h> #include <dos.h> main() { char a[]={3,6,12,9}; char b[]={48,96,192,144};
for (int i=0;i<=100;i++)
{outportb(888,a[i% 4]|b[i%4]); delay(10);
}
} outportb(888,0);
//hybrid mode #include <stdio.h> #include <dos.h> main() { char a[]={1,3,2,6,4,12,8,9 }; char b[]={16,48,32,96,64,1 92,128,144};
for (int i=0;i<=100;i++)
{ outportb(888,a[i% 8]|b[i%8]); delay(10);
} copyright© IIT Guwahati Robotics Club outportb(888,0); }
Sample codes to turn the bot left //single coil mode #include <stdio.h> #include <dos.h> main() { char a[]={1,2,4,8}; char b[]={16,32,64,128}; for (int i=0;i<=100;i++) { outportb(888,a[(100i)%4]|b[i%4]); delay(10); } outportb(888,0); }
//double coil #include <stdio.h> #include <dos.h> main() { char a[]={3,6,12,9}; char b[]={48,96,192,144};
for (int i=0;i<=100;i++)
{outportb(888,a[(1 00-i)%4]|b[i%4]); delay(10);
}
} outportb(888,0);
//hybrid mode #include <stdio.h> #include <dos.h> main() { char a[]={1,3,2,6,4,12,8,9 }; char b[]={16,48,32,96,64,1 92,128,144};
for (int i=0;i<=100;i++)
{ outportb(888,a[(1 00-i)%8]|b[i%8]); delay(10);
} outportb(888,0); copyright© IIT Guwahati Robotics Club }
Sample codes to turn the bot right //single coil mode #include <stdio.h> #include <dos.h> main() { char a[]={1,2,4,8}; char b[]={16,32,64,128}; for (int i=0;i<=100;i++) { outportb(888,a[i%4]| b[(100-i)%4]); delay(10); } outportb(888,0); }
//double coil #include <stdio.h> #include <dos.h> main() { char a[]={3,6,12,9}; char b[]={48,96,192,144};
for (int i=0;i<=100;i++) {outportb(888,a[i%4]| b[(100-i)%4]); delay(10); } outportb(888,0); }
//hybrid mode #include <stdio.h> #include <dos.h> main() { char a[]={1,3,2,6,4,12,8,9 }; char b[]={16,48,32,96,64,1 92,128,144};
for (int i=0;i<=100;i++)
{ outportb(888,a[i% 8]|b[(100-i)%8]); delay(10);
} outportb(888,0); copyright© IIT Guwahati Robotics Club }
Cracking Techno Tennis.... Here we present some vague ideas for developing your robot. Two important considerations are: • Basic movable base which can be accurately positioned and moved in any direction • Hitting mechanism copyright© IIT Guwahati Robotics Club
If u use stepper motors • The data pins D0-D3 will be connected to the left motor and D4-D7 to the right one (or vice versa) • To control the hitting mechanism u can use the 4 control pins. For example u can switch on a control pin to trigger a flap mechanism. A power amplifier must be used in between port pins and devices involved in hitting mechanism copyright© IIT Guwahati Robotics Club
Please note.... Windows XP doesn’t allow to directly access the parallel port so we have to use third party drivers which opens the specific ports.One such software is Userport. http://www.embeddedtronics.com/public/ Ele Generally the address of the parallel port is 0x378-0x37F.If not the check its address in the specific port properties in device manager. copyright© IIT Guwahati Robotics Club
PROGRAMMING IN MATLAB • Basics of Matlab • Image Capturing. • Image Processing.. • Object Identification… • Movement Algorithm….
copyright© IIT Guwahati Robotics Club
Basics Of Matlab • Pre-declaration of variable is not necessary, you can use variable whenever required. • FOR loop for i=1:n body end • IF condition if(condn) statement end • Image is treated as an array in Matlab which can be in any format like RGB,Grayscale,BW,Intensity. • Function[output variables]=name(input variables).Function should be written in an M-file. • For calling function say ‘add’ type add(4,5) in the prompt. copyright© IIT Guwahati Robotics Club
Image Capturing. • • • •
Make a video input object. Set various attributes of the object. Take Snap Shots. Save images in an array.
copyright© IIT Guwahati Robotics Club
Image Capturing. x=0; T=0; data=.2; imaqreset; imaqmem(inf); vid=videoinput('winvideo',1,'RGB24_640x480'); set(vid,'FramesPerTrigger',Inf); triggerconfig(vid, 'Immediate'); start(vid); dio=digitalio('parallel','LPT1');% for enabling parallel ports addline(dio,0:1,'out');
copyright© IIT Guwahati Robotics Club
…….continued for ui=1:10 f=getsnapshot(vid); flushdata(vid); end disp('START');tic; f=getsnapshot(vid);flushdata(vid); prev_cen=0; flag=0; end_y=400; start_y=40; while x==0 T=T+1; f=getsnapshot(vid); {insert your code} end stop(vid);
copyright© IIT Guwahati Robotics Club
Image Capturing. • •
Preview a stream of image frames. preview(obj);
•
Acquire and display a single image frame.
• frame = getsnapshot(obj); •
Remove video input object from memory.
• delete(obj); copyright© IIT Guwahati Robotics Club
Image Processing.. • imread : to read an image eg i=imread(‘name.jpg’); • imview : to view the image eg imview(i); • im2bw : converts a coloured image to black and white eg b=im2bw(i); or b=im2bw(i,.4); copyright© IIT Guwahati Robotics Club
Image Processing.. RGB components • For example, the red, green, and blue color components of the pixel (10,5) are stored in RGB(10,5,1), RGB(10,5,2), and RGB(10,5,3), respectively. eg a=imread(‘name.jpg’); r=a(:,:,1); g=a(:,:,2); b=a(:,:,3); copyright© IIT Guwahati Robotics Club
Object identification • imcrop(image) • Im2bw(image) • medfilt2(image) • bwlabel(image) Distinguishing the ball, robot, red square. • regionprops – area,centroid,perimeter • Ratio of area to sqr of perimeter will be fixed number for a circular object. copyright© IIT Guwahati Robotics Club
• Take [R,G,B] components of image. • Check for area where R >threshold & G,B
copyright© IIT Guwahati Robotics Club
Movement Algorithm
• Use of only 90 degrees turns for motion using DC motor. • Use of stepper motor to move along shortest path. • Implementation At each step find the angle between ball and direction of bot ‘α’. If IαI < 45 deg. Then move bot Repeat till bot hits ball. copyright© IIT Guwahati Robotics Club
MATLAB CODE • dio=digitalio('parallel','LPT1'); • addline(dio,0:3,'out'); putvalue(dio,[0 1 1 0]); • • Keep all the operating tactics of steps same as shown in C
copyright© IIT Guwahati Robotics Club
For any help contact • Niraj Murarka(B2,329,Kameng)
[email protected] ; 9864167497 • Suhas Mishra(B4-206,Kameng)
[email protected] ; 9954248915 • Ashwin Chander(B4-211, Kameng)
[email protected] ; 9954249118 • Abhishek Anand(B2-020,Kameng)
[email protected] • Romesh Khaddar (132,Dihing)
[email protected] copyright© IIT Guwahati Robotics Club