Sunteți pe pagina 1din 41

Order No : II2/13/01

2012 / 2013

FINAL YEAR PROJECT


Submitted in fulfillment of the requirements for the

ENGINEERING DEGREE FROM THE LEBANESE UNIVERSITY BRANCH


III
Major : Electrical Engineering in Industrial Control

By :

Ali Ahmad El Souki


______________________________________________

Title

2D Pick & Place Robot


Advisor: Dr. Noureddine Alameh
Defended on June 17, 2013 in front of the jury:

Mr. Zouheir El-Hajj


Mr. Hussein El-Amine
Mr. Noureddine Alame
Mr. Carlos Bou Gerges

President
Member
Member
Invited member

Project prepared at ITEC and supervised by Eng. Carlos Bou-Gerges

DEDICATION

I dedicate this project to my family, especially.


To the Soul of my Grandparents
To my Parents whose love and care made me the person that I am today.
To my Brother & Sister who never left my side.
To my Soul mate.

ACKNOWLEDGEMENTS

Thanks to GOD for every blessing he gave us


I would like to thank the Faculty of Engineering for hosting me for five years.
Special thanks to the principal of the Faculty Dr. Mohammad HAMDAN and chief
department Dr. Zouheir EL-HAJJ for their efforts and valuable teaching system.
My deepest appreciations go to Dr.Noureddine ALAME for his time, effort and
advice as a supervisor and academic professor.
I would like to thank Mr.Jad WEHBE general manager of ITEC , Eng. Carlos BouGERGES and all people in ITEC for their help and support in all stages of my project.
Finally, I thank everyone who participated in making this work achievable, hoping
that this project will be an important step into a successful career.

Abstract
Commercial and industrial robots are now in widespread use performing jobs more
cheaply or with greater accuracy and reliability than humans. They are also
employed for jobs which are too dirty, dangerous or dull to be suitable for humans.
Robots are widely used in manufacturing, assembly and packing, transport, earth
and space exploration, surgery, weaponry, laboratory research, and mass
production of consumer and industrial goods.
ITEC (Industrial Technologies Company) proposed a 2D Pick & Place industrial robot
project using BECKHOFF automation products in order to prove the high
performance of the hardware (Servo Drive) and software combination: PC-based
control technology from Beckhoff is ideally suited for single and multiple axis
positioning tasks with highly dynamic requirements .Even though one controller
can execute motion control in parallel with many other complicated automation
processes.

Table of Contents
Table of Contents ........................................................................................................ 5
Chapter I :

Introduction .......................................................................................... 8

I.1-

Project description: ...................................................................................... 8

I.2-

About ITEC: ................................................................................................... 9

Chapter II :

The Hardware .................................................................................. 10

Synchronous Servomotor AM3112-0400-0001 ............................................ 10


a)

Appropriate use: ......................................................................................... 10

b)

Product identification: ................................................................................. 10

c)

Technical description of the motor: ........................................................... 11

II.2-

The Servo drives EL7201:............................................................................ 12

a)

Introduction: ............................................................................................... 12

b)

Technology: ................................................................................................ 13

II.3-

The Controller CX-1020: ............................................................................. 13

a)

About the controller ................................................................................... 13

b)

Remote programming via Ethernet............................................................ 14

II.4-

Principle of operation of the servomotor: ................................................. 14

a)

Definition: ................................................................................................... 14

b)

The Magnet: ............................................................................................... 15

c)

Principle of operation: ................................................................................ 15

II.5-

The Electromagnet: .................................................................................... 17

II.6-

The mechanical system: ............................................................................. 17

Chapter III :

The Software ................................................................................... 18

III.1- BeckHoff-TwinCAT: ..................................................................................... 18


a)

Generalities about TwinCAT ....................................................................... 18

b)

TwinCAT NCI (numerical control interpolation): ........................................ 19

III.2- Creation of the project function blocks: .................................................... 19


a)

MoveToPos Function block: .................................................................... 19

b)

Trigger function block: ............................................................................ 21

c)

CamData function block: ......................................................................... 22

d)

Reset function block: .................................................................................. 27

e)

ComparePos function block: ...................................................................... 27

III.3- The Software: ............................................................................................. 28


a)

Latch Program: ........................................................................................ 29

b)

AxesPower Program: ............................................................................... 30

c)

The Cycle Program: ................................................................................. 31

d)

TorqueLim Program: ................................................................................... 38

Chapter IV :

Conclusion ....................................................................................... 39

IV.1-

Achieved Objectives:............................................................................... 39

IV.2-

Forecast objectives ................................................................................. 39

IV.3-

Interesting Statistics: .............................................................................. 39

IV.4-

References: ............................................................................................. 40

IV.5-

APPENDIX ................................................................................................ 40

List of Figures
Figure 1: Sketch of the project .................................................................................... 8
Figure 2 : BeckHoff Servomotor ................................................................................ 10
Figure 3 : Motor's nameplate elemnts definition ..................................................... 10
Figure 4 : Motor's nameplate.................................................................................... 11
Figure 5 : EL7201 connection diagram with the motor ............................................ 12
Figure 6: Servo Drive operation principle ................................................................. 13
Figure 7 : Principle and construction of a brushless Servo motor ............................ 15
Figure 8 : waveform for sinusoidal EMF style and square wave servo drives .......... 16
Figure 9 : Oubari's logo ............................................................................................. 17
Figure 10 : An instance of MoveToPos FB called GoHome ....................................... 20
Figure 11 : NciFeedTablePreparation FB................................................................... 20
Figure 12: NCIFeedTable FB ...................................................................................... 21
Figure 13 :An instance of Trigger FB Called Trig ....................................................... 21
Figure 14: Ladder diagram Trigger ............................................................................ 22
Figure 15: An instance of FB CamData called CamOutput........................................ 22
Figure 16: SFC of the CamData FB............................................................................. 23
Figure 17: Trigger step .............................................................................................. 24
Figure 18: Scrreshot of the TCP/IP data using Hyperterminal .................................. 24
Figure 19 : Screenshot of the received array of bytes .............................................. 25
Figure 20 : Summary of all respected conditions in analyzing data ......................... 26
Figure 21 : Analyze step of the CamData FB ............................................................. 26
Figure 22 : An instance of the MC_Reset FB ............................................................. 27
Figure 23 : An instance of the RESET FB.................................................................... 27
Figure 24 : An instance of the ComaprePos FB ......................................................... 27
Figure 25 : ComparePos process, Units in degrees ................................................... 28
Figure 26 : Screenshot of the MAIN program ........................................................... 28
Figure 27: Ladder diagram of the Latch Program ..................................................... 29
Figure 28 : MC_POWER FB ........................................................................................ 30
Figure 29: CfgBuild3DGroup FB................................................................................. 30
Figure 30 : Operation principle of the "AxesPower" program.................................. 31
Figure 31 : Grafcet of the "Cycle" program............................................................... 32
Figure 32 : The Camera Step ..................................................................................... 33
Figure 33 : Ladder diagram of the "Pick" step .......................................................... 34
Figure 34 :Sketch of the axes and the throwing positions........................................ 35
Figure 35 : Throwing positions according to item's numbers ................................... 36
Figure 36 :"Throw"step diagram .............................................................................. 37
Figure 37 : Project Schedule...................................................................................... 39
Figure 38 : image of theelectrical panel.................................................................... 40
Figure 39 : image of the project in "Project LEbanon 2013" BIEL ............................. 41

Chapter I :
I.1-

Introduction

Project description:

The project consists of a Pick &Place 2D Robot which works following this scenario:

Small metallic items with different shapes and colors (Rectangles, Circles,
Black, and Grey) are supplied onto a moving conveyor/Belt System.
These items are checked by a specific camera which determines their
shape/color, XY position and then sends these data to the controller.
The robot picks the moving item from the calculated position using an
electromagnet and throws it to the specified position according to its
shape/color.

Figure 1: Sketch of the project

I.2-

About ITEC:

This project is developed in collaboration with Industrial Technologies S.A.L


Company (ITEC), which is located in Sin El Fil, Beirut, Lebanon.
ITEC was created with an aim to integrate emerging technologies in the
Automation and information industries. ITEC fundamental business strategy is
building long term business relationship, by matching each customers
requirements via assembling teams of experts with the knowledge and ability to
deliver superior results.
By the way, ITEC is an exclusive Beckhoff Automation distributor for Lebanon,
Jordan and Syria.
Concerning this project, its specifications were set in a dynamic way between the
company and the project supervisor at the university Dr. Noureddine Alameh.
ITEC provided all the hardware (Beckhoff) and software support in order to
accomplish tasks and finish the project.

Chapter II :

The Hardware

Synchronous Servomotor AM3112-0400-0001

Figure 2 : BeckHoff Servomotor

a) Appropriate use:
Synchronous servomotors of the AM3100 series are designed as drives for handling
equipment, textile machines, machine tools, packaging machines and similar
machines with demanding requirements in terms of dynamics. The servomotors
from the AM3100 series are exclusively designed for installation as components in
electrical systems or machines and may only be operated as integrated
components of the system or machine.

b) Product identification:
(i) Nameplate:

Figure 3 : Motors nameplate elements definition

10

Type
S.N.

AM 3112-0400-0001
Confidential
T.:
Sep-12

I0
M0

3.4 Arms
0.32 Nm

Nn
Nn

1500 rpm
3500 rpm

at 24 Vdc
at 48 Vdc

Pn

100 W

Isol.cl.

IP: 54

Figure 4 : Motors nameplate

c) Technical description of the motor:


(i) Design of the motor:
The synchronous servomotors of the AM3100 series are brushless three-phase
motors for demanding servo-applications. In conjunction with digital servo
terminal they are particularly suitable for positioning tasks in industrial robots,
machine tools, actuators
The servomotors are equipped with permanent magnets in the rotor. This
advanced neodymium magnetic material makes a significant contribution to the
motors' exceptional dynamic properties. A three-phase winding is housed in the
stator, and this is powered by the servo drive. The motor has no brushes, the
commutation being implemented electronically in the servo drive.
The motors normally have an integrated resolver to provide feedback. Beckhoff
servo drives analyze the resolver position of the rotor and supply the motors with
sine currents.
(ii) Selection Criteria:
The three-phase servomotors are designed for operation with servo terminals.
Both units together form a speed or torque control loop.
The main selection criteria are:
Standstill torque
M0 [Nm]
Rated speed at rated supply voltage
Nn [min-1]
Moment of inertia of motor and load
J [kgcm]
Effective torque (calculated)
Mrms [Nm]
The static load and the dynamic load (acceleration/braking) must be taken into
account in the calculation of the required motors and servo drives.
The selected motors described in this project have been proposed by ITEC.

11

II.2- The Servo drives EL7201:


a) Introduction:
The EL7201 servomotor EtherCAT Terminal, with integrated resolver interface,
offers high servo performance in a very compact design.
The fast control technology, based on field-oriented current and PI speed control,
supports fast and highly dynamic positioning tasks. The monitoring of numerous
parameters, such as overvoltage and under voltage, overcurrent, terminal
temperature or motor load offers maximum operational reliability.
The latest power semiconductors guarantee minimum power loss and enable
feedback into the DC link when braking. The LEDs indicate status, warning and
error messages as well as possibly active limitations.

Figure 5 : EL7201 connection diagram with the motor

12

b) Technology:
The servomotor is an electrical motor. Together with a servo amplifier, they form a
servo drive. The servomotor is operated in a closed control loop with position,
torque or speed control.
The servo terminal EL7201 supports control of permanent magnet synchronous
motors. These consist of 3 coils which are offset by 120 and a permanent magnet
rotor.

Figure 6: Servo Drive operation principle

Servomotors particularly demonstrate their advantages in highly dynamic and


precise positioning applications:

very high positioning accuracy in applications where maximum precision is


required through integrated position feedback
high efficiency and high acceleration capacity
Servomotors are overload-proof and therefore have far greater dynamics
than stepper motors, for example.
load-independent high torque right up to the higher speed ranges
maintenance requirements reduced to a minimum

II.3- The Controller CX-1020:


a) About the controller
With the CX series of Embedded PCs Beckhoff has combined PC technology and
modular I/O level to form a top-hat rail unit in the control cabinet. The CX1020
is equipped with a 1 GHz Intel(r) CPU. It is an energy-saving device that
13

operates with ultra-low core voltage and features low thermal power
dissipation.
As a top-hat rail and in conjunction with the TwinCAT software from Beckhoff, the
CX1020 offers the same functionality as large Industrial PCs. In terms of PLC, up to
four virtual IEC 61131 CPUs can be programmed with up to four tasks each, with a
minimum cycle time of 50 s. All IEC 61131-3 languages can be used. Moreover, all
TwinCAT functionalities are available for Motion Control applications:
In theory, up to 256 axes can be controlled. In addition to simple point-to-point
movements, more complex multi-axis functions such as "electronic gearbox", "cam
plates" and "flying saw" can be implemented. Due to its higher CPU performance
the CX1020 can now also execute interpolating 3D path movements and
DIN66025 programs. In addition to real-time execution of control tasks, the
TwinCAT real-time kernel ensures that enough time remains for the user interface
(HMI: Human Machine Interface), to communicate with the real-time components
via software interfaces.

b) Remote programming via Ethernet


The CX1020-0113 supplied by ITEC is equipped with Windows CE.NET. In this
case, the system is programmed via a laptop or a desktop PC, which is connected
to the CX1020 via Ethernet (crossover cable). The programs are developed on the
laptop with a standard TwinCAT software license and then loaded into the target
device.

II.4- Principle of operation of the servomotor:


a) Definition:
Permanent magnet AC (PMAC) motors do not rely entirely on current for
magnetization. Instead, magnets mounted on or embedded in the rotor couple
with the motors current induced, internal magnetic fields generated by electrical
input to the stator. More specifically, the rotor itself contains permanent magnets,
which are either surface-mounted to the rotor lamination stack or embedded
within the rotor laminations.
As in common AC induction motors, electrical power is supplied through the stator
windings. Permanent-magnet fields are, by definition, constant and not subject to
failure, except in extreme cases of magnet abuse and demagnetization by
overheating. PMAC, PM synchronous and brushless AC are synonymous terms.
Until recently, PMAC motors were available but not widely distributed; now these
motors are proliferating.

14

b) The Magnet:
Rare-earth elements are those 30 metals found in the periodic tables oft-omitted
long center two rows; theyre used in many modern applications. Magnets made of
rare-earth metals are particularly powerful alloys with crystalline structures that
have high magnetic anisotropy which means they readily align in one direction,
and resist it in others. Discovered in the 1940s and identified in 1966, rare-earth
magnets are One-third to two times more powerful than traditional ferrite
magnets generating fields up to 1.4 Tesla, in some cases. Their magnets are used
in permanent-magnet rotary and linear motors.

c) Principle of operation:
A PMAC (Permanent Magnet AC) motor has a sinusoidal distributed stator winding
to produce sinusoidal back-electromotive force (EMF) waveforms. Back EMF is
voltage that opposes the current that causes it. In fact, back EMF arises in any
electric motor when there is relative motion between the current-carrying
armature (whether rotor or stator) and the external magnetic field. As the rotor
spins (with or without power applied to the windings), the mechanical rotation
generates a voltage so, in effect, becomes a generator. Typical units are
(V/krpm) Volts/ (1,000 rpm).

Figure 7 : Principle and construction of a brushless Servo motor

15

Figure 8 : waveform for sinusoidal EMF style and square wave servo drives

Figures 7 and 8 show the construction and the principle of operation of the motor.
Back EMF is the voltage generated by rotating permanent magnet machine. As the
rotor spins (either with or without power applied to the stator windings) the
mechanical rotation generates a voltage in other words, becomes a generator.
The resultant voltage waveform from back EMF is either shaped like a sine wave
(AC) or a trapezoid (DC), depending on the power supply from the drive. In fact, the
major difference between PMAC and permanent magnet DC motors is that the
faster a PMACs rotor spins, the higher back-EMF voltage is generated.
PMAC-compatible drives (known as PM drives) substitute the more traditional
trapezoidal waveforms flat tops with a sinusoidal waveform that matches PMAC
back EMF more closely, so torque output is smoother. Each commutation of
phases must overlap, selectively firing more than one pair of power-switching
devices at a time. These motor-drive setups can be operated as open-loop systems
used in midrange performance applications requiring speed and torque control. In
this case, PMAC motors are placed under vector-type control.
In fact, though PMACs require a drive specifically designed to drive PM motors, the
PM drive setup is most similar to flux vector drives for AC induction motors, in that
the drive uses current-switching techniques to control motor torque and
simultaneously controls both torque and flux current via mathematically intensive
transformations between one coordinate system and another. These PM drives use
motor data and current measurements to calculate rotor position.

16

During every sampling interval, the three-phase AC system dependent on time


and speed is transformed into a rotating two-coordinate system in which every
current is expressed and controlled as the sum of two vectors.
In PMAC motors, speed is a function of frequency the same as it is with
induction motors. However, PMAC motors rotate at the same speed as the
magnetic field produced by the stator windings; it is a synchronous machine.
Therefore, if the field is rotating at 1,800 rpm, the rotor also turns at 1,800 rpm
and the higher the input frequency from the drive, the faster the motor rotates. A
permanent magnet AC (PMAC) motor is a synchronous motor, meaning that its
rotor spins at the same speed as the motors internal rotating magnetic field.

II.5- The Electromagnet:


The electromagnet is a simple coil taken from a 24 V relay.
The coils terminals are linked to the digital output module (EL2002):
When the Boolean variable linked to this output is True, the electromagnet
is on.
When the Boolean variable linked to this output is False, the electromagnet
is OFF.

II.6- The mechanical system:


The whole mechanical system was designed and implemented by Oubatec
company.
The linear motion is achieved using lead-screw system combined to linear guide
ways.

Figure 9 : Oubari's logo

17

Chapter III :

The Software

III.1- BeckHoff-TwinCAT:
a) Generalities about TwinCAT
The TwinCAT software system is a complete automation system for PC-compatible
computers, which is referred to as "The Windows Control and Automation
Technology". TwinCAT transforms every compatible PC into a real time control
with multi-PLC, NC axis control, a programming environment and a control station.
TwinCAT substitutes PLC (Programmable Logic Controller) and NC (Numerical
Control) controllers as well as control stations with:

open, compatible PC hardware,


programmed in accordance with the manufacturer-independent IEC611313 standard,
linking to all common field buses and PC interfaces for I/O signals,
embedding of PLC and NC systems in Windows NT,

TwinCAT unites the real time control capability with the open and world-wide
largest software platform of Microsoft's Windows operating systems.
TwinCAT embraces a large number of system components which, together,
constitute a complete solution for automation tasks:

Programming of PLC programs for sequential logic in conformity with


IEC61131-3.
Programming of NC point-to-point (PTP) and interpolation (I) positioning in
conformity with DIN66025.
Real time system for the execution of PLC and NC programs in an exactly
timed (deterministic) fashion, regardless of how the PC is used for further
tasks.
I/O linking for all widespread field buses and the PC interfaces and also for
third-party interface cards.

Any TwinCAT software is composed of two 2 types of windows:

TwinCAT PLC where the user creates its own software using available
programming languages and functions.
TwinCAT System Manager: it is the central configuration tool of the
TwinCAT System. It is where the inputs and outputs of the software tasks
and the physical inputs and outputs of the connected fieldbuses are
18

managed. The I/O information of the PLC Software Tasks is read from and
entered in the TwinCAT System Manager. From there, the installed
fieldbuses and their connected modules/boxes are also described. The
logical and physical inputs and outputs are assigned to one another by
linking software task variables and fieldbus variables.

b) TwinCAT NCI (numerical control interpolation):


The TwinCAT NC Interpolation (NC I) is the NC system for interpolated path
movements. TwinCAT NC I offers 3-D interpolation (interpreter, set point
generation, position controller), an integrated PLC with an NC interface and an I/O
connection for axes via the fieldbus. All well-known Fieldbus systems and
programming standards in the CNC world, such as DIN 66025 (G code), are
supported. TwinCAT NC I deliver open PC solutions for standard axial components
and CNC controls. TwinCAT NC I uses the power of the PC (calculation) and allows
axis regulation under Windows NT/2000/XP/Vista/CE. Hardware modules are
simulated in the software, and are thus superfluous.
The following geometries are supported by the interpreter:

a straight line in space will be used in the project


circles in all main planes
circles in space
helices with base circles in the main planes

The main purpose of using NCI in the project is that the 2 axes move at the same
time and arrive to their destinations (even if they are different) instantaneously
which shows the 2D robot more flexible. The CX1020 controller can perform such
calculations and feed the servo drive with the necessary orders to move the
motors and stop them exactly on the desired positions.

III.2- Creation of the project function blocks:


In the software, there was a need to create special function blocks in order to
simplify the process.
Each function block has its own inputs, outputs and internal variables. They can be
called several times in the entire software under different names.

a) MoveToPos Function block:


This function block (FB) will be used later to move the 2 axes to any (X, Y) position.
It takes the desired coordinates, velocity (in degrees/s which maximal value is

19

9000) and a bExecute Boolean variable (to enable the motors to run) as inputs and
generates one Boolean output:

bDone: to identify that the motion is done.

Figure 10 : An instance of MoveToPos FB called GoHome

This function block is a combination of many other sub functions already defined in
TwinCAT libraries that will be described in the following paragraphs. Every time
MoveToPos is called, the sub functions are called in the following order:
(i) NciFeedTablePreparation:

Figure 11 : NciFeedTablePreparation FB

This function block appends an entry of a specified type to a defined structure


called feed group table. One appended entry can generally create more than one
row in the table. In this project, a table with only one row has been chosen. In the
following paragraphs, the term table must be understood as a one row.
The variable E_NCiEntryType is an integer that defines the geometrical type of the
trajectory. In this project, it is assigned the value 2 which is related to a straight
line for each axis.
The variable pEntry is a pointer to another variable: ST_NciGeoline that describes a
straight line with a specified velocity. (ST_Geoline is chosen out of many types like
circles, Helicoids).
These data are delivered to stFeedGroupTable that holds the rows for the NCkernel.
The ST_NciGeoline is a structure that takes X, Y, Z positions and Velocity.

20

(ii) NciFeedTable:

Figure 12: NCIFeedTable FB

The function block FB_NciFeedTable feeds a given table to the NC-kernel. After
feeding is completed, bFeedingDone becomes true. bChannelDone signals the
complete execution in the NC-kernel of the motion.
The variable bDone of the MoveToPos function block is linked to the variable
bChannelDone to indicate the end of motion.
The variables px, py, pz and velo of MoveToPos are linked to the X, Y, Z and
velocity variables of the structure St_Geoline.
The variable bExecute of MoveToPos is linked to all bEnable and bExecute
variables of all the used sub function of MoveToPos.
The variable bError of MoveToPos is linked to all the bError variables of all the
used sub functions of MOVETOPOS.
Now this function block is ready to move the axes based on the NCI benefits: the
axes arrive simultaneously to their targets. It was created using the Structured
Text programming language.

b) Trigger function block:


This function block generates a desired number of pulses on its output timerQ
separated by the desired time interval.
Later on in this project, the creation of this function block will be justified. It was
programmed using the Ladder diagram language.

Figure 13 :An instance of Trigger FB Called Trig

21

Figure 14: Ladder diagram Trigger

A counter (CTU: Counter up) is related to a timer (TON) in the following manner:
When Start is True, the counter counts the first time and its internal
variable M which is linked to the input of the timer generates one pulse.
This pulse starts the timer for the desired time and at the moment the
counter is waiting because its input depends on the Q output of the timer
which is FALSE when the timer is on.
Once the timer finishes one cycle, the counter counts up for one time
(because the output Q of the timer turns TRUE) and the process is repeated
until the counted value (CV) reaches the counter limit (PV) where the
TrigDone output turns TRUE.

c) CamData function block:


This function block is used to receive data from the camera sensor using
TCP/IP connection and analyze its content to determine the shape, color,
and position of the item. The programming language used here is the
Sequential Function Chart language (SFC) also known as Grafcet.
This language is based on steps (actions) and transitions (conditions to
move from one action to another). Every action can be programmed using
any one of the IEC3113 languages.

Figure 15: An instance of FB CamData called


CamOutput

22

This function block takes an execute Boolean input and returns many
outputs:
Rec : turns True if the shape is rectangle
Cir: turns True if the shape is a circle
W: turns True if the color is white
B: turns True if the color is black
Xcam : the X position of the item when detected by the camera
sensor
Ycam: the Y position of the item when detected by the camera
sensor
GrayVal : the grayscale value of the item
Found: a Boolean output indicating that an item was detected by
the camera
The Sequential Function Chart (SFC) of this function block is composed of the
following steps as shown in the figure 16:
(i) Init:
An initialization phase where all Boolean output variables (Rec, Cir, W and B) are
RESET to False.

Figure 16: SFC of the CamData FB

23

The figure 17 represents the action performed in the Trigger Step:

Figure 17: Trigger step

The Trig instance of the Trigger function block generates 10 pulses 10 milliseconds
separated from each other.
These pulses trig the receive function block (already found in the Twincat TCP/IP
server library) as it is shown in the figure. The received data are stored in an array
of bytes in a sequence but in random positions in the array.
Before trigging the receive function block, the connect one is used to establish
the connection and generate a special hand shake variable called hsocket. This
block takes the IP address and the port number of the camera as inputs.
Each time the controller enters this step, data are delivered from the camera to the
array. Thus, the transition to the next step is related to the TrigDone output
variable of the Trigger Function Block.
(ii) Analyze:
The received data are in a sequence starting by the character a and ending with
the character b as it was programmed in the camera software. The received
sequence shown in the figure 18.

Figure 18: Scrreshot of the TCP/IP data using Hyperterminal

24

This sequence can be read in the following order:


B, 1 : a part is found ( if it was 0 means that no item was detected)
(X , Y ) position of the item
AREA (in this example 3127 ) : it is the area of the item, this parameter
leads us to determine the shape according to the area of the item
G, 18: the grayscale value that leads us to determine the color.
Unfortunately, these data are received in the following form:

Figure 19 : Screenshot of the received array of bytes

Each byte was transformed using the ASCII code:


The data are placed in sequence but randomly in the array
Sometimes X is a 2 digits number and sometimes it is a 3 digits number
(same for Y)
Sometimes X has 2 numbers after its decimal point and sometimes 1 (same
for Y)
Taking into account all these conditions, around 12 IF, ELSE complicated
instructions were used to analyze the data without any error.
These instructions were written in the ST (structured text language) and can be
found in the cd attached to the report.
The following figure illustrates all the conditions that were taken into account:

25

Figure 20 : Summary of all respected conditions in analyzing data

Now all the data (X, Y, Grayscale value and the Area of the detected item) are
available, the following figure will summarize how the decision is taken:
Receive Data from
the Camera

Analyze Data in the


Received Array

NO

Item Detected

YES

Get GrayScale and


AREA

AREA <= 4800

YES

GrayVal <=30

NO
YES

Rec:=TRUE
(Rectangle)

NO

Cir:=TRUE
(Circle)
B:=TRUE
(Black)

W:=TRUE
(White)

Figure 21 : Analyze step of the CamData FB

(iii)Intermediate step:
If the camera detects any item, this step makes sure to reset all the outputs (Rec,
Cir, W, B, and Found) to avoid data from remaining the same next time the
CamData FB is called.

26

d) Reset function block:


This function block is used to reset the axes and the group errors.
It is based on the reset function MC_RESET already found in the Twincat MC
Library (motion control) which is called for three times, each time for an axis.

Figure 22 : An instance of the MC_Reset FB

Figure 23 : An instance of the RESET FB

The figure 22 shows an instance of the Reset function block called ResetAxes,
when all axes are reset; the output bit bResetDone becomes TRUE.

e) ComparePos function block:


This function block is related to the MoveToPos function block. It is used to make
sure that the robot has arrived to its X and Y destinations.

Figure 24 : An instance of the ComaprePos FB

The Actual X and Y values are situated in the global variables XNCtoPLC and
YNCtoPLC that are structures including all feedback data from the servo motors to
the PLC.
The following figure shows how this function block works:

27

NO
|ActualX DesiredX|

|ActualY DesiredY|

NO

<1

<1

YES

AND

YES

EqualTrue

Figure 25 : ComparePos process, Units in degrees

III.3- The Software:


When all the tools are ready, the software can be built using the blocks created or
using predefined blocks from Twincat rich libraries.
The Main function executed by the processor calls many programs to run
simultaneously:

Figure 26 : Screenshot of the MAIN program

These programs have a direct access to the global variables.


28

a) Latch Program:
This program aims to organize the operation of the software when we need to
start or to stop it. Because time was not sufficient, the HMI (Human Machine
Interface) created was not able to be implemented on a screen in Project
Lebanon, so a switch was used to start up and stop the software.
This switch is linked to the global variable bSwitch and to the digital input
module EL1002.
To start the software, a rising edge of the variable bSwitch (turning on) is detected;
it sets the bStartLatch bit and resets the bStopLatch bit. Otherwise, a falling
edge of the variable bSwitch (turning off) is detected; it resets the bStartLatch bit
and sets the bStopLatch bit.
Because the servo motors are equipped with resolvers, every time the system is
shut down, the servo loses its position so we need to set its actual position on the
next startup to (0, 0) respecting the condition that before stopping the system, the
robot must be homed. This action will be implemented in the next steps.
The MC_SetActualPosition function block of the MC (Motion Control library) is
used to set the actual position. The following figure shows the Ladder Diagram of
this program:

Figure 27: Ladder diagram of the Latch Program

29

b) AxesPower Program:
(i) MC_POWER function block:
This function block is used to power the axis, enabling positive and negative
running directions.
The input variable AxisRefIn of type NC_TO_PLC Axis Interface presents the actual
status of the axis including many values (e.g. Axis Status, actual position, actual
velocity, Axis Id).These variables could be considered as feedback variables from
the axis to the PLC. The input variable AxisRefOut of type PLC_TO_NC Axis
Interface includes all variables imposed by the PLC on the axis (external set
position, acceleration, velocity.). This function block is used 3 times to power the
3 axes X, Y and Z. Only 2 motors are present but an interpolation channel needs 3
axes to be appended, so a fictive axis Z is appended which will not be linked to any
hardware.
The output bit Status turns TRUE when the axis is powered, now each axis is ready
to move in Point To Point mode independently from others.

Figure 28 : MC_POWER FB

(ii) CfgBuild3Dgroup function block:


This block configures a 3D interpolation group with up to 3 Point To Point axes (X, Y
and Z). The Ids of the PTP axes are supplied to the inputs nXAxisId, nYAxisId and
nZAxisId. nGroupId represents the ID of the 3D group. The command is executed at
a rising edge on the input bExecute.
The output bErr goes TRUE if an error occurs as the command is being executed.
The command-specific error code is contained in nErrId.

Figure 29: CfgBuild3DGroup FB

30

(iii) AxesPower Operation principle:


The AxesPower program is written using the Structured Text programming
language, but it is illustrated using the CFC (Continuous Function Chart) language in
the following figure.

Figure 30 : Operation principle of the "AxesPower" program

As it is shown in the figure, once all axes are powered (bAllAxesReady is TRUE), an
interpolation group can be built and a feedback negation of this variable is linked
to the input to make sure that axes are powered once without error.
When the interpolation group is built without errors, the MoveToPos function
block already created can be used successfully for several times.

c) The Cycle Program:


This program represents the whole cycle followed by the robot from detecting
items to throwing them.
The Sequential Function chart (Grafcet) Programming language was chosen
because it suits the algorithm used along this program. The following figure shows
the cycle program:
31

INIT
bStopLatch
bStartLatch
Home2

Camera

bStopLatch

Home1

Rec OR C

Pick

ComparePosHome.EqualTRUE
INIT

ComparePickSure.EqualTRUE

Inter1
NOT CamOutput.exec

Throw
bStopLatch

Home2

CompareThrow1.EqualTRUE AND NOT bStopLatch

ComparePosHome.EqualTRUE

Inter2
NOT (Rec OR C)

INIT

Figure 31 : Grafcet of the "Cycle" program

32

(i) INIT step:


In this step, an instance of the Reset function block is called to remove any
probable axis error.
(ii) Camera step:
When the Boolean variable bstartLatch is true (the switch is turned on), the system
passes from the INIT step to the Camera step.
In this step, an instance of the CamData function block named CamOutput is
called to receive data from the camera and analyze its content. All output data
from this function block are linked to global variables in order to be able to deal
with them by other steps.
The global variable called Magnet that is related to the digital output of the
module EL2002 is Reset to FALSE in this step to make sure that the robot doesnt
catch any item when the camera is detecting.

Figure 32 : The Camera Step

Whenever the camera detects any item, one of the global variables Rec or C
becomes TRUE and the system then passes to the next step.
(iii) Pick step:
In this step, the following actions are achieved:
1. Move to the calculated X position according to the data from the camera
(CamOutput.Xcam) taking into consideration that the X value delivered by
the camera must be transformed to become suitable with the robots
coordinate system. The Y position is chosen constant (Y3 check figure 34).
33

GoPickOrder function block of the following figure, Network 0001.


2.

When the robot arrives to the calculated X, turn ON the electromagnet


ComparePickOrder1 function block of the following figure, Network
0002.

3. When the robot arrives to the (calculated X, Y3) position, move to the
(calculated X, Y3 +10000) position (unit in degrees) to make sure to catch
the item.
ComparePickOrder and PickSure function blocks of the following figure,
Networks 0003 and 0004.
4. When the robot arrives to the (calculated X, Y3 +10000) position, move to
the next step.
ComparePickSure function block of the following figure, Network 0005.

Figure 33 : Ladder diagram of the "Pick" step

34

(iv) Inter1 step:


In this intermediate step, all the MoveToPos and counters function blocks of the
Pick and Throw steps are called but with their bExecute inputs = FALSE to make
sure they are not still working.
Moreover, the Camoutput function block is called (with bExecute=FALSE) to
prevent the camera from receiving data when the robot is picking and throwing.
(v) Throw step:
In this step, the robot must decide where to throw the item according to its shape
and color taking into account the number of similar items already arranged and
respecting the order shown in the next figure.

Figure 34 :Sketch of the axes and the throwing positions

The robot counts the number of existing items of every type using the UP counter
function block CTU) from the Twincat standard library, every time the counter
value becomes 6, the value is reset to 0 (counter is reset). If we take for example
the black circles, when the number of black circles is 1 (BCnb=1), the robot throws
the item in the (x1, y6) position and when BRnb=6 then (Xthrow, Ythrow) = (x3,y5).
The robot throws from the most far position to the nearest one to prevent the
electromagnet (that is ON when the robot is throwing) to attract the already sorted
items.
This algorithm was applied using the Case structure of the structured text
language.

35

Figure 35 : Throwing positions according to item's numbers

When the robot arrives to the (Xthrow,Ythrow) position


(CompareThrow.EqualTrue), the software moves to the next intermediate action
Inter2 where all the function blocks used in the Throw action (Counters ,
MoveToPos, ComparePos) are called with their bExecute inputs are False to make
sure they are no more active.

36

BR= Rec AND B


BC= C AND B
WR=Rec AND W
WC=C AND W

BR=TRUE

YES

WR=TRUE

YES

YES

WCnb=WCnb+1

WRnb=WRnb+1

WCnb=6

WRnb=6

YES

YES

WCnb=0

WRnb=0

YES

BRnb =BRnb+1

BRnb=6

BCnb=BCnb+1

BCnb=6

YES

YES

BRnb=0
Reset Counter

(Xthrow,Ythrow)
according to BRnb

WC=TRUE

BC=TRUE

BCnb=0

(Xthrow,Ythrow)
according to BCnb

(Xthrow,Ythrow)
according to WCnb

(Xthrow,Ythrow)
according to WRnb

Go Throw to
(Xthrow,Ythrow)

Figure 36 :"Throw"step diagram

37

(vi) Home1 and Home2 Steps:


When the bSwitch is turned off, the bStopLatch becomes TRUE and the robot
must stop and return to its home position.
For these reasons, parallel branches like Home1 and Home2 were added in
different positions in the Sequential Function Chart to make sure that the robot
returns home whenever the switch is turned off.
But if the robot was moving and this switch was turned off, the robot continues its
action and then returns home.

d) TorqueLim Program:
This program is used to set the value of a variable called torque limitation related
to some hardware issues.
Sometimes this value is set to 0 and the robot doesnt move. Thus, this program
resets the variable to its normal value (32767) whenever it changes to 0.

38

Chapter IV :

Conclusion

IV.1- Achieved Objectives:

Learn NCI (numerical control by interpolation) programming using


TWINCAT
Respect the deadlines before 4-June-2013 date of Project LEBANON
2013
Learn how to communicate and deal with other companies
Learn how to lead a workgroup and assign tasks
Assembly of the of the panel from A to Z
Use of 4 IEC3113 languages: ST (Structured text), LD (ladder diagram) ,
SFC(sequential function chart), CFC (continuous function chart)

IV.2- Forecast objectives

To let the robot Pick more than one item Time was not sufficient
especially because of the delay to deliver the mechanical system & some
problems with the camera software.
To let the robot synchronize with the conveyor motor and the magnet turns
ON only when it is right up of the item still need more appropriate
sensor and sufficient time

IV.3- Interesting Statistics:

Figure 37 : Project Schedule

This figure represents the Project Schedule that was followed step by step.
39

3 visits to Oubaris Workshop in Zahle where the mechanical system was


implemented
10 meetings with the Supervisor
More than 90 working days from 8:00 to 6:00

IV.4- References:

http://infosys.beckhoff.com/index_en.htm ; This reference includes all


relevant data about the hardware and the software.

www.leeson.com/documents/.../PMAC_Whitepaper.pdf

The projects Software and Twincat will be attached to this report

IV.5- APPENDIX

Figure 38 : image of theelectrical panel

40

The figure 38 shows the panel board of the project including:


From the top left of the upper rail : Siemens 24 V power supply , camera
driver
From the top left of the lower rail : 2 fuse (one for 220 V and the other for
24 V ), BeckHoff Controller CX1020 with its connected modules (1 digital
input EL1002, 1 digital output EL2002, 2 EL7201 Servo Drive modules)

Figure 39 : image of the project in "Project LEbanon 2013" BIEL

41

S-ar putea să vă placă și