You are on page 1of 20

Contenido

Problematic.......................................................................................................................................... 3
General objectives...............................................................................................................................3
Specific objectives.............................................................................................................................. 3
Theorical Framework (sockets)..........................................................................................................4
What is a socket?...............................................................................................................................4
Stream socket.................................................................................................................................... 4
Applications development.................................................................................................................. 5
C# Code............................................................................................................................................. 5
Class “modelos”...........................................................................................................................5
Class “threadsclass” and “threadsclass m_2”.........................................................................6
Main Form Code........................................................................................................................... 7
UR3 robot code.................................................................................................................................. 10
Before Start...................................................................................................................................... 10
Robot Server Connection.................................................................................................................10
Thread.............................................................................................................................................. 10
Subroutine “Modelo_1” & “Modelo_2”..............................................................................................11
Subroutine “Subprueba_1” & “Subprueba_2”.................................................................................. 11
Robot program................................................................................................................................. 11
Flow diagrams................................................................................................................................... 14
C# Flow Diagram............................................................................................................................. 14
Polyscope Flow Diagram................................................................................................................. 16
UR3 polyscope code........................................................................................................................ 17
Conclutions........................................................................................................................................ 21
PROBLEMATIC
The board testing in an electronic area requires an automation in its process to perform the tasks
in less time than the normal time. The PCB station counts with two charge sockets and also to
discharge sockets for pass/fail samples (this station can handle two different models only). The
current station requires another process before it, to be able to assign a serial number to the
samples.

GENERAL OBJECTIVES
 Automate the PCB station controlling UR3 with sockets application developed in C#.
 Threads will be used to reduce the time that is not related with testing the samples.

SPECIFIC OBJECTIVES
 Implement a socket client/server application using C# to communicate between the application
and the UR3 cobot.
 Develop in the same app a method to give a serial number to the sample depending on the
model of the sample.
 Robot must print messages received from server such as “Test started” or “pass/fail”.
THEORICAL FRAMEWORK (SOCKETS)
What is a socket?
A socket is one endpoint of a two-way communication link between two programs running on the
network. The socket mechanism provides a means of inter-process communication (IPC) by
establishing named contact points between which the communication take place.
Sockets are generally employed in client server applications. The server creates a socket, attaches it
to a network port address then waits for the client to contact it. The client creates a socket and then
attempts to connect to the server socket. When the connection is established, transfer of data takes
place. In Figure 1 is a representation of a socket:

Figure 1. Sockets representation

Stream socket
In Computer operating system, a stream socket is type of inter-process communications socket or
network socket which provides a connection-oriented, sequenced, and unique flow of data without
record boundaries with well-defined mechanisms for creating and destroying connections and for
detecting errors. It is similar to phone. A connection is established between the phones (two ends)
and a conversation (transfer of data) takes place. In figure 2 there is a graphic explanation of a
server/client application:

Figure 2. Server/Client application protocol


APPLICATIONS DEVELOPMENT
C# Code

CLASS “MODELOS”

This class contains the methods required to generate the serial number for the two models
available to the board station. Also, this class contains methods that generates tests randomly to
simulate the station with the robot and determines if the sample pass or fail (Pass/Fail criteria). Class
is shown below in figure 3:

Figure 3. Class “modelos”


CLASS “THREADSCLASS” AND “THREADSCLASS M_2”

Each of this class is a thread (classes are shown in figure 4 and 5) and they will start to execute
when the test start running for each part number. Each thread is adding one by one, the limit is
defined by testing time required. On this case, the testing time is 10 seconds for each part number.

Figure 4. Class “ThreadClass”

Figure 5. Class “ThreadClass M_2”


MAIN FORM CODE

In the form is declared a global variable that is called by the server that provides from
SimpleTcpServer. This is used to create the socket indispensable to communicate with the robot.
Before entering the main code there are declared the objects that are called from the classes
mentioned before.
There are two variables to know if the samples passed the test (it applies for the two models).
Also, another variable is used to send the model to the UR3 and, another two variables to get the
state of each model during the test process.
When the form is initialized, the form creates the object “server” and then, it creates the method
that allows to receive data from the robot. This method contains a switch case to perform different
task; tasks are listed below respectively:

 “Mod1” & “Mod2”: Invokes “Modelo1” from the class called “Modelos” and the serial number
obtained for “modelo 1” will be assigned to variable “mode”. Then, server will send the serial
number to the robot with the command e.ReplyLine(string.Format(“message sent”)). This
will be printed in a label located in the main form.
 “Nido 1” & “Nido 2”: Depending on what fixture is located the board by the cobot. The state of
the sample will change to test in progress. This string will be printed on the main form.
“ThreadsClass” and “Modelos” will be executing during this process (See first two parts of C#
code from this document for details).
 “Paso 1?” & “Paso 2?”: This case has a condition if in which “pasoNopaso” is equal to “s” or “n”
and this data is sent to the robot. Otherwise, the server will send an empty space, and this
means that the test is not done yet.
 “Estado 1” & “Estado 2”: The robot Will send data to the server with the model’s state. The
different states are “pieza en prueba”, “vacio” and “listo, prueba terminada”. It counts with a
condition that restricts any unwanted data in the cobot.
 “Fin de prueba 1” & “Fin de prueba 2”: This case empties the state variables to start the whole
process again.
The switch case explained above is shown below in figure 6,7 and 8.
Figure 6. Switch case UR3 commands Part 1.

Figure 7. Switch case UR3 commands Part 2.


Figure 8. Switch case UR3 commands Part 3.
UR3 ROBOT CODE
Before Start
Into BeforeStart is located a home position and the whole variables required to develop this
project. Variables and their use are listed below with their description:
 “Conexion”: When this variable status is false, it means that there is no connection.
Otherwise, if it is true, it means that connection has been established.
 “prueba_1” & “prueba_2”: Displays test status and gets the pass/fail criteria.
 “ESTADO_M1” & “ESTADO_M2”: Displays test socket status for each model in real time.
 “Mod_1” & “Mod_2”: Verifies which model is the robot taking to the test area.
 “Nido_1” & “Nido_2”: Gets the serial number of a unit under test.
 “bandera”: Synchronize the data sent between client and the server. It is a flag.
 “Count_1” & “Count_2”: Makes an addition starting from zero to two. This represents the
number of tries performed by the robot.

Robot Server Connection


In the main code compartment is located a loop that while the connection is false, it will execute a
script that contains a function to connect the client to the server socket. The function structure is
“Open(Ip,Port, socket name)”. This function throws a true in case a connection is made. This loop will
break when it turns true. While this function is executing, the program will be asking for the sockets
status.

Thread
The thread is running during the whole execution of the program and its function consist on
request the status of the sockets and when the flag is equal to one it will execute a script that sends a
message to the server to the server (message: “estado1”); function is structure is
“socket_send_string(“Message”,socket name)”. Once the server reads the message it will
immediately answer with the socket status. Also, the answer is read with “socket_read_string(Socket
name)”. During the develop of this project an issue shown frequently was a space sent by the server
so, an action performed as a solution was a substring to delete it.
Subroutine “Modelo_1” & “Modelo_2”
It contains an if to confirm that robot received a serial number that corresponds to an specific
model. It asks if “Mod_1” or “Mod_2” are equal to “M1” or “M2”. If this statement is true, the robot will
perform three tries to take a sample and if it does not have a piece by try number three, a popup will
show and also, the popup will ask to continue or if user wants to stop the program. In case that robot
takes a sample, the robot will bring it to the socket it belongs. While sample is testing area the robot
will go and take the next sample to the pass/fail area or, it will bring another sample to the testing
area.

Subroutine “Subprueba_1” & “Subprueba_2”


When samples get placed in the test area by the robot, it will get under test. The first thing that
this subroutine does is to change the value of the flag to 0 and then it sends a message to the server
asking if the sample passed the test; the server will answer with the pass or fail represented in the
main program as an “s” or a “n”. The pass/fail criteria will define the final location of each sample and
when the test is done, robot will send a message indicating that the test is done. After this, the
process will repeat for more samples.

Robot program
It contains several if conditions asking for the sockets status and for each model in case the
socket is empty or in this project language “vacio”; this will call subroutine “Modelo_1” or “Modelo_2”
it depends of the model. When the flag turns into 0 the robot will send a message to the server and
the server answer contains the serial number referring to its corresponding model. A substring is
performed to the serial number so the robot can know the difference between both models (Note:
Model 1 serial number starts with M1 and M2 is for model 2). When the serial number is known, the
flag changes its value to 1. This process also applies for model 2. When the test is done for any
sample model, the server will display a label with an string that says “listo”.

Below is show a list of figures as evidence of the code explanation:


Figure 9. Charge compartment. (left is model 1 and right is model 2).

Figure 10. Test area. (Left is model 2 and right sample is model 1).
Figure 11. Pass/Fail compartment. (Left space is Model 1 pass, middle space is for any model scrap and in the right side,
is Model 2 pass).

Figure 10. Charge station empty. Robot will perform 3 trials before proceeding.
FLOW DIAGRAMS
C# Flow Diagram
Polyscope Flow Diagram
UR3 polyscope code
Program
BeforeStart
MoveL
home
Missing: Gripper
conexion≔ False
prueba_1≔" "
prueba_2≔" "
ESTADO_M1≔""
ESTADO_M2≔""
Mod_1≔""
Mod_2≔""
nido_1≔""
nido_2≔""
bandera≔1
hilo_2≔"1"
hilo_3≔"1"
count_1≔0
count_2≔0
Robot Program
Loop conexion≟ False
Script: conexion.script_bak
Wait: 0.2
Wait: 2.0
If ESTADO_M1≟"vacio"
Call Modelo_1
If ESTADO_M2≟"vacio"
Call Modelo_2
If ESTADO_M1≟"listo"
Call Sub_prueba_1
If ESTADO_M2≟"listo"
Call Sub_prueba_2
Thread_1
Pide_estados
If bandera≟1
socket_send_string("estado1","cliente")
Script: ESTADO_M1.script_bak
Wait: 1.0
socket_send_string("estado2","cliente")
Script: ESTADO_M2.script
Else
Wait: 0.1
Modelo_1
Script: bandera_0.script_bak
Wait: 1.0
socket_send_string("Mod1","cliente")
Wait: 0.1
Script: Mod_1.script_bak
Wait: 0.1
Script: bandera_1.script_bak
Wait: 0.1
If Mod_1≟"M1"
MoveL
Waypoint_1
Loop count_1≤2 and rq_is_object_detected()≟ False
MoveJ
Missing: Gripper
Waypoint_2
Missing: Gripper
Waypoint_1
count_1≔count_1+1
If count_1>2 and rq_is_object_detected()≟ False
Popup: No pudo tomarse modelo 1
If rq_is_object_detected()≟ True
MoveJ
Waypoint_7
Waypoint_8
Missing: Gripper
home
Script: bandera_0.script_bak
Wait: 0.1
socket_send_string("nido 1 cargado","cliente")
Wait: 0.5
Script: bandera_1.script_bak
Modelo_2
Script: bandera_0.script
Wait: 1.0
socket_send_string("Mod2","cliente")
Wait: 0.1
Script: Mod_2.script
Wait: 1.0
Script: bandera_1.script
Wait: 1.0
If Mod_2≟"M2"
MoveL
Waypoint_4
Loop count_2≤2 and rq_is_object_detected()≟ False
Missing: Gripper
MoveJ
Waypoint_5
Missing: Gripper
Waypoint_4
count_2≔count_2+1
If count_2>2 and rq_is_object_detected()≟ False
Popup: No pudo tomarse modelo 2
If rq_is_object_detected()≟ True
MoveJ
Waypoint_6
Waypoint_3
Missing: Gripper
home
Script: bandera_0.script_bak
Wait: 0.5
socket_send_string("nido 2 cargado","cliente")
Wait: 0.5
Script: bandera_1.script_bak
Wait: 1.0
'Thread_2'
'Thread_3'
Sub_prueba_1
Script: bandera_0.script_bak
Wait: 0.5
socket_send_string("paso 1?","cliente")
Wait: 0.1
Script: prueba1_S_N.script
Wait: 0.5
Script: bandera_1.script_bak
If prueba_1≟"s"
Si_pasa_1
MoveL
Waypoint_14
Waypoint_9
Missing: Gripper
Waypoint_14
Waypoint_15
Waypoint_16
Missing: Gripper
Waypoint_15
home
Script: prueba_1_clean.script
Script: bandera_0.script
socket_send_string("fin de prueba 1","cliente")
Wait: 0.1
Script: bandera_1.script_bak
ElseIf prueba_1≟"n"
No_pasa_1
MoveL
Waypoint_14
Waypoint_9
Missing: Gripper
Waypoint_14
Waypoint_17
Waypoint_18
Missing: Gripper
Waypoint_17
home
Script: prueba_1_clean.script_bak
Script: bandera_0.script
socket_send_string("fin de prueba 1","cliente")
Wait: 0.1
Script: bandera_1.script_bak
Sub_prueba_2
Script: bandera_0.script_bak
Wait: 0.5
socket_send_string("paso 2?","cliente")
Wait: 0.1
Script: prueba2_S_N.script
Wait: 0.5
Script: bandera_1.script
If prueba_2≟"s"
Si_pasa_2
MoveL
Waypoint_6
Waypoint_19
Missing: Gripper
Waypoint_6
Waypoint_12
Waypoint_13
Missing: Gripper
Waypoint_12
home
Script: prueba_2_clean.script
Script: bandera_0.script_bak
socket_send_string("fin de prueba 2","cliente")
Wait: 0.1
Script: bandera_1.script
ElseIf prueba_2≟"n"
No_pasa_2
MoveL
Waypoint_6
Waypoint_20
Missing: Gripper
Waypoint_6
Waypoint_17
Waypoint_18
Missing: Gripper
Waypoint_17
home
Script: prueba_2_clean.script_bak
Script: bandera_0.script_bak
socket_send_string("fin de prueba 2","cliente")
Wait: 0.1
Script: bandera_1.script_bak
CONCLUTIONS
Threads minimize the context switching time; the use of threads provides concurrency within a
process and an efficient communication. It is more economical to create and context switch threads.
Performing a program using threads can minimize time of operation almost to its limit but, it requires
another tool. In this project the results were efficient enough because, the communication between
C# and UR polyscope allowed a clear communication. Also, subroutines are required so the code can
be clear in the robot program structure.

You might also like