Download as pdf or txt
Download as pdf or txt
You are on page 1of 109

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/252629271

Design, Implementation and Digital Control of a Robotic Arm

Thesis · July 2009


DOI: 10.13140/RG.2.2.34023.24486

CITATIONS READS
0 6,213

3 authors, including:

Mahmoud Khaled Mona Khalaf


Technische Universität München Minia University
24 PUBLICATIONS   58 CITATIONS    1 PUBLICATION   0 CITATIONS   

SEE PROFILE SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Power Quality Improvement of PV System View project

Multiprocessor Implementations of Digital Controllers View project

All content following this page was uploaded by Mahmoud Khaled on 31 May 2014.

The user has requested enhancement of the downloaded file.


 

 
Faculty of Engin
neering 
 
Com
mputers & Systeems Dept. 

Dessign
D n, 
I plem
Imp men ntation 
a d Diggitaal 
and
C ntro
Con ol off a 
R botic Arrm
Rob
  CS
SE – B.S
Sc. Pro
oject ­ 2
2009 
Projject Membrs  Fromm scratch and d with low co
ost, a multipurpose 4 DOF 
• Ayat Salah El‐
A Din Ahmed  robotic arm is deesigned and im mplemented.. With the 
• Mona Khalaf A
M Abel‐Lateef  helpp of a DAQ caard and MATLLAB, a digital PID 
• Mahmood Kh
M aled  controller is desiigned and imp plemented to o control the 
M
Mohammed  anggles of the join
nts of the arm
m. Using a diggital camera 
andd Image Proceessing toolboxx in MATLAB, a simple 
  GUI application iis developed to demonstraate how the 
  robotic arm works. The robottic arm identiffies certain 
Sup
pervised by  objeects within itss workspace bbased on their shape and 
colo
or, moves tow wards them, p picks them up p and places 
Prof. M.
M Mone
ess themm to a certainn position. 

 
Design, Implementation and Digital Control of a Robotic Arm

Acknowledgment
The work on this project has been an inspiring, often exciting, sometimes challenging,
but always interesting experience. It has been made possible by many other people, who
have supported us. So we would like to take this opportunity to express our sincere
gratitude to all those who have contributed in completing this project.

First of all, we Thank ALLAH who gave us the strength, power and health for finishing
this project.

We are grateful to our supervisor prof. M.Moness for his continuous support for the
project, from initial advice and contacts in the early stages of conceptual inception, and
through ongoing advice and encouragement to this day.

We would also like to thank Eng. Mohammed Abdel-Hady for his help and advice
throughout the project, and also our colleges from the other departments for providing
us with the necessary information and advice in their fields.

We thank all department technicians who helped us during our work times and
supported us with all possible tools and labs

Finally, We wish to thank our parents for their undivided support and interest, who has
inspired us and encouraged us to go our own way, without whom we would unable to
complete this project.

[1]
Design, Implementation and Digital Control of a Robotic Arm

Table of Contents

Acknowledgment ............................................................................................................................ 1
Preface ............................................................................................................................................ 4

Chapter 1 : Introduction ................................................................................................................. 5


1.1. System overview.............................................................................................................. 5
1.2. System block diagram...................................................................................................... 6
1.3. Applications ..................................................................................................................... 7
1.4. Previous work in this field ............................................................................................... 7

Chapter 2 : Mechanical Model ....................................................................................................... 9


2.1. Block Diagram .................................................................................................................. 9
2.2. Design and implementation .......................................................................................... 10
2.3. Kinematics of the Robotic Arm ...................................................................................... 16
2.4. Selecting DC Motors ...................................................................................................... 20

Chapter 3 : DC Motors Modeling and Interfacing ........................................................................ 22


3.1. Overview of DC Motors ................................................................................................. 22
3.2. Motor Driver Circuit ...................................................................................................... 22
3.3. Motor Parameters ......................................................................................................... 24
3.4. Modeling DC Motors ..................................................................................................... 27
3.5. Pulse Width Modulation (PWM) ................................................................................... 29
3.6. Shaft Encoders ............................................................................................................... 30

Chapter 4 : DC Motors Control using PID ..................................................................................... 37


4.1. Overview of PID Controller ............................................................................................ 37
4.2. Overview of DAQ Card................................................................................................... 49
4.3. Motor Position Control (MATLAB Simulation) .............................................................. 54

Chapter 5 : The Gripper ................................................................................................................ 67


5.1. Overview........................................................................................................................ 67
5.2. Gripper control .............................................................................................................. 68
5.3. Gripper simulation......................................................................................................... 69

[2]
Design, Implementation and Digital Control of a Robotic Arm

Chapter 6 : Image Processing ....................................................................................................... 74


6.1. Overview........................................................................................................................ 74
6.2. Block diagram ................................................................................................................ 75
6.3. Image Acquisition: ......................................................................................................... 76
6.4. Image Thresholding and Noise Cleaning ....................................................................... 77
6.5. Object Recognition ........................................................................................................ 78
6.6. Locating Centers ............................................................................................................ 81
6.7. Circle Detection ............................................................................................................. 81
6.8. Color Recognition: ......................................................................................................... 82

Chapter 7 : System Integration..................................................................................................... 86


7.1. The Workspace .............................................................................................................. 86
7.2. The webcam .................................................................................................................. 87
7.3. DAQ card and Driver Circuits: ........................................................................................ 88
7.4. Controlling the System using Matlab GUI Application .................................................. 89
7.5. GUI Application Source Code ........................................................................................ 91

Chapter 8 : Conclusion and Future Work ..................................................................................... 95


8.1. Conclusion ..................................................................................................................... 95
8.2. Future work ................................................................................................................... 96

REFRENCES .................................................................................................................................. 100


LIST OF FIGURES AND GRAPHS ................................................................................................... 101
NOMENCLATURE......................................................................................................................... 104
ABBREVIATIONS .......................................................................................................................... 105
Appendix-A: [List of Components] ............................................................................................. 106
Appendix-B: [Datasheets]........................................................................................................... 107

[3]
Design, Implementation and Digital Control of a Robotic Arm

Preface
The project is a Robotic Arm that can identify different objects located in its workspace
according to their shape and color and places the objects in a certain location with the help
of a video camera as a visual feedback. The arm has 4 Degrees of Freedom (DOF) with a DC-
Motor at each joint. The DC-Motor is position-controlled using a PID controller to position
the link at the required angle; the feedback of the angle is measured using rotary-encoders.
This project introduces intelligence to industries to reduce human errors and increase the
quality and mass production of industries. It can operate under hazardous circumstances
(high pressure, high temperature and locations that can be unstable for human operation) so
it reduces that risk for human injures. It can be updated and controlled easily to achieve a
larger number of applications. It has a simple graphic user interface (GUI) that can easily be
used by any worker or operator not precisely an engineer. It reduces the costs as it can
perform a task that is done by many workers using only one operator.
Goal of work the goal of this project is to control the angles of a robotic arm joints using a
PID controller with a DAQ card and a computer system as a digital controller.
Computational tools :
MATLAB is a numerical computing environment and fourth generation programming
language. Developed by The MathWorks, MATLAB allows matrix manipulation, plotting of
functions and data, implementation of algorithms, creation of user interfaces, and interfacing
with programs in other languages. Although it is numeric only, an optional toolbox uses the
MuPAD symbolic engine, allowing access to computer algebra capabilities. An additional
package, Simulink, adds graphical multidomain simulation and Model-Based Design for
dynamic and embedded systems.
Proteus PCB design combines the ISIS schematic capture and ARES PCB layout programs to
provide a powerful, integrated and easy to use suite of tools for professional PCB Design.All
Proteus PCB design products include an integrated shape based autorouter and a basic SPICE
simulation capability as standard. This tool was very helpful when designing and
implementing electric circuits.

[4]
Design, Implementation and Digital Control of a Robotic Arm

Chapter 1 : Introduction
1.1. System overview

The project is a Robotic Arm that can identify


different objects located in its workspace according
to their shape and color and places the objects in a
certain location.

The diagram in figure 1.1 describes the main


components of the system.

A Robotic arm is controlled through the Computer


by using a DAQ card. A Digital Camera system is used
for visual feedback. Based on the visual feedback Fig. 1.1 "The system"
information, control signals are calculated and sent
to the arm.

System components
1) Robotic arm: A 4-DOF Manipulator with DC-Motor Joints.
2) Driver Circuit: An electronic circuit that is used for sending Commands to Motors
and Reading Encoder's outputs.
3) Computer Control: A computer Equipped with a PCI DAQ card.
4) Camera System: A digital camera that is used for acquiring an image of the
workspace for providing feedback to the controller.

[5]
Design, Implementation and Digital Control of a Robotic Arm

1.2. System block diagram

The following block diagram describes the main parts of the Robotic Arm
System:

Digital
Camera
(webcam)

Computer
Control
system

Motor
Diver
Circuit

Robotic
Arm

[6]
Design, Implementation and Digital Control of a Robotic Arm

1.3. Applications
The robotic arm system has many applications in many
aspects not only in the industrial field. Here we list some of
the application.

a) Factories, example, Figure (1.2 – 1.3)


1. Assembly lines.
Fig 1.2

2. Sorting objects.
3. Collecting objects.
b) Nuclear accident cleanup
c) Planetary exploration
d) Automatic Guided Vehicles in factories

Fig 1.3

1.4. Previous work in this field

Before designing and implementing our robot, we reviewed the


previous works of robotic arms. Here we show some of those robotic
arms and compare them to our robot,

Lynx 5 Robotic Arm


This is a 5 DOF robotic arm. The links are actuated using servo
motors. This lead to reducing the size of the robot. The robot is
interfaced using a driver circuit and connected to PC using serial port.

Fig 1.4: Lynx5 Robotic Arm

KUKA KR C1
This is a famous industrial robotic arm with 6 DOF and used to carry
heavy weights. Its main applications: Arc welding, Machining,
Polishing, grinding, Assembly and Cutting

Fig 1.5: KUKA KR C1 Robotic Arm

[7]
Design, Implementation and Digital Control of a Robotic Arm

Open Source DIY Robotic Arm


A very light robotic arm made of plastic and
actuated using servo motors. It is 5 DOF with a
gripper. This robotic arm is not interfaced using a
PC. It is open-loop controlled using a remote
control circuit.

Fig 1.6: DIY Robotic Arm

Robarm the robotic arm


Giandomenico De Sanctis, made a really clever
robot arm, source and schematics included. It is 5
DOF arm actuated with servo motors and has a
gripper as end-effector.

Fig 1.7: Robarm

[8]
Design, Implementation and Digital Control of a Robotic Arm

Chapter 2 : Mechanical Model


2.1. Block Diagram
The following block diagram describes the process of mechanical modeling and
analysis of our robotic arm,

Model Design

Model
Implementation

Kinematics
Calculations

Model
Simulation

[9]
Design, Implementation and Digital Control of a Robotic Arm

2.2. Design and implementation


A robotic arm is a robot manipulator, usually programmable, with similar functions to
a human arm. The links of such a manipulator are connected by joints allowing either
rotational motion or translational (linear) displacement. There are mainly two types of
links; revolute and prismatic. Figure 2.1 shows the two types of links,

Fig. 2.1 (a)"Revolute Link" (b)"Prismatic Link"

Robotics involves the simultaneous motion in 3D space of several objects. In the


particular case of robotic arms in motion, the resulting end-effectors' trajectory is
caused by the synchronous activation of several motors along the robotic mechanism.
A Joint is the part of the arm that connects two links together. Each link represents
one degree-of-freedom (DOF). The application of the arm decides how many DOF are
required. Larger number of DOF gives great flexibility but more complexity. Each joint
requires an actuator (usually a motor) to perform its required job; bend or rotate or
translate.

[10]
Design, Implementation and Digital Control of a Robotic Arm

Figure 2.2 shows different manipulators with different DOF:

Fig. 2.2 (a) "4-DOF" (b) "3-DOF" (c) "5-DOF"

Figure 2.3 shows a diagram of our robotic arm:

Fig. 2.3 "The robotic arm"

It is a 4-DOF robotic arm, two main links (L1, L2) connected to a link that holds the
end-effector (L3). The end-effector is a gripper that opens and closes as required
which makes the arm capable of holding the required objects. The Base Moves around
the Real Z-Axis causing an angel of . The first joint is placed on the base and moves

[11]
Design, Implementation and Digital Control of a Robotic Arm

the First Link around X-Axis causing an angle of . The second joint is directly
connected to the First Link and Second Link and makes an angle of . The last joint
connects the second link with the gripper directly and makes an angle of . The
gripper has no DOF and it just opens and closes.
To analyze the motion of robot manipulators, reference frames ; a frame is 3-axis
group[X Y Z], the frames are attached to each link starting at frame Fo, attached to the
fixed link (the base), all the way to frame Fn, attached to the robot end-
effector (assuming the robot has n joints). The process followed in assigning frames to
links is based on the Denavit- Hartenberg parameters.
Given two consecutive link frames on a robot manipulator, frames F i-1 and Fi,
frame Fi will be uniquely determined from frame Fi-1 by use of the parameters di, ai, i,
and i illustrated in figure 2.4

Fig. 2.4 "reference frames"

As shown, any link connects two joints together (except last link), from the previous
figure we conclude the following results,

[12]
Design, Implementation and Digital Control of a Robotic Arm

 The Z vector of any link frame is always on a joint axis. The only exception to this
rule is the end-effector of the robot which does not have a joint axis.
 is the algebraic distance along axis to the point where the common
perpendicular intersects axis
 is the length of the common perpendicular to axes and .
 is the angle, about , that the common perpendicular makes with
vector
 is the angle, about , that vector makes with vector

The DH Parameters Table


The DH-Parameters table is a common method of mechanical model of a robotic arm.
It describes each link by these main previously mentioned four parameters. The DH
table (table 2.1) for our robotic arm is presented next,
Joint number α a Ѳ D
0 0 0
1 0 L1 0
2 0 L2 4.5
3 0 L3 -3
Table 2.1

[13]
Design, Implementation and Digital Control of a Robotic Arm

Figure 2.5 shows the real parts of the robot before they are collected to form the
links:

Fig. 2.5 "robotic arm components"

Each link consists of two identical pieces of wood placed in parallel and held in that
position using small stems of wood to support the link and keep the pieces in parallel,
Figure 2.6 shows the firs link attached to the base and the link parts are glued
together.

[14]
Design, Implementation and Digital Control of a Robotic Arm

Fig. 2.6

Figure 2.7 shows the two main links connected together with the joint's DC motors
mounted inside the joints:

Fig. 2.7

[15]
Design, Implementation and Digital Control of a Robotic Arm

The following table 2.2 shows the mechanical specification of each part:
Part Weight (gm) Length (cm)
Link-1 40 for the two pieces, 20 for connecting stems (60 total) 25
Link-2 45 for the two pieces, 20 for connecting stems (65 total) 28
Link-3 16 for the two pecies, 8 for the stems (22 total) 14
Table 2.2
The End-Effector
The end-effector can be designed to perform any desired task such as welding,
gripping, spinning etc., depending on the application.

2.3. Kinematics of the Robotic Arm


With the help of our colleges in the mechanical engineering department, we were
able to calculate the Forward and inverse kinematics of a general 4-DOF robotic arm
with all joints assumed to be revolute. As shown in figure 2.8

Fig. 2.8

Forward Kinematics
Forward kinematics means that we have the angles of each joint and need to calculate
the position of the end-effector and its orientation in the space. The previous figure
shows only the last three angles. The first angle rotates the arm around the base. This

[16]
Design, Implementation and Digital Control of a Robotic Arm

shown configuration is called planar configuration as the robot angles makes it move
inside a single plane.
The following matrices describe the position and orientation of each joint: the
notation describes the translation and orientation matrix from joint x to joint y:

[ ]

[ ]

[ ]

[ ]

The upper left 3x3 Matrix of the A matrix represents the rotation; the upper right 3x1
vector represents the position translation. When a point that is represented with a
position and orientation is multiplied by the A matrix, it will get translated and rotated
by the translation and rotation matrix in the 3D space. The notation means the
sine of while means the cosine of
The Final transform that represent the total forward kinematics:
(2.1)
It is also possible to use MATLAB Robotics toolbox for the simulation and kinematics
calculation of robotic arms. The ROBOTICS toolbox enables designing, simulation
forward and inverse kinematics many types of manipulators.
The following MATLAB code simulates our previously designed robotic arm, the DH-
Table is directly given to MATLAB that simulates it,

[17]
Design, Implementation and Digital Control of a Robotic Arm

function manip=Create4DOFManipulator(L1,L2,L3,t1,t2,t3,t4)
% manip is a ROBOT object :: refer to robot toolbox
% Ls = Link Lengths
% ts = Theta (angles)
% alpha A theta D
% ------------------------------------------------------
L{1} = link([-pi/2 0 t1 0]);
L{2} = link([0 L1 t2 0]);
L{3} = link([0 L2 t3 0]);
L{4} = link([0 L3 t4 0]);

manip = robot(L, 'Manipulator-4DOF', 'robot');


drivebot(manip);
end

Where, L1, L2 and L3 are lengths of links. t1, t2, t3 and t3 are initial angles of each
joint.
In MATLAB workspace we execute this function,
>> manip=Create4DOFManipulator(1,1.5,0.5,0,0,0,0)
manip =
Manipulator-4DOF (5 axis, RRRRR)
grav = [0.00 0.00 9.81] standard D&H parameters
alpha A theta D R/P
0.000000 0.000000 0.000000 0.000000 R (std)
-1.570796 0.000000 0.000000 0.000000 R (std)
0.000000 1.000000 0.000000 0.000000 R (std)
0.000000 1.500000 0.000000 0.000000 R (std)
0.000000 0.500000 0.000000 0.000000 R (std)

[18]
Design, Implementation and Digital Control of a Robotic Arm

This generates the following simulation figures,


[1] Joint Control Panel: Enables changing angles of each joint

Fig. 2.9: Joint Control Panel

[2] Robot’s Current Configuration:

Fig. 2.10: Robot Simulation

Inverse Kinematics
We had used the previously mentioned tool (ROBOTICS Toolbox) inside Matlab to
calculate the inverse kinematics.

[19]
Design, Implementation and Digital Control of a Robotic Arm

2.4. Selecting DC Motors


Selecting the right motor for the right joint is not a random selection. It was done
based on calculations of expected weights that each joint will handle. The basic
specification we look for when selecting a motor for a joint is the holding torque. For
the motor to be able to hold the link and all subsequent links connected to it, its
holding torque should be greater than the sum of all torques from this joint to the end
of the link chain. The following figure shows the links and their weights; also motor
weight should be taken into account,

Where,
 W1, W2, W3 are the weights of each link, the effecting point of those weights
are at the center of each link.
 J2, J3 are the weights if each joint (motor at each joint was also taken into
account).
 G is the weight of the End-Effector.
 M is the weight of the object that the arm will lift.

[20]
Design, Implementation and Digital Control of a Robotic Arm

The required torques at each joint is:

( ) ( ) ( )

( ) ( ) ( )

( ) ( )

And the results was as follows


( )
( )
( )
And hence, the motors were selected correctly.

[21]
Design, Implementation and Digital Control of a Robotic Arm

Chapter 3 : DC Motors Modeling and


Interfacing
3.1. Overview of DC Motors
DC motors are widely used in robotics for their small size and high energy output.
They are inexpensive, small, and powerful.
Typical DC motors operate on as few as 1.5 volts on up to 100 volts. Robotic engineers
often use motors that operate on 6, 12, or 24 volts. DC motors run at speeds from
several thousands to ten thousands RPM. A low voltage (e.g., 12 volt or less) DC motor
may draw from 100 milliamps to several amps at stall, depending on its design.
Main characteristics of DC motors include: High speed, Low torque, and Continuous
Motion.

3.2. Motor Driver Circuit


Controlling DC motors divided into two common types of control, speed control and
direction control. To apply these types of controls we need a circuit that handles this
two requirements we call it motor driver.

The L298N
The L298N consist of four inputs lines (IN1-IN2-IN3-IN4) each pair control one motor,
also contain fours outputs (OUT1- OUT2- OUT3- OUT4) each pair connected to the
motors terminals and also to enables lines (ENA-ENB) that can switch on/off the
motors. Addition to the Vcc line the IC power supply and finally the Vs line the motors
power supply.

[22]
Design, Implementation and Digital Control of a Robotic Arm

Fig. 3.1 : The L298N IC Schematic

Control of a DC Motor
To control the motor speed, we apply a train of pulses (high & low) to the enable lines
using a PWM module inside the DAQ card. To control the motor direction, we apply a
TTL logic power (5V for high – 0V for low) to the inputs lines.

Computer

[23]
Design, Implementation and Digital Control of a Robotic Arm

The next figure shows the schematic of a motor driver circuit ready to accept signals
to control a DC motor:

Fig. 3.3: schematic of driver circuit

3.3. Motor Parameters

To choose the right motor for our robot we should choose it according to specific
measured parameters that specify the torque of each motor.

Measuring Motor Parameters

These are the motor parameters that are needed:


 Motor voltage constant: (volts-sec/rad)
 Motor torque constant: (lb-in/amp)
 Motor resistance: (ohms)
 Motor inductance: (Henries)
 Motor inertia: (lb-in-sec^2)

MOTOR RESISTANCE,
For a dc motor we measure the resistance between the 2 armature wires.
MOTOR VOLTAGE CONSTANT,
To measure the voltage constant of the motor, we put the motor shaft in a lathe
and rotate the shaft at some speed [rpm] such as 1000rpm. With a dc motor, use a dc

[24]
Design, Implementation and Digital Control of a Robotic Arm

voltmeter to measure the armature voltage. is then the voltage you read divided
by the speed in rad/sec.
Convert rpm to rad/sec as:

3.1

Where, is the motor torque constant.

MOTOR INDUCTANCE,
To measure the motor inductance, use a low voltage ac source to the motor winding.
For a dc motor, apply the ac voltage to the armature winding, nd measure the voltage
and the current.
Remember that the BLDC motor is usually connected in WYE. Thus the readings will be
line-to-line. You want the phase values for the voltage, so divide the voltage by 2. The
impedance of the BLDC motor phase winding is then:

( )

√ (3.3)

R √ ( )
Solve for the reactance from this equation. Note that the phase resistance was
measured previously. The inductance can then be calculated from:
The reactance = 2π x frequency x inductance (3.5)
The frequency is probably going to be from the ac source at 60 Hz. Thus

(3.6)

[25]
Design, Implementation and Digital Control of a Robotic Arm

MOTOR INERTIA,
 Cylindrical object(solid) of diameter D ( radius R=D/2) and mass M

And this is measured for the motor rotor.


But the motor is also connected to a load (the link). Its inertia is calculated around the
rotation axis of the motor as follows:
(3.7)

The total inertia is then summed for the motor and the link.

Motor Parameters of our robotic arm system


Motor Motor Voltage Inductance(L) Mass Diameter(m Inertia
# Resistance( Constant (Kg) )
Ω) ( )
M1 5.5 0.0292 0.22 0.037

M2 5.5 0.0292 1.81 0.232 0.036 3.758

M3 25 0.0041 0.699 0.232 0.036 3.758

M4 68 0.7633 0.402 0.070 0.023 4.628

Table 3.1

[26]
Design, Implementation and Digital Control of a Robotic Arm

3.4. Modeling DC Motors


The DC Motor Model
A common actuator in this control system is the DC motor. It directly provides rotary
motion and, coupled with wheels or drums and cables, it can provide transitional
motion. The electric circuit of the armature and the free body diagram of the rotor are
shown in the figure 3.4

Fig. 3. 4: motor electric circuit

System Equations
The motor torque, T, is related to the armature current, i, by a constant factor, . The
back emf, e, is related to the rotational velocity by the following equations:
(3.9)

(3.10)

In SI units (which we will use), (armature constant) is equal to (motor constant).


From the figure 3.1 we can write the following equations based on Newton's law
combined with Kirchhoff's law:

̈ ̇ (3.11)
̇ (3.12)

[27]
Design, Implementation and Digital Control of a Robotic Arm

3.4.1. Transfer Function


Using Laplace transform for the above equations, they can be expressed in terms of s
( ) ( ) ( ) (3.13)
( ) ( ) ( ) (3.14)

By eliminating ( ) we can get the following transfer function, where the rotating
speed is the output and the voltage is the input
̇
( )( )
(3.15)

)( )
(3.16)
(( )

3.4.2. State Space


These equations can be represented in state-space form. If we choose motor position,
motor speed, and armature current as our state variables, we can write the equation
as follows:

[ ̇] [ ] [ ̇] [ ] (3.17)

[ ̇] (3.18)

[28]
Design, Implementation and Digital Control of a Robotic Arm

3.5. Pulse Width Modulation (PWM)

Pulse Width Modulation is a technique for reducing the amount of power delivered to a
DC motor. This is typically used in mechanical systems that will not need to be operated
at full power all of the time. Here we use this technique to provide an open loop speed
control on a DC motor.

Instead of reducing the voltage operating the motor (which would reduce its power),
the motor’s power supply is rapidly switched on and off. The percentage of time that
the power is on determines the percentage of full operating power that is accomplished.
Figure 3.5 illustrates this concept, showing pulse width modulation signals to operate a
motor at 75%, 50%, and 25% of the full power potential.

A wide range of frequencies can be used for the PWM signal. A PWM waveform
consisting of eight bits, each of which maybe on or off, the waveform is repetitiously
used to control the motor. Every 1/1000 of a second, a control bit determines whether
the motor is enabled or disabled. Every 1/25 of second the waveform is repeated,
because one to eight bits may be set in the PWM waveform, the motors may be
adjusted to eight power levels between off and full on.

Fig. 3.5: pulse width modulation signals

[29]
Design, Implementation and Digital Control of a Robotic Arm

3.6. Shaft Encoders


When working with DC motors, a shaft encoder is the most common and accurate
way of providing feed-back to the controller. Shaft encoder comes in many shapes
and sizes, but they all rely of the same principle. Figure 3.6a shows a classic encoder
disk (which is one of the main parts of a shaft encoder mechanism) while figure 3.6b
shows how it is connected to the back-shaft of a gear- head DC motor.

Fig. 3.6a : encoder disk

Fig. 3.6c: purpose of shaft encoders

Fig. 3.6b: encoder connection

[30]
Design, Implementation and Digital Control of a Robotic Arm

The purpose of shaft encoders is shown in figure 3.6c, where a U- shaped photo-
couple made of an Infra-Red sender and a matching receiver is positioned in a certain
way so that the beam of infrared light passes through one of the small openings in the
encoder disk.
In reality, photo-couple come in many shapes and sizes, but most of them are more or
less similar to the one shown in figure 3.7. Any photo couple has 4 leads, two for the
sender, which is usually an Infra-Red LED and, and the two others are for the receiver,
which is usually a photo transistor. You can see the schematic representation of that
photo couple at the lower corner of figure 3.7, where is clear that the photo-couple is
composed of a LED and a photo transistor.

The encoder disk is firmly connected to the back-shaft of the motor, so that both the
shaft and the encoder disk rotate at the same r.p.m. (the back-shaft is an extension of
the output shaft of the motor at its back, usually present for the sole purpose of
adding a shaft encoder). When this encoder disk is inserted in the configuration
shown in figure 3.6c, the rotation of the motor
causes the beam of light to be periodically
intercepted by the solid parts of the encoder
disk creating a sequence of pulses of light,
which will be translated by the photo couple's
receiver into pulses of electricity.
Those pulses of electricity contain all the
information we need to implement a closed
loop control.
Fig. 3.7: Optical Encoder

The frequency of those pulses is directly proportional to the speed of rotation of the
shaft (RPM) and the numbers of these pulses correspond to the angular displacement
of the shaft.

[31]
Design, Implementation and Digital Control of a Robotic Arm

The more the number of holes in an encoder disk, the higher will be the resolution
(the slightest angular displacement that can be detected). One important factor that
affects the performance of shaft encoder and thus the overall performance of a closed
loop control system is the position of the encoder disk.

Most of the motors are used with a gearbox designed to reduce the r.p.m. while
increasing the output torque (figure 3.6b shows a motor +gearbox assembly). Thus,
the motor itself can be turning at 4400 r.p.m. for example, driving a 40:1 gear box,
dividing the rpm by 40, giving a final output speed of 110 r.p.m. You can take a great
advantage of this to reach very high degrees of accuracy, by connecting the encoder
disk at the back shaft of the motor (which is turning at 4400 rpm in our example).

This way, each turn of the final output shaft from the gearbox will correspond to 40
turns of the shaft encoder, and if the encoder disk has 30 holes on its circumference, a
single turn on the final output shaft will correspond to 1200 pulses, reaching a
theoretical precision of 0.3 degrees (i.e. each pulse correspond to 0.3 degrees of
rotation of the final output shaft).
Depending on the type of motor and gearbox, it may be difficult to reach exactly that
theoretical precision.

[32]
Design, Implementation and Digital Control of a Robotic Arm

Encoders and angle measurement


In our system we use encoders as feedback tools to the rest of the control system;
these encoders have the following specifications:
First encoder, figure 3.8 (a,b)
 It is an optical encoder
 Connected to first joint
 The motor it is connected to has a gear box with a ratio 1:100
 The encoder disk has 4 slots
 It has a resolution of 359/399 deg.

Fig. 3.8.a

Fig. 3.8.b

[33]
Design, Implementation and Digital Control of a Robotic Arm

The second encoder, Figure 3.9 (a,b)


 It is an optical encoder
 Connected to second joint
 The motor it is connected to has a gear box with a ratio 1:100
 The encoders disk has 4 slots
 It has a resolution of 359/399

Fig. 3.9a

Fig. 3.9b

[34]
Design, Implementation and Digital Control of a Robotic Arm

The third encoder, Figure 3.10 (a,b)


 It is an optical encoder
 Connected to third joint
 The encoder disk has 21 slots
 It has a resolution of 179/20

Fig. 3.10a

Fig. 3.10b

[35]
Design, Implementation and Digital Control of a Robotic Arm

The forth encoder, Figure 3.11 (a,b)


 It is an optical encoder
 Its disk has no slots
 This encoder is used to detect the grippers final position

Fig. 3.11a

Fig. 3.11b

[36]
Design, Implementation and Digital Control of a Robotic Arm

Chapter 4 : DC Motors Control using


PID
4.1. Overview of PID Controller
A proportional-integral-derivative controller (PID controller) is a generic control loop
feedback mechanism (controller) widely used in industrial control systems. A PID
controller attempts to correct the error between a measured process variable and a
desired set-point by calculating and outputting a corrective action that can adjust the
process accordingly and rapidly, to keep the error minimal.

The PID controller calculation (algorithm) involves three separate parameters; the
proportional, integral, and derivative values. The proportional value determines the
reaction to the current error, the integral value determines the reaction based on the
sum of recent errors, and the derivative value determines the reaction based on the
rate at which the error has been changing. The weighted sum of these three actions is
used to adjust the process via a control element such as the position of a control valve
or the power supply of a heating element.

By tuning the three constants in the PID controller algorithm, the controller can
provide control action designed for specific process requirements. The response of
the controller can be described in terms of the responsiveness of the controller to an
error, the degree to which the controller overshoots the set-point and the degree of
system oscillation. Note that the use of the PID algorithm for control does not
guarantee optimal control of the system or system stability.

Some applications may require using only one or two modes to provide the
appropriate system control. This is achieved by setting the gain of undesired control

[37]
Design, Implementation and Digital Control of a Robotic Arm

outputs to zero. A PID controller will be called a PI, PD, P or I controller in the absence
of the respective control actions. PI controllers are particularly common, since
derivative action is very sensitive to measurement noise, and the absence of an
integral value may prevent the system from reaching its target value due to the
control action.
( )
Set-point Output

∑ ∫ ( ) ∑ Process

( )

Fig. 4.1: PID controller


PID Controller Theory
This section describes the parallel or non-interacting form of the PID controller. The
PID control scheme is named after its three correcting terms, whose sum constitutes
the manipulated variable (MV). Hence:
( ) ( )
Where,
, , and are the contributions to the output from the PID controller from
each of the three terms, as defined below.

[38]
Design, Implementation and Digital Control of a Robotic Arm

Proportional term

Plot 4.1 of PV vs. time, for three values of ( and held constant)

The proportional term (sometimes called gain) makes a change to the output that is
proportional to the current error value. The proportional response can be adjusted by
multiplying the error by a constant , called the proportional gain.
The proportional term is given by:
( ) ( )
Where,
: Proportional term of output
: Proportional gain, a tuning parameter
: Error = SP - PV
: Time or instantaneous time (the present)
A high proportional gain results in a large change in the output for a given change in
the error. If the proportional gain is too high, the system can become unstable. In
contrast, a small gain results in a small output response to a large input error, and a
less responsive (or sensitive) controller. If the proportional gain is too low, the control
action may be too small when responding to system disturbances.

[39]
Design, Implementation and Digital Control of a Robotic Arm

In the absence of disturbances, pure proportional control will not settle at its target
value, but will retain a steady state error that is a function of the proportional gain
and the process gain. Despite the steady-state offset, both tuning theory and
industrial practice indicate that it is the proportional term that should contribute the
bulk of the output change.

Integral term

Plot 4.2 of PV vs. time, for three values of ( and held constant)

The contribution from the integral term (sometimes called reset) is proportional to
both the magnitude of the error and the duration of the error. Summing the
instantaneous error over time (integrating the error) gives the accumulated offset
that should have been corrected previously. The accumulated error is then multiplied
by the integral gain and added to the controller output. The magnitude of the
contribution of the integral term to the overall control action is determined by the
integral gain, .

[40]
Design, Implementation and Digital Control of a Robotic Arm

The integral term is given by:

∫ ( ) ( )

Where,
: Integral term of output
: Integral gain, a tuning parameter
: Error = SP - PV
: Time or instantaneous time (the present)
: Dummy integration variable
The integral term (when added to the proportional term) accelerates the movement
of the process towards set-point and eliminates the residual steady-state error that
occurs with a proportional only controller. However, since the integral term is
responding to accumulated errors from the past, it can cause the present value to
overshoot the set-point value (cross over the set-point and then create a deviation in
the other direction).

Derivative term

Plot 4.3 of PV vs. time, for three values of ( and held constant)

[41]
Design, Implementation and Digital Control of a Robotic Arm

The rate of change of the process error is calculated by determining the slope of the
error over time (i.e., its first derivative with respect to time) and multiplying this rate
of change by the derivative gain, . The magnitude of the contribution of the
derivative term (sometimes called rate) to the overall control action is termed the
derivative gain, .
The derivative term is given by:
( )
( )

Where,
: Derivative term of output
: Derivative gain, a tuning parameter
: Error = SP - PV
: Time or instantaneous time (the present)
The derivative term slows the rate of change of the controller output and this effect is
most noticeable close to the controller set-point. Hence, derivative control is used to
reduce the magnitude of the overshoot produced by the integral component and
improve the combined controller-process stability. However, differentiation of a signal
amplifies noise and thus this term in the controller is highly sensitive to noise in the
error term, and can cause a process to become unstable if the noise and the
derivative gain are sufficiently large.

Summary
The proportional, integral, and derivative terms are summed to calculate the output
of the PID controller. Defining ( ) as the controller output, the final form of the PID
algorithm is:

( )
( ) ( ) ( ) ∫ ( ) ( )

[42]
Design, Implementation and Digital Control of a Robotic Arm

where the tuning parameters are,


 Proportional gain,

Larger values typically mean faster response since the larger the error, the larger the
Proportional term compensation. An excessively large proportional gain will lead to
process instability and oscillation.
 Integral gain,

Larger values imply steady state errors are eliminated more quickly. The trade-off is
larger overshoot: any negative error integrated during transient response must be
integrated away by positive error before we reach steady state.
 Derivative gain,

Larger values decrease overshoot, but slows down transient response and may lead to
instability due to signal noise amplification in the differentiation of the error

Loop Tuning
If the PID controller parameters (the gains of the proportional, integral and derivative
terms) are chosen incorrectly, the controlled process input can be unstable, i.e. its
output diverges, with or without oscillation, and is limited only by saturation or
mechanical breakage. Tuning a control loop is the adjustment of its control
parameters (gain/proportional band, integral gain/reset, derivative gain/rate) to the
optimum values for the desired control response.
The optimum behavior on a process change or set-point change varies depending on
the application. Some processes must not allow an overshoot of the process variable
beyond the set-point if, for example, this would be unsafe. Other processes must
minimize the energy expended in reaching a new set-point. Generally, stability of
response (the reverse of instability) is required and the process must not oscillate for
any combination of process conditions and set-points. Some processes have a degree
of non-linearity and so parameters that work well at full-load conditions don't work

[43]
Design, Implementation and Digital Control of a Robotic Arm

when the process is starting up from no-load. This section describes some traditional
manual methods for loop tuning.
There are several methods for tuning a PID loop. The most effective methods
generally involve the development of some form of process model, and then choosing
P, I, and D based on the dynamic model parameters. Manual tuning methods can be
relatively inefficient.
The choice of method will depend largely on whether or not the loop can be taken
"offline" for tuning, and the response time of the system. If the system can be taken
offline, the best tuning method often involves subjecting the system to a step change
in input, measuring the output as a function of time, and using this response to
determine the control parameters.

Choosing a tuning method


Method Advantages Disadvantages
Manual No math required. Online method. Requires experienced
Tuning personnel.
Ziegler– Proven Method. Online method. Process upset, some trial-
Nichols and-error, very aggressive
tuning.
Software Consistent tuning. Online or offline Some cost and training
Tools method. May include valve and involved.
sensor analysis. Allow simulation
before downloading.
Cohen-Coon Good process models. Some math. Offline method.
Only good for first-order
processes.
Table 4.1

[44]
Design, Implementation and Digital Control of a Robotic Arm

1. Manual tuning
If the system must remain online, one tuning method is to first set and values to
zero. Increase the until the output of the loop oscillates, then the should be left
set to be approximately half of that value for a "quarter amplitude decay" type
response. Then increase until any offset is correct in sufficient time for the process.
However, too much will cause instability. Finally, increase , if required, until the
loop is acceptably quick to reach its reference after a load disturbance. However, too
much will cause excessive response and overshoot. A fast PID loop tuning usually
overshoots slightly to reach the set-point more quickly; however, some systems
cannot accept overshoot, in which case an "over-damped" closed-loop system is
required, which will require a setting significantly less than half that of the
setting causing oscillation.

Effects of increasing parameters


Parameter Rise time Overshoot Settling time Error at
equilibrium
Decrease Increase Small change Decrease
Decrease Increase Increase Eliminate
Indefinite (small Decrease Decrease None
decrease or
increase)
Table 4.2
2. Ziegler–Nichols Method
Another tuning method is formally known as the Ziegler–Nichols method, introduced
by John G. Ziegler and Nathaniel B. Nichols. As in the method above, the and
gains are first set to zero. The P gain is increased until it reaches the critical gain, ,
at which the output of the loop starts to oscillate. and the oscillation period are
used to set the gains as shown,

[45]
Design, Implementation and Digital Control of a Robotic Arm

Control Type
P - -
PI ⁄ -
PID ⁄ ⁄
Table 4.3

3. PID Tuning Software


Most modern industrial facilities no longer tune loops using the manual calculation
methods shown above. Instead, PID tuning and loop optimization software are used
to ensure consistent results. These software packages will gather the data, develop
process models, and suggest optimal tuning. Some software packages can even
develop tuning by gathering data from reference changes.
Mathematical PID loop tuning induces an impulse in the system, and then uses the
controlled system's frequency response to design the PID loop values. In loops with
response times of several minutes, mathematical loop tuning is recommended,
because trial and error can literally take days just to find a stable set of loop values.
Optimal values are harder to find. Some digital loop controllers offer a self-tuning
feature in which very small set-point changes are sent to the process, allowing the
controller itself to calculate optimal tuning values. Other formulas are available to
tune the loop according to different performance criteria.

Limitations of PID
While PID controllers are applicable to many control problems, they can perform
poorly in some applications. PID controllers, when used alone, can give poor
performance when the PID loop gains must be reduced so that the control system
does not overshoot, oscillate or hunt about the control set-point value. The control
system performance can be improved by combining the feedback (or closed-loop)
control of a PID controller with feed-forward (or open-loop) control. Knowledge about
the system (such as the desired acceleration and inertia) can be fed forward and

[46]
Design, Implementation and Digital Control of a Robotic Arm

combined with the PID output to improve the overall system performance. The feed-
forward value alone can often provide the major portion of the controller output. The
PID controller can then be used primarily to respond to whatever difference or error
remains between the set-point (SP) and the actual value of the process variable (PV).
Since the feed-forward output is not affected by the process feedback, it can never
cause the control system to oscillate, thus improving the system response and
stability.

For example, in most motion control systems, in order to accelerate a mechanical load
under control, more force or torque is required from the prime mover, motor, or
actuator. If a velocity loop PID controller is being used to control the speed of the load
and command the force or torque being applied by the prime mover, then it is
beneficial to take the instantaneous acceleration desired for the load, scale that value
appropriately and add it to the output of the PID velocity loop controller. This means
that whenever the load is being accelerated or decelerated, a proportional amount of
force is commanded from the prime mover regardless of the feedback value. The PID
loop in this situation uses the feedback information to affect any increase or decrease
of the combined output in order to reduce the remaining difference between the
process set-point and the feedback value. Working together, the combined open-loop
feed-forward controller and closed-loop PID controller can provide a more responsive,
stable and reliable control system.

Another problem faced with PID controllers is that they are linear. Thus, performance
of PID controllers in non-linear systems (such as HVAC systems) is variable. Often PID
controllers are enhanced through methods such as PID gain scheduling or fuzzy logic.
Further practical application issues can arise from instrumentation connected to the
controller. A high enough sampling rate, measurement precision, and measurement
accuracy are required to achieve adequate control performance.

[47]
Design, Implementation and Digital Control of a Robotic Arm

A problem with the Derivative term is that small amounts of measurement or process
noise can cause large amounts of change in the output. It is often helpful to filter the
measurements with a low-pass filter in order to remove higher-frequency noise
components. However, low-pass filtering and derivative control can cancel each other
out, so reducing noise by instrumentation means is a much better choice.
Alternatively, the differential band can be turned off in many systems with little loss
of control. This is equivalent to using the PID controller as a PI controller.

Cascade Control
One distinctive advantage of PID controllers is that two PID controllers can be used
together to yield better dynamic performance. This is called cascaded PID control. In
cascade control there are two PIDs arranged with one PID controlling the set point of
another. A PID controller acts as outer loop controller, which controls the primary
physical parameter, such as fluid level or velocity. The other controller acts as inner
loop controller, which reads the output of outer loop controller as set point, usually
controlling a more rapid changing parameter, flow rate or acceleration. It can be
mathematically proven that the working frequency of the controller is increased and
the time constant of the object is reduced by using cascaded PID controller.

[48]
Design, Implementation and Digital Control of a Robotic Arm

4.2. Overview of DAQ Card


The National Instruments PCI-6221 is a low-cost multifunction M Series data
acquisition (DAQ) board optimized for cost-sensitive applications. Low-cost M Series
devices have a one-year calibration interval. For better accuracy, faster speeds, and an
extended two-year calibration service, consider high-speed and high-accuracy M
Series devices. The following image shows the DAQ card:

Fig. 4.2 DAQ Card

NI PCI-6221 Card Specifications

 Two 16-bit analog outputs (833 kS/s)


 10 digital I/O lines; 32-bit counters; digital triggering
 Correlated DIO (2 clocked lines, 1 MHz)
 37-pin D-Sub connector to reduce connectivity costs by 80%

[49]
Design, Implementation and Digital Control of a Robotic Arm

General DAQ Card Specifications

Form Factor PCI

Operating System / Target Windows, Real-Time, Linux, Mac OS

Measurement Type Digital, Frequency, Quadrature encoder, Voltage

DAQ Product Family M Series

MATLAB Support Yes

Table 4.4

Digital I/O
Number of Channels 10 DIO
Timing Hardware, Software
Maximum Clock Rate 1 MHz
Logic Levels TTL
Input Current Flow Sinking, Sourcing
Programmable Input Filters Yes
Output Current Flow Sinking, Sourcing
Current Drive (Channel/Total) 24 mA/176 mA
Table 4.5

Software Compatibility
 MATLAB
 ANSI C
 LabVIEW
 Visual Studio .NET
 Measurement Studio
 Visual Basic
 LabWindows/CVI

[50]
Design, Implementation and Digital Control of a Robotic Arm

Application and Technology

M Series for Test

For test, you can use 16-bit, 250 kS/s analog inputs and 1 MHz digital lines with NI signal
conditioning for applications including data logging and sensor measurements.

M Series for Control

Low-cost M Series digital lines can drive 24 mA for relay and actuator control. With up
to four analog outputs, two 80 MHz counter/timers, and six DMA channels, M Series
devices can execute multiple control loops simultaneously. Low-cost M Series devices
also have direct support for encoder measurements, protected digital lines, and digital
debounce filters for control applications. With up to 80 analog inputs, 32 clocked digital
lines at rates of 1 MHz, and four analog outputs, you can execute multiple control loops
with a single device. For higher-count control loops, you can use M Series devices in
conjunction and tightly synchronized with National Instruments analog output devices
for 64 or more loops.

Calibration of DAQ card

NI measurement hardware is calibrated to ensure measurement accuracy and verify


that the device meets its published specifications. To ensure the ongoing accuracy of
your measurement hardware, NI offers basic or detailed recalibration service that
provides ongoing ISO 9001 audit compliance and confidence in your measurements.

[51]
Design, Implementation and Digital Control of a Robotic Arm

Pinouts/Front Panel Connections

Fig. 4.3 PCI-6221 (68-Pin) Pinout

[52]
Design, Implementation and Digital Control of a Robotic Arm

DAQ Ports for our control


Our robotic arm is connected to the driver circuit. The driver circuit is connected to
the DAQ card. The following table shows the connection between the driver circuit
and the DAQ card Pinout board:
 For Motor1
P0.1  17  Encoder output
P0.2  49  Enable
P0.3  47  Motor_in1
P0.2  19  Motor_in2
 For Motor2
P0.0  52  Encoder output
P0.5  51  Enable
P0.6  16  Motor_in1
P0.7  48  Motor_in2
 For Motor3
P1.0  11  Encoder output
P1.1  10  Enable
P1.2  43  Motor_in1
P1.3  42  Motor_in2
 For Motor4
P1.4  41  Encoder output
P1.5  6  Enable
P1.6  5  Motor_in1
P1.7  38  Motor_in2
 For Gripper
P2.0  37  G_Ctrl1
P2.1  3  G_Ctrl2
 The Digital Ground
D GND  9  Ground

[53]
Design, Implementation and Digital Control of a Robotic Arm

4.3. Motor Position Control (MATLAB Simulation)

 A State-Space Model

[ ̇] [ ̇] [ ] ( )

[ ]

[ ̇] ( )

We can put the state space equations into MATLAB command window by defining the
system’s matrices as follows

⁄ ⁄ ⁄ ⁄

To obtain the step response, enter the following command in the command window
Step(A,B,C,D)

[54]
Design, Implementation and Digital Control of a Robotic Arm

The step response is then,

Plot 4.4 of step response

Continuous PID
Open the Matlab simulink and place the block as the following:

Fig. 4.4: continuous PID

[55]
Design, Implementation and Digital Control of a Robotic Arm

The signal constraint is a software tuning.


In command window, enter ( , , )

From signal constraint, add tuned parameters ( , , )


Then, run optimization

The optimization progress results the following gains:

Plot 4.5 of continuous PID optimization

[56]
Design, Implementation and Digital Control of a Robotic Arm

The system response after PID control

Plot 4.6 of continuous PID system respons

[57]
Design, Implementation and Digital Control of a Robotic Arm

Discrete PID Controller

Fig. 4.5: discrete PID

We convert the continuous PID controller for discrete as follows:


Type the following command in the command window

[Ad,Bd,Cd,Dd]=ssdata(c2d(ss( A,B,C,D), 0.01 ));

Then enter ( , , )

From signal constraint, add tuned parameters ( , , )


Then, run optimization

The optimization progress results the following gains:

[58]
Design, Implementation and Digital Control of a Robotic Arm

Plot 4.7 of discrete PID optimization

System Response

Plot 4.8 of discrete PID system response

[59]
Design, Implementation and Digital Control of a Robotic Arm

 We control the motor position by using Matlab’s Data Acquisition toolbox and
PID Controller inside a simulink model shown below:

Fig. 4.6: motor position control

We set the required angle as step input with final value of required angle:

Fig. 4.7: step function block

 We set the step final value to 90 degree to move the motor 90 degrees

[60]
Design, Implementation and Digital Control of a Robotic Arm

 We configure the output limits of the discrete PID to [5 -5]

Fig. 4.8: PID block

 The subsystem of M_signals is responsible for the conversion of PID signal into a
digital signals that will be delivered to the motor driver circuit to control the
motor direction and speed. As shown in the block, a digital logic is implemented
to convert the PID signal into motor direction signals (IN_1 and IN_2) needed by
the driver circuit. The PID signal again gets converted to PWM pulse train using
the sub_system ‘Voltage_to_PWM’ this signal is placed on the (EN) pin of the
driver circuit. Detailed description this block is presented below:

[61]
Design, Implementation and Digital Control of a Robotic Arm

Fig. 4.9: motor signals

 The PID signal is compared with zero ( < , >, and =)


 The truth table is as follows
PID < 0 PID > 0 PID ==0 Motor_in1 Motor_in2

0 0 1 1 1

1 0 0 1 0

0 1 0 1 0

Table 4.6
 Motor_in1 = Not (PID < 0).Not (PID > 0). (PID == 0) + (PID < 0).Not(PID >
0).Not(PID == 0)
 Motor_in1= (Not (PID < 0) AND Not (PID > 0) AND (PID == 0)) OR((PID < 0) AND
Not(PID > 0) AND Not(PID == 0))

[62]
Design, Implementation and Digital Control of a Robotic Arm

 Motor_in2 = Not (PID < 0).Not (PID > 0). (PID == 0) + Not (PID < 0). (PID >
0).Not(PID == 0)
 Motor_in2= (Not (PID < 0) AND Not (PID > 0) AND (PID == 0)) OR(NOT(PID < 0)
AND (PID > 0) AND Not(PID == 0))
 Then we adjust the enable signal to be PWM of the PID signal
 The input to the enable is the absolute pulse-width modulated PID signal
 The subsystem of voltage to PWM is as follows

Fig. 4.10: voltage to PWM

 The difference between a triangle signal and the input voltage, Vin is compared
to zero to represent the PWM
 We set the frequency of the triangle signal to 25 HZ, the amplitude to 2.5 and
the offset to 2.5.
 The outputs of the subsystem are then converted to Boolean by Data Type
Conversion block
 The digital M_signals are then entered to the DAQ card using the Digital output
block from the Data-Acquisition toolbox with the pinout set as listed previously:

[63]
Design, Implementation and Digital Control of a Robotic Arm

Now we come to the part responsible for the feed-back of the system
 Digital-Input block from the Data-Acquisition toolbox is used to read the
encoder’s signal, also pinout is set inside the block as listed previously:

 The digital input from the DAQ card is then entered to the encoder reader
subsystem, the encoder reader block diagram is just an up-down counter:

Fig. 4.11: Up-Down Counter Block

[64]
Design, Implementation and Digital Control of a Robotic Arm

Inside this block:

Fig. 4.12: Inside the counter block

 The counter subsystem counts the maximum count for the encoder
 The gain block is responsible for the conversion of the count of the encoder disc
holes into the right angular displacement and outputs it in degrees. The block is
capable of up and down counting using a selection signal (updown). This is done
using two up counter blocks but only one of them works at a time. The final
result of counting is the difference between the two counters. The following
figure shows the configuration of the counter for the first motor (4 slots for
encoder disc and 100:1 gearbox ratio)

Fig. 4.13: counter block Parameters

[65]
Design, Implementation and Digital Control of a Robotic Arm

 the following model is ‘MOTOR_CONTROLLER’, this model is used for the direct
signaling to the driver circuit for the purpose of testing, the following
configuration shows a break order passed to the driver circuit.

Fig. 4.14: Motor Controller Model

 The truth table for the motor-controller is as follows:

Enable Motor_in1 Motor_in2 Output

0 0 0 Stop

0 1 1 Stop

1 1 0 Rotate CW

1 0 1 Rotate CCW

1 1 1 Break

1 0 0 Break

Table 4.7

[66]
Design, Implementation and Digital Control of a Robotic Arm

Chapter 5 : The Gripper


5.1. Overview
In manufacturing, a robot arm can accommodate only certain tasks without changes
to its end effector's ancillary hardware and/or programming. If a robot needs to pick
something up, a type of robot hand called a gripper is the most functional end
effector.

Grippers are the part of the robot that interacts with the environment. The structure of
an end effector and the nature of the programming and hardware that drives it depend
on the task the robot will perform. They are end used to grasp or manipulate objects
during the work cycle. The objects are usually work parts that are moved from one
location to another in the cell. Owing to the variety of parts, shapes, sizes, and weights,
most grippers must custom designed. Types of industrial robot applications can be
mechanical, vacuum, magnetized, adhesive, or just simple mechanical devices such as
hooks.

In our robotic system we designed a gripper that opens and closes as requested to
hold a required object, it is controlled using a programmable IC (PIC) that determines
the time the gripper need to open or close to hold an object. Figure 5.1 shows the
system's gripper. The gripper is actuated using a bipolar stepper motor controlled
using the L923D motor driver

[67]
Design, Implementation and Digital Control of a Robotic Arm

Fig. 5.1: The gripper (before adding the motor)

5.2. Gripper control


The gripper in our system is controlled using a programmable IC (PIC 16F48) which
controls the direction of the motor and the amount of time the motor rotates in a
certain direction. The motor used in the gripper is a stepper motor that is driven using
the IC (L293D).The driver circuit of the gripper is shown in figure 5.2

Fig. 5.2: Control circuit schematic

[68]
Design, Implementation and Digital Control of a Robotic Arm

Using the PROUTUS software we minimized the size of the circuit and obtain the best
routing configuration for the connection and then we implemented it on a printed
circuit board (PCB) as shown in figure 5.3

Fig. 5.3: Control Circuit PCB Layout

5.3. Gripper simulation


In MATLAB SIMULINK, we draw the diagram to control the gripper (close and open).

Fig. 5.4: Gripper control Simulink-Model.

 The input is entered from MATLAB work space by calling the functions
“Close_Grip” or “Open_Grip”,

function Open_Grip()
sim('Grip', [0 0.1], [],[0 true true]);
% This command calls the model ‘Grip’
% the start time of the inputs must be determined first when
% multiple

[69]
Design, Implementation and Digital Control of a Robotic Arm

% inputs are specified


end

function Close_Grip()
sim('Grip', [0 0.1], [],[0 true false]);
% This command calls the model ‘Grip’
% the start time of the inputs must be determined first when
% multiple
% inputs are specified
end

 The zero-order hold block is used to sample the input and convert it to digital
signal.
 Then we used data type conversion block to specify the Boolean data type for
the signal that will enter to the DAQ card.

The following image shows the gripper placed in its joint:

Fig. 5.5: The gripper connected to the robotic arm.

[70]
Design, Implementation and Digital Control of a Robotic Arm

PIC16F84A code for the Gripper controller,


#include <16F84A.h>

#FUSES NOWDT //No Watch Dog Timer


#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#use delay(clock=8000000)
#define COUNT 25

void main()
{
int banned1,banned2,i1,i2;;
banned1=0;
banned2=0;
i1=0;
i2=0;

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
SET_TRIS_B(0b00000000);
SET_TRIS_A(0b11111111);

OUTPUT_B(0b10000000);
delay_ms(1000);
OUTPUT_B(0b00000000);
delay_ms(1000);
OUTPUT_B(0b10000000);
delay_ms(1000);
OUTPUT_B(0b00000000);
delay_ms(1000);

while(true)
{
if(input(PIN_A1))
{

[71]
Design, Implementation and Digital Control of a Robotic Arm

if(input(PIN_A0))
{
if(banned1==0)
{
i1++;
if(i1==COUNT)
{
i1=0;
banned1=1;
banned2=0;
}
OUTPUT_B(0b00001100);
delay_ms(30);
OUTPUT_B(0b00000110);
delay_ms(30);
OUTPUT_B(0b10000011);
delay_ms(30);
OUTPUT_B(0b00001001);
delay_ms(30);
}
}
else
{
if(banned2==0)
{
i2++;
if(i2==COUNT)
{
i2=0;
banned1=0;
banned2=1;
}

OUTPUT_B(0b00001001);
delay_ms(30);

[72]
Design, Implementation and Digital Control of a Robotic Arm

OUTPUT_B(0b00000011);
delay_ms(30);
OUTPUT_B(0b10000110);
delay_ms(30);
OUTPUT_B(0b00001100);
delay_ms(30);
}
}
}
else
{
banned1=0;
banned2=0;
i1=0;
i2=0;
}
}
}

[73]
Design, Implementation and Digital Control of a Robotic Arm

Chapter 6 : Image Processing


6.1. Overview
Image processing is any form of signal processing for which the input is an image, such
as photographs or frames of video; the output of image processing can be either an
image or a set of characteristics or parameters related to the image. Most image-
processing techniques involve treating the image as a two-dimensional signal and
applying standard signal-processing techniques to it. Image processing usually refers
to digital image processing, but optical and analog image processing are also possible.
In robotic arm system we use digital image processing for detecting and identifying
the required objects. The arm's workspace is monitored using a digital camera for
locating the required object's position.

The digital camera is connected to the computer through a USB connection; the
computer receives the acquired image from the camera as an input for specified
software which identifies the objects according to their shape and color, the program
also outputs the center of the required objects which is taken as an input for the rest
of the control program.

The arm's position control program takes the location of the objects and converts it to
specific angles that each link in the arm should move so that it can be able to hold the
object to move it to another position or location. In this system we use the MATLAB
image processing toolbox to process the acquired image.

[74]
Design, Implementation and Digital Control of a Robotic Arm

6.2. Block diagram


The following block diagram describes the process of circle detection and color
recognition using image processing techniques:

Image
Acquisition

Image
Thresholding

Noise
Cleaning

Object counting
and recognition

Locating the
object's center

Color
Recognition

[75]
Design, Implementation and Digital Control of a Robotic Arm

6.3. Image Acquisition


Image acquisition is the process of acquiring the image that will be processed on or
analyzed, and this can be done by two ways:
• From file

The image can be an image that is already saved on the computer, and it can
be acquired by using the matlab command:
F=imread(‘image.jpg’)
• From camera

The image can be acquired from reality by using a web digital camera
connected to the computer and is managed by commands from the MATLAB
program; the image can be just a snapshot or a video that is divided into
frames where each frame is treated as a single image.
In our system we use the second method for acquiring the required image, by
using the getsnapshot MATLAB command the camera captures an image of
the arm's workspace and sends it to the rest of the software for the rest of the
processing. Figure 6.1 show an example of the image that can be acquired by
the camera.

Fig. 6.1: original image

[76]
Design, Implementation and Digital Control of a Robotic Arm

6.4. Image Thresholding and Noise Cleaning

• Thresholding
Image thresholding converts the colored RGB image to a black and white image
in order to prepare it for boundary tracing using bwboundaries MATLAB
command. Figure 6.2(a,b) shows an example of the gray and binary image.

Fig. 6.2: Gray and binary Image

[77]
Design, Implementation and Digital Control of a Robotic Arm

 Noise cleaning
Using morphology functions, remove pixels which do not belong to the objects of
interest. It remove all object containing fewer than 20 pixels, fill any holes, so
that regionprops can be used to estimate the area enclosed by each of the
boundaries.

6.5. Object Recognition


Object recognition in computer vision is the task of finding a given object in an image
or video sequence. For any object in an image, there are many 'features' which are
interesting points on the object that can be extracted to provide a "feature"
description of the object. There are different methods that can be used to tell the
computer how to differentiate between different objects, like,

 Training method
This is done by entering the required patterns in a database so that the program
can compare it with the objects in the image and identify the required objects,
the objects in the image should be of the same shape and size if the specified
shaped so it can be identified.
• Decision theoretic method
It deals with patterns that are described using quantitative descriptors, such as,
area, length, and texture.

• Structural method

It deals with patterns that are best represented by symbolic information, such
as strings, and described by the properties and relationships between those
symbols.
• Some customized equations or function.

This can be a group of equations or a function that defines the patterns or


shapes that are needed to be identified in an image.

[78]
Design, Implementation and Digital Control of a Robotic Arm

6.5.1 Finding boundaries


From the MATLAB image processing toolbox we use the command bwboundaries to
detect the objects' boundaries, It Concentrate only on the exterior boundaries. Option
'noholes' will accelerate the processing by preventing bwboundaries from searching for
inner contours.
[B,L] = bwboundaries(bw,'noholes');

For displaying the label matrix and drawing each boundary we use the following
command
imshow(label2rgb(L, @jet, [.5 .5 .5]))

6.5.2 Defining objects


A pixel p at coordinates (x,y) has two horizontal and two vertical neighbors whose
coordinates are (x+1,y),(x-1,y),(x,y+1),and (x,y-1),this set of 4-neighbors are donated by
N4(p). the four diagonal neighbors of p have coordinates (x+1,y+1),(x-1,y+1),(x+1,y-
1),and (x-1,y-1),as shown in figure 6.3
Two pixels p and q are said o be 4- adjacent if q belongs to N4(p), similarly p and qare
said to be 8-adjacent if q belongs to N8(p).

Fig. 6.3: pixel adjacency

[79]
Design, Implementation and Digital Control of a Robotic Arm

The term connected components (objects) is defined in terms of a path and the
definition of a path in turn depends on adjacency. This implies that the nature of
connected components depends on the form of adjacency we choose.

By using the MATLAB function bwlabel we can define all connected components
(objects) in a binary image, it returns the number of objects present in the image and
gives a numerical label for each object, as shown in figure 6.4

[l,n]=bwlabel(f,conn)

Fig. 6.4: objects labeling

[80]
Design, Implementation and Digital Control of a Robotic Arm

6.6. Locating Centers


After identifying the objects present in the workspace we identify the location of each of
these objects, first, finding the row and column indices for all the pixels belonging to
each object using the MATLAB command find which returns the rows and columns of
each object

[r,c]=find(L=3)
Computing the average value (mean) of the rows and columns allows us to find the
center of the objects
Rbar=mean(r)
cbar=mean(c)

6.7. Circle Detection

By estimate each object's area and perimeter we can form a simple metric that
identifies the roundness of an object:

metric = 4*pi*area/perimeter^2.

This metric is equal to one only for a circle and it is less than one for any other shape.
The discrimination process can be controlled by setting an appropriate threshold. In this
example use a threshold of 0.70 so that only the pills will be classified as round.
By using regionprops command we estimate the area for all of the objects.

[81]
Design, Implementation and Digital Control of a Robotic Arm

Fig. 6.5

6.8. Color Recognition:


We use color recognition to differentiate between different objects present in the arm's
workspace, the required color is entered as an input to the function.
After the program performs the object recognition part it crops a part of each object
and calculates the average value of this part which is the value of the color in this part.
The function then compares this value with the values specified for each color and the
outputs only the center of the object with the required color.

The source code for the Matlab function


This source code is used for detecting the objects in the image that have a red color,
counting the number of objects, locating its center, and identifying the round objects.

The main code

function Red_crcls_centers = Find_Red_Crcl()

close all;

% Image Aquisition
vidobj = videoinput('winvideo');
f=getsnapshot(vidobj);
subplot(3,3,1),subimage(f)
title('Org. Image')

[82]
Design, Implementation and Digital Control of a Robotic Arm

% Gray Image
I = rgb2gray(f);
subplot(3,3,2),subimage(I)
title('Gray. Image')

% Binary Image
%threshold=graythresh(I);
bw=im2bw(I,0.5);
% remove all object containing fewer than 30 pixels
bw = bwareaopen(bw,20);
subplot(3,3,3),subimage(bw)
title('Binary Image')

[c,n] = center(bw);

count=1;
for k=1:n

row = c(k,1);
col = c(k,2);

ic=imcrop(f,[col-5 row-5 10 10]);


red_slice = ic(:,:,1);
m=mean(mean(red_slice));

if(m>=210)
Red_crcls_centers(count,1)=row;
Red_crcls_centers(count,2)=col;
count=count+1;
end

end

[83]
Design, Implementation and Digital Control of a Robotic Arm

The function that calculates the objects center


function [Centers,n] = center( bw )

%computing all connected components in an image


[L,n]=bwlabel(bw);
%L= Numerical LAbel
%N=Number of found objects

for k=1:n
%computing the center of the object
[r,c]=find(L==k);
rbar=mean(r);
cbar=mean(c);

Centers(k,1)=round(rbar);
Centers(k,2)=round(cbar);
end
[B,L] = bwboundaries(bw,'noholes');

% Display the label matrix and draw each boundary


imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end
stats = regionprops(L,'Area','Centroid');

threshold = 0.94;

% loop over the boundaries


for k = 1:length(B)

% obtain (X,Y) boundary coordinates corresponding to label 'k'


boundary = B{k};

% compute a simple estimate of the object's perimeter


delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));

% obtain the area calculation corresponding to label 'k'


area = stats(k).Area;

% compute the roundness metric


metric = 4*pi*area/perimeter^2;

% display the results


metric_string = sprintf('%2.2f',metric);

[84]
Design, Implementation and Digital Control of a Robotic Arm

% mark objects above the threshold with a black circle


if metric > threshold
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
end

text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',...
'FontSize',14,'FontWeight','bold');

end

title(['Metrics closer to 1 indicate that ',...


'the object is approximately round']);
end

[85]
Design, Implementation and Digital Control of a Robotic Arm

Chapter 7 : System Integration


7.1. The Workspace
The robot work-space was designed as a half of a circle. It contains three boxes. The
robotic arm is required to identify objects in the workspace and detect circular
objects. After the process of object recognition using a webcam and with the help of
Matlab’s Image-Processing toolbox the system is required to detect different color of
recognized circles (balls). The robotic arm them moves and picks balls of a specific
color and places them in one of the three boxes based on the color.

The following image shows the workspace of the robotic arm. Small red ball is placed
inside a yellow rectangle. The yellow rectangle represents the area that is visible to
the webcam. The image processing procedure is applied to this area only. Any other
place outside this area is not visible to the vision system.

Fig. 7. 1: The workspace

[86]
Design, Implementation and Digital Control of a Robotic Arm

7.2. The webcam


The web cam is placed in a way to be facing the area labeled by the yellow rectangle.
Its direct is perpendicular to the face of the workspace. The next image shows how
the webcam is configured.

And the following image is a closer view to the


webcam.

Fig. 7. 2: The webcam

The webcam is connected to the PC using USB


port and configured to be used inside MATLAB.
The following image shows a picture captured
by the webcam:

Fig. 7.3: The webcam placed on top of the


workspace

Fig. 7.4

The red ball is detected by our circle recognition algorithm and the marked in the
image by a black rectangle.

[87]
Design, Implementation and Digital Control of a Robotic Arm

7.3. DAQ card and Driver Circuits


The robotic arm is connected directly to the driver circuit (Motor driver circuit using
L298N IC) which in turn gets connected to the DAQ Card. The following image shows
the cable of the DAQ card connecting the circuit to the PC [shown two terminals one
to the DAQ Card and the second one is to the DAQ pinout board]:

And the following image shows the pinout board connected to our driver circuit:

The following circuit shows the motor driver circuit:

[88]
Design, Implementation and Digital Control of a Robotic Arm

7.4. Controlling the System using Matlab GUI Application


A GUI Matlab Application is developed to enable full control of each part of the
system. The following image shows the GUI of the application:

Fig. 7. 5

The application consists of two main parts:


1- Visual-Feedback and Kinematics calculations.
2- Mechanical Model and Control of the Robotic-Arm.

[89]
Design, Implementation and Digital Control of a Robotic Arm

1. Visual-Feedback and Kinematics calculations

This part of the application does the following:


 Image acquisition and taking an image of the system’s workspace.
 Analyzing the image and detecting any circles.
 Classifying found circles based on their color.
 As a test case only red circles are considered, found red-circles are marked with
a black rectangle.
 Computing the position of the circle as three coordinates (X,Y and Z) from the
base frame of the robotic arm.
 Using these coordinates, it can calculate the required angles the arm should
move to reach the ball. The angles are calculated using an inverse kinematics
iterative algorithm.
 Passing angles to the control part of the application after converting them to
degrees.

2. Mechanical Model and Control of the Robotic-Arm

This part of the application does the following:


 Visualizing the robotic arm using the ROBOTICS toolbox with the ability to modify
the parameters of the mechanical model.
 The the ability of generating 3D visualization of the arm.
 Taking the angles to move from the first part.
 Calling control models (Simulink PID Controllers) of each motor and passing
angles to each motor to position the robotic arm correctly.
 Opening or closing the gripper.

[90]
Design, Implementation and Digital Control of a Robotic Arm

7.5. GUI Application Source Code

function varargout = RA_GUI(varargin)


% RA_GUI M-file for RA_GUI.fig

gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @RA_GUI_OpeningFcn, ...
'gui_OutputFcn', @RA_GUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before RA_GUI is made visible.


function RA_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to RA_GUI (see VARARGIN)

% Choose default command line output for RA_GUI


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes RA_GUI wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = RA_GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on button press in btnCapture.


function btnCapture_Callback(hObject, eventdata, handles)

[91]
Design, Implementation and Digital Control of a Robotic Arm

% hObject handle to btnCapture (see GCBO)


% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[c,Img]=FindRedCrcl();
axes(axes_ip);
imshow(Img);
hold on
rectangle('Position', [c(1)-10 c(2)-10 20 20], 'FaceColor','k')
set(handles.edit_x,'String',num2str(c(1)));
set(handles.edit_y,'String',num2str(c(2)));

% --- Executes on button press in btnVisualize.


function btnVisualize_Callback(hObject, eventdata, handles)
% hObject handle to btnVisualize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
L1=str2num(get(handles.edit_l1,'String'));
L2=str2num(get(handles.edit_l2,'String'));
L3=str2num(get(handles.edit_l3,'String'));

r=create4DOFManipulator(L1,L2,L3,0,0,0,0);

axes(handles.axes_robot)
plot(r,[0 0 0 0 0])

% --- Executes on button press in btnCalkIKINE.


function btnCalkIKINE_Callback(hObject, eventdata, handles)
% hObject handle to btnCalkIKINE (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

h=30; % ball workspace height


w=40; % ball workspace width
wcd=5; % distance betweedn ball workspace center and the overall
wokspace center;
p=15; % distance between the arm axis and workspace center;

x=str2num(get(handles.edit_x,'String'))*30/240;
y=str2num(get(handles.edit_y,'String'))*40/320;
z=str2num(get(handles.edit_z,'String'));

L1=str2num(get(handles.edit_l1,'String'));
L2=str2num(get(handles.edit_l2,'String'));
L3=str2num(get(handles.edit_l3,'String'));

r=create4DOFManipulator(L1,L2,L3,0,0,0,0);

y_real = (w/2)-x + wcd;


x_real = h-y+p;
z_real =z;

% The Transform of the gripper

[92]
Design, Implementation and Digital Control of a Robotic Arm

T=transl(x_real,y_real,z_real);

% you should add the rotation here


angles = ikine(r,T)

set(handles.edit_th1,'String',num2str(rad2deg(angles(1))));
set(handles.edit_th2,'String',num2str(rad2deg(angles(2))));
set(handles.edit_th3,'String',num2str(rad2deg(angles(3))));
set(handles.edit_th4,'String',num2str(rad2deg(angles(4))));

axes(handles.axes_robot)
plot(r,angles)

% --- Executes on button press in pushbutton5.


function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.edit_th1_c,'String',get(handles.edit_th1,'String'))
set(handles.edit_th2_c,'String',get(handles.edit_th2,'String'))
set(handles.edit_th3_c,'String',get(handles.edit_th3,'String'))
set(handles.edit_th4_c,'String',get(handles.edit_th4,'String'))

% --- Executes on button press in bntCtrlM1.


function bntCtrlM1_Callback(hObject, eventdata, handles)
% hObject handle to bntCtrlM1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Move_M1_PID(str2num(get(handles.edit_th1_c,’String’)));

% --- Executes on button press in bntCtrlM2.


function bntCtrlM2_Callback(hObject, eventdata, handles)
% hObject handle to bntCtrlM2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Move_M2_PID(str2num(get(handles.edit_th2_c,’String’)));

% --- Executes on button press in bntCtrlM3.


function bntCtrlM3_Callback(hObject, eventdata, handles)
% hObject handle to bntCtrlM3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Move_M3_PID(str2num(get(handles.edit_th3_c,’String’)));

% --- Executes on button press in bntCtrlM4.


function bntCtrlM4_Callback(hObject, eventdata, handles)
% hObject handle to bntCtrlM4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Move_M4(str2num(get(handles.edit_th4_c,’String’)));

% --- Executes on button press in bntGripOpen.


function bntGripOpen_Callback(hObject, eventdata, handles)
% hObject handle to bntGripOpen (see GCBO)

[93]
Design, Implementation and Digital Control of a Robotic Arm

% eventdata reserved - to be defined in a future version of MATLAB


% handles structure with handles and user data (see GUIDATA)
Open_Gripper();

% --- Executes on button press in btnCloseGrip.


function btnCloseGrip_Callback(hObject, eventdata, handles)
% hObject handle to btnCloseGrip (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Close_Gripper();

% --- Executes on button press in btn3D.


function btn3D_Callback(hObject, eventdata, handles)
% hObject handle to btn3D (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
L1=str2num(get(handles.edit_l1,'String'));
L2=str2num(get(handles.edit_l2,'String'));
L3=str2num(get(handles.edit_l3,'String'));

r=create4DOFManipulator(L1,L2,L3,0,0,0,0);
figure, plot(r,[0 0 0 0 0])

Motor Control Functions


function Move_M1_PID(angle)
sim('M1_PID', [0 100], [],num2str(angle));
sim('m1', [0 0.1], [],'0');
end

function Move_M2_PID(angle)
sim('M2_PID', [0 100], [],num2str(angle));
sim('m2', [0 0.1], [],'0');
end

function Move_M3_PID(angle)
sim('M3_PID', [0 100], [],num2str(angle));
sim('m3', [0 0.1], [],'0');
end

function Move_M4(angle)
sim('M4', [0 100], [],num2str(angle));
end

[94]
Design, Implementation and Digital Control of a Robotic Arm

Chapter 8 : Conclusion and Future


Work
8.1. Conclusion
This is a summary of all the achieved goals in the project and the problems that
appeared during our work on building the system.

Achieved goals
The following points are the project goals the we were able to achieve successfully,

 Building a mechanical model for arm.


 Designing and implementing the arm's driver circuit.
 Designing the PID controller for the system including DAQ card as an interface.
 Testing the PID controller on the system and obtaining correct results.
 Building the mechanical model for the gripper.
 Designing and implementing the gripper's driver circuit.
 Designing software for programming the PIC to control the motion of the
gripper.
 Designing software that recognizes the shape and color of required objects.
 Building a GUI program that connects the visual system part with the rest of the
system control.

[95]
Design, Implementation and Digital Control of a Robotic Arm

Problems
The following points are the problems that faced us during the design and
implementation the project,

 We build the entire project prototype ourselves from light wood so it can be
easily handled but this lead to some problems due to its weakness and instability
in its motion.
 In controlling the system there was a problem in the second joint as the motor
torque barely enough to hold the rest of the arm causing this joint to be weak
when it moves.
 In the image acquisition part there was a problem due to difference in the light
above the workspace.

8.2. Future work


In this chapter we introduce all the possibilities of improving our system, including
possible updates in its motion, components, and visual system. These improvements will
increase the project's accuracy, performance quality, and accuracy.

The improvements will be in the fields of:

 Applying mobility
 Model identification
 On-line tuning
 Real time operation
 Image processing

[96]
Design, Implementation and Digital Control of a Robotic Arm

Applying mobility
Applying mobility to the system changes it from being a position fixed robotic arm to a
mobile arm, the mobility increases the arm's workspace from a fixed limited workspace
to an unlimited workspace. Mobility provides the arm with the ability to move freely in
the place where it should operate. For the system to be converted from a fixed robotic
arm to a mobile robotic arm some changes and updates should be made, these changes
are as follows:

 Embedded system controller


For the system to be mobile all its control components should be embedded inside it
as it can't be connected to a computer with wires so it can move easily. A PIC micro
controller can be used instead of the DAQ card for the system control.

 Building a vehicle with a navigational system


For the system to be mobile it should be placed on a moving vehicle, this vehicle
should contain a navigational control system that controls the system's motion, like,
its direction, when it starts its motion and when to stop. It also should contain an
obstacle avoidance system that controls the vehicle and prevents it from being
stopped by any obstacles.

Fig. 8.1: mobile robotic arm

[97]
Design, Implementation and Digital Control of a Robotic Arm

 System weight
For a mobile arm to be used in areas such as offices and houses, it is desirable that
the mobile platform be small sized. In the case of a small-sized platform, the mobile
manipulator may tip over when moving at high speed or executing tasks in the
presence of disturbances. Therefore, it is necessary to simultaneously consider both
stabilization and manipulation while coordinating vehicle motion and manipulator
motion.

 Batteries
The mobile arm should be powered using batteries instead of power supplies so it
can move freely in its workspace.

Model identification
For better performance and increased accuracy the motors' modeling parameters can
be obtained through the computer instead of being measured by hand, this gives more
accurate values of the parameters so that the model kinematics can be calculated and
designed correctly.

Online tuning of the PID


For more accurate control we will tune the PID controller online.

Real time operation


We may use MATLAB RTK (Real Time Kernel) for a real-time control of the robotic arm.

Image processing
• Using live video image acquisition
Using video image acquisition instead of acquiring only one image provides a better
method for monitoring the workspace; it makes the system capable of tracing
moving objects and also capable of noticing any changes in the workspace.

[98]
Design, Implementation and Digital Control of a Robotic Arm

• Using two cameras


Using two cameras instead of one camera allows the program to recognize a third
dimension of the objects, allowing the system to measure the depth of the objects.

[99]
Design, Implementation and Digital Control of a Robotic Arm

REFRENCES
Books and E-Books

[1] Katsuhiko Ogata, "Modern Control Engineering," Second Edition. 1990


[2] Rafael C. Gonzales, Richard E. Woods, Steven L. Eddins "Digital Image
Processing Using MATLAB",2006

[3] William K.Patt, “Digital.Image.Processing.4th.Edition”, Fourth edition, 2007


[4] Liptak, Bela (1995). Instrument Engineers' Handbook: Process Control. Radnor,
Pennsylvania: Chilton Book Company. pp. 20–29.
[5] Tan, Kok Kiong; Wang Qing-Guo, Hang Chang Chieh (1999). Advances in PID
Control. London, UK: Springer-Verlag. ISBN 1-85233-138-0.
[6] Van, Doren, Vance J. (July 1, 2003). "Loop Tuning Fundamentals". Control
Engineering (Red Business Information)

PDF Files and Papers

[1] Sellers, David. "An Overview of Proportional plus Integral plus Derivative
Control and Suggestions for Its Successful Application and Implementation",
1998.
[2] MOTORS.pdf, “Measuring DC Motors Parameters”, METU ROBOT SOCIETY
[3] PID Tutorial, http://saba.kntu.ac.ir/eecd/pcl/download/PIDtutorial.pdf
[4] http://www.toshiba.com/ind/data/tag_files/Q9_Process_PID_Application_Note_4
125.pdf
[5] NI PCI DAQ Manual

Websites and other references

[1] http://www.societyofrobots.com/
[2] http://www.engin.umich.edu
[3] Giandomenico De Sanctis, [http://gidesa.altervista.org/roboticarm.php]
[4] http://www.controleng.com/article/CA307745.html.
[5] http://web.archive.org/web/20050206113949/www.tcnj.edu/~rgraham/PID-
tuning.html. Retrieved on 2009-01-05.
[6] Video Tutorials:
http://www.youtube.com/view_play_list?p=65CC0384A1798ADF

[100]
Design, Implementation and Digital Control of a Robotic Arm

LIST OF FIGURES AND GRAPHS


Figures
Fig. 1.1 << The System>> <<page 5 >>
Fig. 1.2 <<Project Application>> << page 7 >>
Fig. 1.3 <<Project Application>> << page 7 >>
Fig. 1.4 <<LYNX 5 robotic arm>> << page 7 >>
Fig. 1.5 <<KUKA KR C1 robotic arm>> << page 7 >>
Fig. 1.6 <<DIY robotic arm>> << page 8 >>
Fig. 1.7 <<robarm>> << page 8 >>
Fig. 2.1 << (a)"Revolute Link" (b)"Prismatic Link">> << page 10 >>
Fig. 2.2 << (a)"4-DOF" (b)"3-DOF" (c)"5-DOF">> << page 11 >>
Fig. 2.3 <<The Robotic Arm>> << page 11 >>
Fig. 2.4 <<The Reference Frames>> << page 12 >>
Fig. 2.5 <<Robotic Arm Components>> << page 14 >>
Fig. 2.6 <<Arm of Firs Link>> << page 15 >>
Fig. 2.7 <<Arm's Second Link>> << page 15 >>
Fig. 2.8 <<Initial Position >> << page 16 >>
Fig. 2.9 <<Joint Control Panel>> << page 19 >>
Fig. 2.10 <<Robot's Simulation>> << page 19 >>
Fig. 3.1 << L298N schematic IC schematic>> << page 23 >>
Fig. 3.2 << Control of dc motor >> << page 23 >>
Fig. 3.3 << Schematic of driver circuit >> << page 24 >>
Fig. 3.4 << Motor electric circuit>> << page 27 >>
Fig. 3.5 << Pulse width modulation signals>> << page 29 >>
Fig. 3.6a << Encoder disk>> << page 30 >>
Fig. 3.6b << Encoder connection>> << page 30 >>
Fig. 3.6c << Purpose of shaft encoders >> <<page 30 >>
Fig. 3.7 << Optical encoder >> << page 31 >>
Fig. 3.8 <<First encoder>> <<page 33 >>
Fig. 3.9 <<Second encoder>> << page 34 >>

[101]
Design, Implementation and Digital Control of a Robotic Arm

Fig. 3.10 <<Third encoder>> << page 35 >>


Fig. 3.11 <<Forth encoder>> << page 36 >>
Fig. 4.1 <<PID controller >> <<page 38 >>
Fig. 4.2 << DAQ card >> << page 49 >>
Fig. 4.3 <<PCI 6221 pinout>> << page 52 >>
Fig. 4.4 << Continuous PID>> <<page 55 >>
Fig. 4.5 <<Discrete PID>> << page 58 >>
Fig. 4.6 << Motor position control>> << page 60 >>
Fig. 4.7 << Step function block>> << page 60 >>
Fig. 4.8 <<PID block>> << page 61 >>
Fig. 4.9 <<Motor signals>> << page 62 >>
Fig. 4.10 << Voltage to PWM>> << page 63 >>
Fig. 4.11 << Up-down counter block>> << page 64 >>
Fig. 4.12 << inside the counter block >> << page 65 >>
Fig. 4.13 << counter block parameters>> << page 65 >>
Fig. 4.14 << motor controller model>> << page 66 >>
Fig. 5.1 <<The Gripper>> << page 68 >>
Fig. 5.2 <<control circuit schematic>> << page 68 >>
Fig. 5.3 <<control circuit PCB layout>> << page 69 >>
Fig. 5.4 <<Gripper control model>> << page 69 >>
Fig. 5.5 <<the gripper with its motor>> << page 70 >>
Fig. 6.1 <<Original Image>> << page 76 >>
Fig. 6.2 <<Gray and Binary Image>> << page 77 >>
Fig. 6.3 <<Pixel Adjacency>> << page 79 >>
Fig. 6.4 <<Objects Labeling>> << page 80 >>
Fig. 6.5 <<Circle Detection >> << page 82 >>
Fig. 7.1 <<The workspace >> <<page 86 >>
Fig. 7.2 <<The webcam >> <<page 87 >>
Fig. 7.3 <<The workspace with the webcam >> <<page 87 >>
Fig. 7.4 <<captured image >> <<page 87 >>
Fig. 7.5 <<MATLAB GUI >> <<page 88 >>

[102]
Design, Implementation and Digital Control of a Robotic Arm

Fig. 8.1 <<Mobile robotic arm >> <<page 79 >>

Graphs
Plot 4.1 << PV vs. time, for >> << page 39 >>
Plot 4.2 << PV vs. time, for >> << page 40 >>
Plot 4.3 << PV vs. time, for >> << page 42 >>
Plot 4.4 <<step response>> << page 55 >>
Plot 4.5 << continuous PID optimization>> << page 56 >>
Plot 4.6 << continuous PID system respons>> << page 57 >>
Plot 4.7 << discrete PID optimization>> << page 59 >>
Plot 4.8 << discrete PID system response >> << page 59 >>

[103]
Design, Implementation and Digital Control of a Robotic Arm

Nomenclature
Chapter.2
L Link
θ Angle of a Link
F Frame
W Weight of the Link
J Weight of Joint
G Weight of the End-Effector
M Weight of the Object That the Arm Will Lift

Chapter.3
Motor voltage constant
Motor torque constant
Motor resistance
Motor inductance
Motor inertia

Chapter.4
Motor torque
Back EMF voltage
Armature current
Proportional term of output
Integral term of output
Derivative term of output
proportional gain
Error
instantaneous time
integral term
derivative gain
critical gain
oscillation period

[104]
Design, Implementation and Digital Control of a Robotic Arm

Abbreviations
PWM Pulse Width Modulation
PID Proportional-Integral-Derivative
MV Manipulated variable
SP Set-Point
PV Process Variable
DAQ Data Acquisition
RGB Red Green Blue
DOF Degree of Freedom

[105]
Design, Implementation and Digital Control of a Robotic Arm

Appendix-A: [List of Components]


Component Quantity. Price
Woods and Carpentry - 80
Glue and Spray - 30
Copper boards 3 51
Glossy paper for PCB 6 9
Ferric Chloride Acid for PCB 5 51
Metalwork’s tools and screws 51
L298 Motor Driver IC 1 15
Geared DC Motor with different shapes and 4 300
torques
Optical Rotary Encoders 6 60
Stepper motor from old Floppy Drive 5 5
Wires and jumpers - 51
Pic16F84A Micro Contoller ID 1 20
L298N Motor Driver IC 4 80

Total: 691

[106]
Design, Implementation and Digital Control of a Robotic Arm

Appendix-B: [Datasheets]

[107]

View publication stats

You might also like