El controlador KUKA youBot
Abstract
Vilnius Gediminas Technical University. Faculty of Electronics. Department of Electrical Engineering
Full text
UNIVERSIDAD DE VALLADOLID ESCUELA DE INGENIERIAS INDUSTRIALES Grado en Ingeniería Electrónica Industrial y Automática El controlador KUKA youBot Autor: Justo Lobato, Alberto Valladolid, Junio 2019. Responsable de Intercambio en la UVa Herráez Sánchez, Marta Universidad de destino Vilnius Gediminas Technical University
2 e TFG REALIZADO EN PROGRAMA DE INTERCAMBIO TÍTULO: The KUKA youBot controller ALUMNO: Alberto Justo Lobato FECHA: 05/06/2019 CENTRO: Electronics Faculty. Vilnius Gediminas Technical University TUTOR: Dainius Udris Cinco palabras claves que describen el TFG: Robótica, Morfología, PCB, ROS, Octave Abstract en español (máximo 150 palabras): En nuestros días, muchas placas base y PCBs presentan fallos debido al fin de su vida útil o a errores en el proceso de producción. En muchos de estos casos, su clasificación se realiza mediante operaciones manuales, llevando a los empleados a una posible exposición frente a elementos tóxicos. Debido a este motivo, en este proyecto se propone detectar dichos fallos con el procesamiento de imágenes tomadas por una cámara Siemens MV440 mediante el programa GNU Octave, así como la clasificación de las mismas gracias a la programación de un robotbrazo KUKA youBot dentro del entorno Linux conocido Robot Operating System o ROS. Previa a la programación de dicho robot, se simulará su comportamiento dentro del programa Gazebo.
[ESK-17-5.1EN] 3 VILNIUS GEDIMINAS TECHNICAL UNIVERSITY FACULTY OF ELECTRONICS DEPARTMENT OF ELECTRICAL ENGINEERING Alberto Justo Lobato THE KUKA YOUBOT CONTROLLER KUKA YOUBOT ROBOTO VALDIKLIS Bachelor Thesis Automation study programme, State Code 612H62002 Automatic Control of Technologies specialization Electrical Engineering Study Area Vilnius, 2019
4 e
2 e Alberto Justo The KUKA youBot controller. Bachelor Thesis for degree. Vilnius Gediminas Technical University. Vilnius, 2019. Abstract: Nowadays, many mother boards and PCBs have errors due to their life cycle end or mistakes in production process. In most of these cases, their classification is done manually, meaning an exposition to toxic elements for the employees. Thus, in this project we propose a solution based on computer vision and robotics. On one hand, error detection is made with a Siemens MV440 camera and images taken by it are processed on Octave. On the other hand, PCB classification is done by robot KUKA youBot, which is programmed on Linux supported software Robot Operating System or ROS. Previously, we simulate our robot workspace on Gazebo program. Key words: ROS, Octave, PCB, image processing, error detection.
3 INDEX OF CONTENTS 1. INTRODUCTION 9 1.1. Motivation of the project ............................................................................ 10 1.2. Main goals .................................................................................................. 10 2. ANALYTICAL PART 12 2.1. ROS: architecture and characteristics ........................................................ 12 2.1.1. Architecture ..................................................................................... 12 2.1.1.1. Filesystem level. ....................................................................... 12 2.1.1.2. Computation graph level .......................................................... 13 2.1.2. First steps on ROS ........................................................................... 15 2.1.2.1. Creating a new workspace........................................................ 15 2.2. KUKA youBot............................................................................................ 16 2.2.1. Overview of kinematic structure ...................................................... 16 2.2.1.1. How to move KUKA youBot arm to its home position .......... 16 2.2.2. Robot kinematics theory .................................................................. 18 2.2.3. Denavit-Hartenberg parameters ....................................................... 19 2.2.4. Inverse kinematics ........................................................................... 21 2.2.5. Technical specifications ................................................................... 25 2.2.6. Connections ..................................................................................... 26 2.3. Camera ....................................................................................................... 26 2.4. Computer vision on Octave ........................................................................ 29 2.4.1. Programming on Octave. Artificial vision most used commands ... 29 2.4.2. Computer vision techniques for error detection in PCBs ............... 32 2.4.3. PCBs. Production and use errors. .................................................... 36 3. DESIGN PART 38 3.1. Real workspace: settings and preparation. ................................................. 38 3.1.1. Camera connections. ........................................................................ 38 3.1.2. Platform instalation for camera. ....................................................... 40 3.2. Robot simulation. ....................................................................................... 42 3.2.1. Forward and inverse kinematics equations obtained on Robotics Toolbox. ........................................................................................... 42
4 e 3.2.2. Inverse Kinematics programming for KUKA youBot. .................... 45 3.2.3. Robot programming on C++ ............................................................ 46 3.2.4. Simulation on Gazebo. ..................................................................... 58 3.3. Computer vision programming. ................................................................. 61 3.3.1. License Automation Manager from Siemens. ................................. 61 3.3.2. Image acquistion mode for Siemens MV440 camera. ..................... 63 3.3.3. PCBs error detection programming. ................................................ 64 3.3.4. Communication between camera and ROS ..................................... 72 4. RESULTS AND CONCLUSIONS 76 4.1. Computer vision part results ...................................................................... 76 4.2. KUKA youBot part results ......................................................................... 80 4.3. Final conclusions ........................................................................................ 82 5. ACKNOWLEDGEMENTS 83 6. REFERENCES 84 7. ANNEXES 86 7.1. ROS C++ CODE ........................................................................................ 86 7.2. OCTAVE COMPUTER VISION CODE .................................................. 99 7.3. MATLAB FORWARD AND INVERSE KINEMATICS CODE ........... 106 8. APPENDIXES 111 8.1. KUKA YOUBOT ARM SPECIFICATIONS .......................................... 111 8.2. MAXON JOINT MOTORS ..................................................................... 115 8.3. SIEMENS MV440 CAMERA SPECIFICATIONS ................................ 116
5 INDEX OF ILUSTRATIONS Figure 1. Scheme of final thesis ..................................................................................... 11 Figure 2. Filesystem level folders[2] .............................................................................. 13 Figure 3. Computation graph level elements[2] ............................................................. 14 Figure 4. Communication between nodes[3] .................................................................. 14 Figure 5. Creating a new workspace on ROS ................................................................. 15 Figure 6. Packages included in created workspace[3] .................................................... 16 Figure 7. KUKA youBot ................................................................................................ 16 Figure 8. Robot's arm movement to its home position[6] .............................................. 17 Figure 9. KUKA youBot home position ......................................................................... 18 Figure 10. Kinematics model for a 2 DOF robot[8] ....................................................... 18 Figure 11. D-H link twist and length[8] ......................................................................... 20 Figure 12. Example of D-H parameters obtaining[8] ..................................................... 20 Figure 13. Example of inverse kinematics[18] ............................................................... 21 Figure 14. Inverse kinematics of 2R arm[18] ................................................................. 22 Figure 15. How to calculate q1 and q2 for 2R arm[18] ................................................. 22 Figure 16. KUKA youBot model for obtaining inverse kinematics[20] ........................ 23 Figure 17. KUKA youBot manipulator scheme in XYZ axes[20] ................................. 24 Figure 18. Joints motors[8.2] .......................................................................................... 25 Figure 19. Robot’s angles and height[8.1] ..................................................................... 25 Figure 20. KUKA youBot connections .......................................................................... 26 Figure 21. Siemens MV440 camera[4]........................................................................... 27 Figure 22. MV440 camera connections and components[4] .......................................... 28 Figure 23. MATLAB supported vision cameras ............................................................ 29 Figure 24. Robot’s arm image with Imshow[9] ............................................................. 31 Figure 25. PCB image with Imshow[9] .......................................................................... 31 Figure 26. PCB image converted to greyscale with rgb2gray[9] ................................... 31 Figure 27. Graphical example of dilation matrix[11] ..................................................... 33 Figure 28. Erosion graphical example[10] ..................................................................... 33 Figure 29. Erosion practical example, before and after. [10] ......................................... 33 Figure 30. Example of filtering[10] ................................................................................ 35 Figure 31. Example of template matching10] ................................................................ 36
12 e 2. ANALYTICAL PART 2.1. ROS: architecture and characteristics 2.1.1. Architecture ROS structure can be divided in three levels of knowledge: filesystem level, computation graph level and community level. We will make a previous introduction of each one of them, to make a deeper analysis afterwards. [2] Filesystem level. This level contains all ROS resources that we can find on disk. Without them, it would not be able to work. It contains packages, metapackages, package manifests, repositories, message types and service types. All these concepts are going to be defined later. Filesystem level’s main aim is to group the building process of a project and keep flexibility on each of its parts. Computation graph level. It is the network of ROS processes that are connected all together. This includes a lot of concepts that we should know before starting to program in ROS: nodes, master, parameter server, messages and topics. On this level, any element can interact with other elements, see information sent between them and exchange data. Community level. It is the level in charge of enable different communities in order to transmit information and software. We are not going to focused on this level because it is more oriented to sharing code to the cloud. 2.1.1.1. Filesystem level. The same way as an operating system like Windows or Linux, ROS programs are formed by folders, which define their functions. We can see this in the Figure 2 attached.
13 Figure 2. Filesystem level folders[2] - Packages. They are minimum structures necessaries for ROS to work properly and can contain configuration files, nodes, etc. - Metapackages. A group of packages received the name of metapackage. An example of metapackage could be the navigation stack. - Package manifests. They are like packages, but with their extension in XML. Package manifests mainly give information to users about packages, licenses, compilation files, and so on. - Message types. It is the kind of information standardized about communication between processes. - Service types. They give information about processes structure in ROS. 2.1.1.2. Computation graph level This level is used by ROS to set up systems, handle all the processes and stablish communication with more than one computer only. Now we are going to introduce some concepts that are very useful to understand what computation graph level is about, as shown in Figure 3.
14 e Figure 3. Computation graph level elements[2] - Nodes. They are processes which are communicated to each other. ROS normally uses a combination of nodes in order to manage different functions. - Master. It is the server responsible of the communication between nodes, messages, topics, etc. Regardless of the number of nodes we have, without the master they would be useless because we couldn’t send information from one to another. All computers with ROS installed must have a master. Normally we launch ROS master with roscore and roslaunch. - Parameter server. As its name shows, parameter server provides configuration of nodes parameters. - Messages. They are the way of communication between nodes. In ROS, we can develop our own message types, sending different data to other nodes, such as float, double, integer, etc. - Topics. A standardized way to say that a node is sending information is that it is publishing a topic. Topics are routes used by ROS network to give a name to each message. - Services. In order to get a response from a node, topics are not the answer. Because of this, we need to stablish communication previously with services, so every node that has a service can exchange information with the rest, as shown in Figure 3. This is done thanks to request-reply communication, due to distributed systems like ROS do not use client-server or other many-to-many politics. Figure 4. Communication between nodes[3]
15 - Bags. They are used to save data from nodes, such as sensor data, camera data, and so on, to develop new algorithms and programs with it. 2.1.2. First steps on ROS 2.1.2.1. Creating a new workspace Before starting to work with nodes and packages, a new workspace must be created to have all the information necessary, such as make files or build files. For this reason, we need to execute the following commands on a Linux terminal, attached in Figure 5. Figure 5. Creating a new workspace on ROS Once we have created our workspace, all the packages included in it (and the ones that we are going to include next too) can be seen with the command ls, as shown in Figure 6. [3]
16 e Figure 6. Packages included in created workspace[3] 2.2. KUKA youBot This robot has been made with the purpose of scientific research and training on an open source platform. In our case, this robot only has an arm with five degrees of freedom as further illustrated in Figure 7, but it normally includes an omnidirectional base. Anyway, we don’t need this one for the application explained. Figure 7. KUKA youBot We decide to choose this robot for our project because of its small size and flexibility. For grabbing mother bases, it can grip them without making too many movements, in contrast to other types of robots that we can find in the industry. This implies a lot of advantages, but mainly one: our workspace doesn’t need to be big to let the robot do its job, as larger ones do. 2.2.1. Overview of kinematic structure 2.2.1.1. How to move KUKA youBot arm to its home position
17 It is crucial to consider that our robot’s joints are based on relative coordinates. This means that they have encoders whose position depends on a reference one, so there are not absolute joint angles. The reference position that we mentioned before is also called home position or rest position, which is a starting point to make different actions with the robot. The process of going to this position must be slow and smooth, so we will not break any of robot’s joints. [5] Moreover, a critical factor is knowing that every time robot’s movement starts, it must depart from a rest position in order to keep everyone’s safety and robot’s too. For this motive, we must program our robot to move to home position at the start and at the end of the process. With the purpose of bringing the arm to its rest position, it is necessary to follow these instructions as shown in Figure 8. [6] Figure 8. Robot's arm movement to its home position[6] In a nutshell, this process consists in moving all robot’s joints to its mechanical stops. Now we can obtain its Denavit-Hartenberg parameters, but previously an explanation of it is necessary. Following the instructions mentioned before, our robot must be in rest position like it is shown in Figure 9 attached.
18 e Figure 9. KUKA youBot home position 2.2.2. Robot kinematics theory Before introducing D-H parameters and calculating them, there must be an introduction of some robotics and mechanics concepts. [8] Robot kinematics. It is the study of robot’s movement compared to a reference system, including an analytical description of it as a time function and a relation between robot’s end location and joints values. We can see an example of this explanation in Figure 10, which is a direct kinematic model of 2 D.O.F (Degrees Of Freedom) plane robot. Our joints coordinates are q1 and q2, while (x, y) are robot’s end position grid reference. Figure 10. Kinematics model for a 2 DOF robot[8]
19 Direct kinematics problem. Its aim is to get robot’s end position and orientation with regard to a baseline coordinates system. Previously, we have to know joints angles and geometrical parameters of robot’s elements. Differential model. It is a mathematical model, based on Jacobian matrix which associates joints movement speed with robot end’s ones. To make things easier, we are going to use Denavit-Hartenberg model to calculate kinematics model of KUKA youBot. Inverse kinematics problem. In this case, the issue is the opposite compared to the direct kinematics one. Here, we know the end positions, but our main goal is getting arm positions and angles in order to reach it. 2.2.3. Denavit-Hartenberg parameters J. Denavit and R.S. Hartenberg proposed, back in 1955, a matrix model that gives a reference system in a systematic way, relative to each tier named i from a joint, so robot’s kinematic model can be obtained of it. According to this representation, choosing a reference system for each tier, we can obtain the next one following 4 basic transformations that only depend on tier’s geometrics characteristics. [8] These transformations are based on rotations and translations: • Rotation around zi-1 axis an angle θi. • Translation through zi axis a distance di. • Translation through xi axis a distance ai. • Rotation around xi axis an angle αi. Finally, we will obtain a matrix like the attached one in Equation 1. Also, an example of how to calculate D-H parameters is shown in Figure 12. Note: 𝐶𝛼𝑖 and 𝑆𝛼𝑖 mean cos (𝛼𝑖) and sin (𝛼𝑖), respectively.
20 e 𝐴𝑖 𝑖−1 =𝑅𝑜𝑡𝑧(𝜃𝑖) 𝑇(0,0,𝑑𝑖) 𝑇(𝑎𝑖,0,0) 𝑅𝑜𝑡𝑥(𝛼𝑖)= Equation 1. Denavit-Hartenberg parameters matrix Furthermore, we can see how to obtain twists and lengths in Figure 11, continuing with D-H model. Figure 11. D-H link twist and length[8] Because this process is really annoying to do , as it requires 16 steps according to D-H model to obtain its parameters for our robot, we are going to use Robotics Toolbox on MATLAB for it. Figure 12. Example of D-H parameters obtaining[8]
21 In KUKA youBot case (5 DOF), D-H symbolic parameters are included in following Table 1. These parameters were explained at the beginning of this section [2.2.3] Link αi ai di qi 1 α1 a1 d1 q1 2 α2 a2 d2 q2 3 α3 a3 d3 q3 4 α4 a4 d4 q4 5 α5 a5 d5 q5 Table 1. D-H symbolic parameters for KUKA youBot These parameters will be used in next sections also for obtaining inverse kinematics in our project. [3.2.1] 2.2.4. Inverse kinematics In most of cases, we know the position which we want our robot to go, but it is necessary to get their joints positions and angles for it. [18] Due to this, inverse kinematics concept is introduced, as shown in Figure 13. Figure 13. Example of inverse kinematics[18]
28 e Figure 22. MV440 camera connections and components[4] In respect of connection ports, our camera works with Ethernet and obviously its power supply port. The Ethernet one is used to control our camera with a PC, so it must require a network connection via TCP/IP. Combined cable socket (number 6 in Figure 11) is used for power supplying, I/O connectors and RS-232 interface.
29 2.4. Computer vision on Octave Instead of using MATLAB, we are going to develop the part relative to computer vision with Octave, which functions and programming are really similar to MATLAB, but it is an open source IDE, which means that nodes communications between it and ROS will not be a problem in terms of permissions, keys, etc. Octave is a MATLAB compatible software, so every program made in MATLAB can be compiled in Octave and vice versa. Moreover, thanks to its working on Linux softwares, Octave can take any kind of camera for image acquisition, not like MATLAB which only accepts a specific amount of them, as shown in Figure 23. Figure 23. MATLAB supported vision cameras 2.4.1. Programming on Octave. Artificial vision most used commands[11] We are going to use mainly a combination of these basic commands on Octave, but they are the same as MATLAB:
30 e • Imshow. It shows an input image. • Imread. It loads an image from disc on a I matrix, accepting multiple formats as .jpg, .tif, .bmp, etc) • Imwrite. It saves an I image on disc with a specific format. • Imhist. It calculates an histogram from a I image and it saves it on a variable. • Imtool. Tool for image processing that allows to zoom, measure, visualize and manipulate histograms, contrast ajust and shining. We can see some examples of code and image processing, made on MATLAB, which work on Octave perfectly. Images attached in Figure 24, Figure 25 and Figure 26. %% %Shows an image through screen I=imread('brazo_robot.jpg'); figure imshow(I) %% whos %% figure J=imread('HeroImage_PCB.jpg'); imshow(J) whos figure W=rgb2gray(J); % convert image into greys with rgb2gray imshow(W)
31 Figure 24. Robot’s arm image with Imshow[9] Figure 25. PCB image with Imshow[9] Figure 26. PCB image converted to greyscale with rgb2gray[9]
32 e 2.4.2. Computer vision techniques for error detection in PCBs [11] In order to detect components not well welded, corrosion or other type of errors in mother bases, we have to introduce a definition, called morphology, which is going to be applied on Octave. Morphology is a matematical concept, introduced by G. Matheron and J. Serra at Mines School of Paris in the 1960s, which is applied for changing and understanding objects structure that appear in images. An important concept in morphology is the structuring element, which is the responsible of defining form and extension of morphological operation. This means that we can apply morphology on a specific zone of our picture without changing the rest, thanks to structuring element. First of all, we consider that readers have a previous knowledge of Set Theory and its operations such as union, intersection, complement, and so on. For our project, we are going to use two main morphological operations: dilation and erosion. • Dilation. This operation is similar to the XOR logical port, where we have an image A and structuring element B, as it is shown in attached example in Equation 7. 𝐴 𝑋𝑂𝑅 𝐵={(0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2)} Equation 7. Example of dilation matrix Result of dilation is an image which is a set of all vectors possibles of adding pairs elements of both A and B. A graphical example of this can be seen in Figure 27.
33 Figure 27. Graphical example of dilation matrix[11] • Erosion. This operation implies a decrease of active pixels number compared to our original image. Its main application is to eliminate details of small size on a binary image. We can see a graphical example of erosion in Figure 28 and also a practice of it in Figure 29, in order to count the number of screws in attached image. Figure 28. Erosion graphical example[10] Figure 29. Erosion practical example, before and after. [10]
34 e As we have seen in last picture, erosion is a very useful tool to count pieces or distinguish different elements of them, with a view to apply other morpholical operations so we could know their area, labelling, etc. Main commands on Octave are the following: [11] - Se=strel(´disk´, R). Structuring element with size disk of radium R. - Se=strel(´line´, long, grad). Lineal structuring element with height long, grad specifies angle in grades on counterclockwise. - Se=strel(´square´, w). Square structuring element of w pixels. - D=imdilate(BW, se). Picture dilation with structuring element se. - E=imerode(BW, se). Picture erosion with structuring element se. - C=imclose(BW,se). Morphological closing of BW image with element se. - O=imopen(BW, se). Morphological opening of BW image with element se. - Z=imsubtract(X, Y). Subtraction of images X and Y. Previous to apply morphological operations, we must filter our images to eliminate pixels that can ruin fails detection process. Filtering aim is to modifie images in order to make them more proper for later transformations. One thing that should be considered is that filtering can eliminate desired characteristics of our image, so it needs to be applied carefully. Depending on which mathematical expression has been used, we can distinguish between lineal and non-lineal filters. From lineal filters perspective, there are two main types: average filter and gauss filter. From no lineal filters view, most important one is median strainer. In our project we are going to focused on lineal ones, mainly on gauss filter, because they have better applications for filtering out pixels that are less important in our image. Gauss filter is based on mathematical bell of the same name, which downgrades less image at issue than average filter, keeping details and outlines. An example of filtering is shown in Figure 30, which corresponds to a photo of a oneeuro coin. Here first image has noise (specifically a salt and pepper one) and second one is after applying median strainer.
35 Figure 30. Example of filtering[10] Moreover, our last computer vision method that will be applied is template matching, which is based on statistical concept of correlation coefficient. Level of association between two variables (in our case it will be pictures) is defined as correlation coefficient, whose ranges change between -1 and 1. This means that if two variables have a correlation of 1, they are identical. Mathematical formula is attached in Equation 8 . However, we are not going to get into this concept deeply, but in image processing one instead. 𝑝𝑥,𝑦=𝐸[(𝑋−µ𝑥)(𝑌−µ𝑦)] 𝜎𝑥𝜎𝑦 Equation 8. Correlation coefficient[9] In terms of computer vision, correlation will be translated to matrix correlation, simply searching for elements in common between images. Each pixel of search image with coordinates (xs, ys) has intensity matrix Is(xs, ys) and another one in the jig with coordinates (xt, yt) has intensity matrix It(xt ,yt). Therefore, absolute difference in the pixel intensities is defined as the following: Diff(xs, ys, xt, yt) = | Is(xs, ys) – It(xt, yt) |.
36 e Lowest differential provides an estimate for best position of template within main picture, being shown in Figure 31, where elements that match are marked by an asterisk. Figure 31. Example of template matching[10] 2.4.3. PCBs. Production and use errors. During production process and also when PCBs end their life cycle, there are some different types of errors that can produce their bad working, such as corrosion, components not well welded or broken, etc. Identification of these errors is purely visual and done manually by workers, but in some occasions, they are difficult to see for human eye. In our case, we are going to use PCBs from printing toners, with a standard one, as it is shown in Figure 32, being compared with others that have broken pads or other types of errors. Figure 32. PCB ML/XEROX model used for detection
37 Thanks to these reference images, we are going to compare them easily, due to the fact that there are big differences between well working PCBs and underwhelming ones, as we can see in the following picture, Figure 33. Figure 33. Bad PCB ML/XEROX model On this image it is quite obvious that there is too much welding in pads and also some components such as capacitors are missing. To sum up, we are going to do a recognition that can be seen by workers, but in an automated way, as it implies better production process as well as more safety for employees due to exposition of noxious fumes.
44 e Therefore, D-H parameters for the KUKA youBot are shown in Table 4, where L1, L2, L3, L4, L5 and L6 are known values from our robot specifications[Figure 19] and qi angles are obtained on inverse kinematics code. Link αi ai di qi 1 -π/2 L1 L2 q1 2 0 L3 0 q2 3 0 L4 0 q3 4 π/2 0 0 q4 5 0 0 L5+L6 q5 Table 4. D-H parameters for KUKA youBot obtained with MATLAB Robotics Toolbox Finally, these angles values can be seen in the following Table 5, which will be applied in our C++ code afterwards. LINK qi 1 0 2 -1,9526 3 -2,0192 4 1,73184 5 3,14 Table 5. Values for Qi angles of KUKA youBot
45 3.2.2. Inverse Kinematics programming for KUKA youBot. First of all, KUKA youBot model needs to be initialized. Then, we implement our model with youbot_driver package, downloaded from GitHub webpage. After that, we need to test robot’s movement, as its gripper can be calibrated in order to take our PCBs in a proper way. This is done thanks to hello_world_demo program, included in the package mentioned before, where the robot starts to move and its gripper as well, stopping in its rest position. In terms of our program, we are going to modify this one and some inverse kinematics code that we can find on the Internet, as well as adding our communication with computer vision part. [17] Next, we need to program inverse kinematics of our robot, so we will know each notable angle and position for our joints. Then, with the results obtained by computer vision part, we should configure robot movement to reach the positions we wanted in first touch. For the inverse kinematics part, we programmed it on C++, where now we are going to explain each part of the code and what it does in next sections. Furthermore, it is remarkable that relevant positions were taken empirically, configuring our KUKA youBot with PC keyboard, following the instructions given inside its user manual, as it can be seen in Figure 35. This code is included in [2]. ROS C++ code, part keyboard.cpp.
46 e Figure 43. Instructions for using KUKA youBot with keyboard [3] 3.2.3. Robot programming on C++ First, we should remark that for our program we are following the right hand rule, meaning that all robot‘s movement are going to follow the reference system attached in Figure 44, but in our case without onmidirectional base. Positive X-axis direction is straight outward from the front of our robot. Positive Y direction is on the letf side and Z is positive in the upward one.
47 Figure 44. Reference system for KUKA youBot programming [5] Next step remarkable that we are going to take is explaining each part of code relative to our robot. [1] #include "youbot/YouBotBase.hpp" #include "youbot/YouBotManipulator.hpp" #include <math.h> #include <studio.h> #include <ImageService.h> using namespace youbot; int main() { double px=0,pz=0,py=0; double theta_base=0, theta_2=0, theta_3=0, theta_4=0; double theta_link_1=0 , theta_link_2=0; double theta_link_1p=0, theta_link_2p=0; /* configuration flags for different system configuration (f.e. arm without base)*/
48 e bool youBotHasBase = false; bool youBotHasArm = false; /* define speeds */ double translationalVelocity = 0.05; //meter_per_second double rotationalVelocity = 0.2; //radian_per_second /* pointers for youBot base and manipulator */ YouBotBase* myYouBotBase = 0; YouBotManipulator* myYouBotManipulator = 0; /* obtain response from Octave */ res=req.create_response_(); As we can see here, first variables are configured with value 0 or False in defect, except for translational and rotational speeds. This is because of they will change during each loop that we will apply in a relative form, so it means we are using increments, not absolute coordinates. Also, we put some youBot base related variables due to the fact that in all simulators available for KUKA youBot they have it included, so we will not have problems with it. Finally, we have to receive a response from our image processing program, so we include a data structure res for it. try { myYouBotBase = new YouBotBase("youbot-base", YOUBOT_CONFIGURATIONS_DIR); myYouBotBase->doJointCommutation(); youBotHasBase = true; } catch (std::exception& e) { LOG(warning) << e.what(); youBotHasBase = false; } try {
49 myYouBotManipulator = new YouBotManipulator("youbot-manipulator", YOUBOT_CONFIGURATIONS_DIR); myYouBotManipulator->doJointCommutation(); myYouBotManipulator->calibrateManipulator(); // calibrate the reference position of the gripper //myYouBotManipulator->calibrateGripper(); youBotHasArm = true; } catch (std::exception& e) { LOG(warning) << e.what(); youBotHasArm = false; } This part is the relative of proving robot configurations such as gripper‘s or arm‘s. /* Variable for the base. quantity<si::velocity> longitudinalVelocity = 0 * meter_per_second; quantity<si::velocity> transversalVelocity = 0 * meter_per_second; quantity<si::angular_velocity> angularVelocity = 0 * radian_per_second; /* Variable for the arm. */ JointAngleSetpoint desiredJointAngle; //GripperBarSpacingSetPoint gripperSetPoint; Then, we define robot speeds variables, as well as joints angles. try { /* * Simple sequence of commands to the youBot:
50 e */ /*if (youBotHasBase) { /* move forward */ /*longitudinalVelocity = translationalVelocity * meter_per_second; transversalVelocity = 0 * meter_per_second; myYouBotBase->setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity); LOG(info) << "drive forward"; SLEEP_MILLISEC(2000); /*we always put a little delay between moves*/ /* move backwards */ /*longitudinalVelocity = -translationalVelocity * meter_per_second; transversalVelocity = 0 * meter_per_second; myYouBotBase->setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity); LOG(info) << "drive backwards"; SLEEP_MILLISEC(2000); /* move left */ /*longitudinalVelocity = 0 * meter_per_second; transversalVelocity = translationalVelocity * meter_per_second; angularVelocity = 0 * radian_per_second; myYouBotBase->setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity); LOG(info) << "drive left"; SLEEP_MILLISEC(2000); /* move right */ /*longitudinalVelocity = 0 * meter_per_second; transversalVelocity = -translationalVelocity * meter_per_second; angularVelocity = 0 * radian_per_second; myYouBotBase->setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity); LOG(info) << "drive right"; SLEEP_MILLISEC(2000);
51 /* stop base */ longitudinalVelocity = 0 * meter_per_second; transversalVelocity = 0 * meter_per_second; angularVelocity = 0 * radian_per_second; myYouBotBase->setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity); LOG(info) << "stop base"; } */ On this part, we test our robot‘s base movement, in order to prove if all variables are working properly on Gazebo later.[3.2.4] This means that it will be forward, backwards, left and right with breaks of 2 seconds between them. if (youBotHasArm) { /* unfold arm * position were taken empirically using keyboard and KUKA youBot */ desiredJointAngle.angle = 2.9624 * radian; myYouBotManipulator->getArmJoint(1).setData(desiredJointAngle); SLEEP_MILLISEC(1000) desiredJointAngle.angle = 2.5988 * radian; myYouBotManipulator->getArmJoint(2).setData(desiredJointAngle); desiredJointAngle.angle = -2.4352 * radian; myYouBotManipulator->getArmJoint(3).setData(desiredJointAngle); desiredJointAngle.angle = 1.7318 * radian; myYouBotManipulator->getArmJoint(4).setData(desiredJointAngle); desiredJointAngle.angle = 2.88 * radian; myYouBotManipulator->getArmJoint(5).setData(desiredJointAngle);
52 e /*desiredJointAngle.angle = 3.14 * radian; myYouBotManipulator->getArmJoint(5).setData(desiredJointAngle); desiredJointAngle.angle = 1.9526 * radian; myYouBotManipulator->getArmJoint(2).setData(desiredJointAngle); desiredJointAngle.angle = -2.0192 * radian; myYouBotManipulator->getArmJoint(3).setData(desiredJointAngle); /*desiredJointAngle.angle = 1.73184 * radian; myYouBotManipulator->getArmJoint(4).setData(desiredJointAngle); */LOG(info) << "unfold arm"; SLEEP_MILLISEC(4000); On this section, the meaning of our code is the same as in previous part, but here we test robot‘s arm, putting the desired joint angle as robot‘s home position, so it will always start its movement from it every time we compile the code. std::cout << " -------------- Co-ordiantes of Point Location ------------ : " << endl; if(res.myPCB=0){ /* co-ordinates taken empirically for end positions where we are going to put our PCB */ x_cordinate=-0.1225; y_cordinate=0.1124; z_cordinate=0.0239; std::cout << "PCB in bad conditions! " << endl; std::cout << "Co-ordinates of end position are : " << endl; std::cout << " X: " << x_cordinate << endl; std::cout << " Y: " << y_cordinate << endl; std::cout << " Z: " << z_cordinate << endl;
53 } if(res.myPCB=1){ x_cordinate=-0.2225; y_cordinate=0.1124; z_cordinate=0.0239; std::cout << "PCB in good conditions! " << endl; std::cout << "Co-ordinates of end position are : " << endl; std::cout << " X: " << x_cordinate << endl; std::cout << " Y: " << y_cordinate << endl; std::cout << " Z: " << z_cordinate << endl; } double px = x_cordinate + px_p; double py = -y_cordinate + py_p; double pz = z_cordinate; //0.0432; This part explains how we manage to get Octave‘s variables from computer vision part, as well as configuring aim points(where PCBs will be left) which were taken empirically. [3.2.2] ////////////////// THETAS FOR ARM-LINK 1 2 3 /////////// double l1 = 0.302 - 0.147;
60 e Once we have our workspace built in the simulator, we have to compile our code developed on C++ for our robot and see how it responds. Before doing this, it should be pointed out that simulation doesn‘t correspond to reality exactly, as we saw in previous paragraphs, where KUKA youBot model provided by Gazebo has both omnidirectional base and arm, despite of our real robot only owns the last one. Next step is to launch our code developed on C++ with the command roslaunch mypackage myrobot.launch. After this, our robot starts to move in simulator workspace, grabbing the cube and putting it in the left side of the table or in the right one, depending on the result given by image processing part, which needs to be compiled previously.
61 3.3. Computer vision programming. 3.3.1. License Automation Manager from Siemens. Before taking photos with Siemens camera, we need to install its licenses and software in order to work with it properly. [4] Due to this, working with Siemens MV440 camera on Linux is not possible, so it was necessary to install every single package in a second PC with Windows support and stablish communication between computers afterwards. Furthermore, we have to take into account that network between these two PCs will be via Internet and another Siemens program that we can download in every platform, but this part will be explained in next sections. [3.3.4] Primarly, camera has to be connected physically to the PC (this means both power supply and Ethernet wire) before installing the software, mainly because IP camera configuration has to be done to communicate camera and computer on PRONETA(another Siemens software included in instalation CD), as we can see in attached Figure 48. Figure 48. PC and camera IP connection[3.3.1] After this part, license needs to be installed with License Automation Manager, keeping in mind previously that IP address put on PRONETA must be the same for this program as well. Next step is installing user interface on our computer, with Internet connection needed, as we are going to use web browser, following attached Figure 49.
62 e Figure 49. Opening web browser in PRONETA for user interface[3.3.1] Once we open user program, communication between our two PCs can be stablished, as in computer which software is Linux, we can put IP address of the reader in a web browser and work with both of them at the same time. An example of configuration on Internet Explorer is attached in Figure 50. Figure 50. Code reading configuration on web browser[3.3.1] Next step is to adjust camera settings according to user’s will, as its calibration is needed before saving all the pictures for image processing. Tough this part will be explained in next section. [3.3.2]
63 3.3.2. Image acquistion mode for Siemens MV440 camera. Before putting our pictures taken by the camera on image processing part, it is necessary to configure our reader and trigger mode. Three types of image acquistion can be distinguished, but we are only going to use one of them. This is going to be the triggered mode, where camera takes photos only when we press the refresh button. Therefore, user has to be focused on pulling the trigger every time PCBs are changed for their recognition. Another reason to use this mode is that we can control the brightness of each picture between each camera shot, so error detection will be easier afterwards. [4] Finally, we can also adjust camera‘s flash in order to take better quality photos with more or less resolution. The only part which cannot be configured in real time is image color, as it always be binarize picture, so we need to transform it later when saving to a directory. Before transfering pictures to Octave directory, user has to select which part of the photo wants to be processed. An example of this proceeding is enclosed in Figure 51. Figure 51. SIMATIC MV440 HR user program[3.3.2]
64 e 3.3.3. PCBs error detection programming. In this section we are going to explain each part of code belonging to functions used for error detection programming, adding representative pictures of it as well. However, first it is needed to point out that every photo of PCBs has a white background. This is due to restriction between elements and background is easier when the last one is white in terms of binarizing, filtering, and so on, but the main reason is that pixels after our transformation can only be black or white, so it makes detection more user-friendly, as Figure 52 shows. [11] Also, we should consider illumination, which takes an important part on this section, as if there is too much light or too little, it can end up in recognition mistakes. Figure 52. PCB with white background for detection[3.3.3] 3.3.3.1. Filtering function The main purpose of this function is to filter one of our images taken by camera to eliminate possible noises from them. Before binarizing the image to apply gauss filters, it is necessary to check if it is in color frame range or black and white one. Thus, this process can be applied in an optimum way without mistakes. %Obtain image edge from subtract of two gauss filters if ndims(I) == 3 %Checking if image is in black and white or not disp('Image in color') I=rgb2gray(I);
65 end After that, we build a zeros matrix where we will add our image transformed. Two matrixes of filtering are built for being applied to the original picture, considering both axes X and Y. [rows,columns]=size(Ig); Ig=double(Ig); %passing to double format I_contour=zeros(rows,columns); Sx=[-1 0 1;-2 0 2;-1 0 1]; Sy=[-1 -2 -1;0 0 0; 1 2 1]; Then, our image is retouched with imfilter and the matrixes created previously. Next step is transforming this matrix from mathematics view to gray scale with mat2gray, to plot our images with and without filtering finally. [9] Ix=imfilter(Ig,Sx); Iy=imfilter(Ig,Sy); I_contour=abs(Ix)+abs(Iy); S=mat2gray(I_contour); figure imshow(I), title('original image') figure imshow(S), title('contour image with mat2gray') Figure 53. Original and filtered image[3.3.3.1]
66 e As we can see in Figure 53, the contour of image obtained with mat2gray command can be distinguished from the background, just as we wanted at the beginning. Both pads and elements included in the PCB taken as an example are seen without any problem, so it is a good signal for later treatments. 3.3.3.2. Morphology This function is the responsible of detecting different elements of pictures taken by Siemens camera, with the purpose of concluding if PCBs are in a good condition or not. function [T]=mymorphology(I,A) if(islogical(I)) disp('Image is already binarized, so it will not be modified') T=I; return end repeat=1; while(repeat==1) umbral=graythresh(I); BW=im2bw(I,umbral); BW2=im2bw(A,umbral); BW2inv=~BW2; BWinv=~BW; radium=input('Introduce radium of structuring element between 1-5: ') ee=strel('disk',radium); % We apply dilation for splitting elements and detecting them B=imerode(BWinv,ee); B2=imerode(BW2inv,ee);
67 L=~B; L2=~B2; Subsequently, it is needed to make a loop where users can apply a dilation according to their taste, as if we select the same structuring element in order to do it in an automated way, it can result in a mistake due to camera’s illumination between shot and shot. We apply dilation to both images in order to delete elements that are not of our interest. figure imshow(I),title('original image'); figure imshow(A),title('testing image'); figure subplot(1,4,1),imshow(BWinv), title('binarized original image') subplot(1,4,2),imshow(L), title('original image with dilation') subplot(1,4,3),imshow(BW2inv), title('binarized test image') subplot(1,4,4),imshow(L2), title('test image with dilation') Next step is plotting all the images used and transformed by this function, as we can see in Figure 54, Figure 55 and Figure 56. Figure 54. Standard image for comparing elements in mymorphology function[3.3.2]
68 e Figure 55. Testing image in mymorphology function[3.3.2] Figure 56. Both images transformed and compared in same plot for mymorphology function[3.3.2] % We see split objects after transformations cc=bwconncomp(B); % creating two data structures for knowing nº elements a=cc.NumObjects ccs=bwconncomp(B2); as=cc.NumObjects if (a~=as)
69 disp('Number of elements are really different. Second image has mistakes'); myPCB=0; %% we create a variable called myPCB which value is 0 when it has mistakes and 1 when it is in good conditions else disp('Number of elements are similar in both images. So testing image is correct'); myPCB=1; %% this variable will be shared with ROS end fprintf('\n Is obtained result the one you wanted?'); fprintf('\n t1. Yes(press 0)'); fprintf('\n t2. No(press 1)'); fprintf('\n'); repeat=input(' '); %Asking user about results end Figure 57. Result obtained after applying mymorphology function[3.3.2] Thanks to command bwconncomp, we create a data structure with the purpose of knowing number of elements in each PCB and compare them to each other. If the number of
76 e 4. RESULTS AND CONCLUSIONS 4.1. Computer vision part results Filtering function As it concerns to filtering function, we can conclude that it works in a proper way, as we can see in Figure 61, and other examples that will be introduced in project presentation afterwards. In all images introduced to this function, their contour can be distinguished without any problem, as well as their elements such as capacitors, resistors, microprocessors and so on. To sum up, filtering function is a good way for detecting contour of each element from our PCBs in the first view, so it can help users to see if they already have errors before applying other methods. Figure 61. Contour image with filtering function[4.1]
77 Mymorphology function As a result of the mymorphology function, it is possible to detect mistakes and elements missing in testing images, as shown in following pictures. We can value at a glance that testing image, corresponding to Figure 62, has too much welding and also some pads and elements are missing, so this mistakes recognition is going to be easy to make in terms of programming. Figure 62. Standard image number 2 for mymorphology function[4.1] Figure 63. Testing image number 2 for mymorphology function[4.1]
78 e Figure 64. Images after applying dilation[4.1] In above Figure 64, it can be seen that after binarizing and applying dilation to both images, the difference between each image is remarkable, as later we can check in commands line that number of elements are different, so our function takes the conclusion that second image is not right. This is shown in Figure 65. Figure 65. Mymorphology function applied to second couple of images. [4.1] In short, this function is the most useful one for our project, as it always detects mistakes in testing PCBs with accuracy. Also, it is the responsible of sending to ROS if our testing PCB is okay or not, so the robot will put it in one side or other, depending on the results obtained. Matching function As for matching function, we can say, without any doubt, that is the least helpful of all, as it is very inconsistent depending on photos ilumination, ending up in detection
79 mistakes. Here we have an example of average recognition of elements in Figure 66 and Figure 67. Figure 66. Jig for second standard image in matching function[4.1] Figure 67. Template matching applied on second testing image[4.1]
80 e 4.2. KUKA youBot part results Our first part for robot results is its D-H parameters, as well as kinematic equations obtained by our code on MATLAB and C++ mentioned in previous sections. [3.2.2] After that, we can see that the robot is starting to move properly, trying to reach PCB position which is shown in Figure 68, but unable to grab it, as we can see in Figure 69 . Figure 68. Robot's movement from home position One of the most probable reasons why I didn‘t work was due to Gazebo simulator doesn‘t have accurate torques for each arm‘s joint of KUKA youBot, so it is working on it, but not in the real workspace. Another one can be that, because of this robot normally has its base included, we should add an offset that is not existent in our working model, so it could reach its main goal. Finally, the most probable one is that an universal gripper should be included to grip small objects like the ones we are using in this project.
81 Figure 69. KUKA youBot trying to reach PCB
82 e 4.3. Final conclusions From computer vision standpoint, we can say that most of our functions are working properly. However, they can be improved as a first approach, mainly for making them in a more automated way. On the other hand, Octave is a good tool for image processing, but is is quite slow, as it doesn´t work in real time(same for MATLAB) like other IDEs do, such as Python+OpenCV. So a second approach could be programming all this part in this software instead of Octave. In terms of our camera, the Siemens MV440 one, my opinion is that we could use a normal camera instead of this one. Basically, this is due to the difference is not that notable and licenses problems for working on Linux too. From robotics forward and inverse kinematics perspective, we can conclude that MATLAB provides a really good toolbox for programming and testing our equations, taking different values and parameters as a result. Thanks to it, we can program our code on C++ for our robot later, following these equations and parameters obtained on it. From robotics programming point of view, our KUKA youBot works perfectly in simulator environment. Nevertheless, when we try to apply our code in real robot, it doesn´t move as we want in first touch, mainly because it is not able to grip the PCBs correctly. The conclusion obtained from this issue, due to differences between real robot and simulator one(it has base with wheels, real one does not) and also because of accuracy problems with the gripper, is that an universal gridder is needed to catch every type of object, including small ones like PCBs, and that a new model of KUKA youBot arm should me added on Gazebo in order to fix the offset between these two configurations. Overall, I think this robot may be more useful in terms of working with it on a Windows developed system, like LabView Robotics or something similar. Despite of being a robot that can be programmed on a Linux environment, where all the licenses are free, it implies a lot of problems, especially on calibration and drivers installation, compared to other robots like ABB where you can use their own simulator (Robot Studio) and they are all configured from scratch.
83 5. ACKNOWLEDGEMENTS From my point of view, working on this project was a great experience, which has developed my knowledges in robotics and programming. I have learnt how ROS works and how to use different libraries already developed for creating my own algorithm. Furthermore, I have learned a new toolbox on MATLAB, such as the robotics one, as well as improving my computer vision programming on this IDE. This thesis cannot be achieved without my teacher’s help, Prof. Dr. Dainius Udris, who gave me the opportunity to work with him and all his advices and recommendations. I would like to thank VGTU in general and its Department of Mechatronics and Robotics and head of the department Professor Vytautas Bučinskas personally for providing the equipment and support. Also, thanks to ESN VGTU, from top to bottom, which has made me have a really good concept of Lithuania overall, way better than it would be without it. Special mention to my mentor, Živilė Latakaitė, who has helped me on adapting to Vilnius and making me feel like home, as well as organizing a lot of events with more Erasmus people, making our friendships even stronger. Now she is not a mentor anymore, but a friend instead. It has been a bless meeting her and all my new friends here in Lithuania. Finally, thanks to my parents, for giving me all their confidence and support from Spain. Regardless of all the kilometers that separate us, they have always been there when I needed them the most, both in good and bad moments.
84 e 6. REFERENCES 1. Short circuit: The lifecycle of our electronic gadgets and the True Cost to Earth. Author: Philippe Sibaud. Retrieved 2013, from http://therightsofnature.org/short-circuit-report-the-true-cost-of-our- electronic-gadgets/ 2. ROS Programming: Building Powerful Robots: Design, build and simulate complex robots. Authors: Anil Mahtani, Luis Sanchez, Enrique Fernandez, Aaron Martinez, Lentin Joseph. Retrieved 2018, from www.PacktPub.com 3. A Systematic Approach to Learning Robot Programming with ROS. Author: Wyatt S. Newman. Retrieved 2018, from http://www.taylorandfrancis.com. 4. SIMATIC Ident for MV420/MV440 Code Reader Systems. Operating systems. Retrieved 2012. 5. KUKA youBot User Manual. Retrieved 2012, from KUKA.com. 6. A novel kinematics for a 5 DOF manipulator based on KUKA youBot. Authors: Allan D. Zhang, Xiao Xiao, Yangmin Li. Retrieved 2015, from https://www.researchgate.net/publication/300416616. 7. Robotics toolbox for Matlab. Author: Peter Corke. Retrieved 2015, from https://petercorke.com/wordpress/toolboxes/robotics-toolbox. 8. Parámetros Denavit-Hartenberg. Cinemática Directa de un Robot Manipulador. Authors: Alberto Herreros, Juan Carlos Fraile Marinero. Retrieved 2017. 9. Digital Image Processing in Matlab. Authors: Rafael C. González, Richard E. Woods, Steve L. Eddins. Retrieved 2011. 10. Image Processing in Octave. Author: John W. Eaton. Retrieved 2018, from https://octave.org/doc/v4.4.0/index.html#Top. 11. Visión Artificial Industrial. Procesamiento de imágenes para inspección automática y robotica. Authors: Eusebio de la Fuente López, Félix Miguel Trespaderne, from Valladolid University. Retrieved 2012. 12. Simulación, control cinemático y dinámico de robots comerciales usando la herramienta de MATLAB, Robotics Toolbox. Author: Miguel Ángel Mato San José. Retrieved 2014 from Valladolid University. 13. Research of robot trajectory control by optical method. Author: Alejandro Perez San Martín. Retrieved 2017 from
85 https://upcommons.upc.edu/bitstream/handle/2117/114061/Alejandr o_Perez_Sanmartin.pdf?sequence=1&isAllowed=y. 14. ROS youBot Inverse Kinematics, from https://github.com/arifanjum/ROS-YouBot-Inverse-Kinematics. 15. ROS tutorials, from http://wiki.ros.org/ROS/Tutorials#Beginner_Level 16. ROS and Octave tutorial, from http://wiki.ros.org/rosoct 17. ROS-Youbot-Inverse-Kinematics, from https://github.com/arifanjum/ROS-YouBot-Inverse-Kinematics 18. Inverse Kinematics theory, University of Rome, from http://www.diag.uniroma1.it/~deluca/rob1_en/10_InverseKinematic s.pdf 19. KUKA youBot motor joints, from https://www.maxonmotor.com/medias/sys_master/root/8815566520 350/2014-10-story-enUS-kuka-research-robot.pdf?attachment=true 20. Derivation of Kinematic Equations for KUKA youBot and implementation on Simulink, . From https://www.academia.edu/23871359/Derivation_of_Kinematic_Eq uations_for_the_KUKA_youBot_and_implementation_of_those_in_ Simulink
92 e //------------------------------------------------------------------- for (double x =0; x< n; x++ ){ for (double y =0; y<m; y++){ double px_p = grid_spacing_n*x; double py_p = grid_spacing_m*y; double px = x_cordinate + px_p; double py = -y_cordinate + py_p; double pz = z_cordinate; //0.0432; ////////////////// THETAS FOR ARM-LINK 1 2 3 /////////// double l1 = 0.302 - 0.147; double l2 = 0.437 - 0.302; double l3 = 0.655 - 0.437; double xc = sqrt(px*px +py*py); double zc = pz; double phi_c = 0; double d = sqrt (xc*xc + zc*zc); std::cout << " d = " << d << std::endl; if (d >= 0.500){ double theta_link_1 = atan2(zc,xc) ; //break; } else if (d == 0.508) { double theta_link_1 = atan2(zc,xc) ; //break;
93 } else if (d > 0.508) { std::cout << " Co-ordinate Points are out of the work space. \n" ; std::cout << "Enter New Co-ordinates Points. \n" ; //break; } else { double xw = xc - l3*cos(phi_c); double zw = zc - l3*sin(phi_c); double alpha = atan2 (zw,xw); double cos_beta = (l1*l1 + l2*l2 -xw*xw -zw*zw)/(2*l1*l2); double sin_beta = sqrt (abs(1 - (cos_beta*cos_beta))); double theta_link_2 = 3.1416 - atan2 (sin_beta , cos_beta) ; double cos_gama = (xw*xw + zw*zw + l1*l1 - l2*l2)/(2*l1*sqrt(xw*xw + zw*zw)); double sin_gama = sqrt (abs (1 - (cos_gama * cos_gama))); double theta_link_1 = alpha - atan2(sin_gama, cos_gama); double theta_link_1p = theta_link_1 + 2*atan2 (sin_gama , cos_gama); double theta_link_2p = - theta_link_2; double theta_2 = theta_link_1p; double theta_3 = theta_link_2p; double theta_4 = (theta_2 + theta_3);
94 e std::cout << " Base Angle " << theta_base << std::endl; std::cout << " Link-1 Angle " << theta_2 << std::endl; std::cout << " Link-2 Angle " << theta_3 << std::endl; std::cout << " Link-3 Angle " << theta_4 << std::endl; desiredJointAngle.angle = theta_base * radian; myYouBotManipulator->getArmJoint(1).setData(desiredJointAngle); //SLEEP_MILLISEC(1000); desiredJointAngle.angle = (2.5988 - theta_2) * radian; myYouBotManipulator->getArmJoint(2).setData(desiredJointAngle); //SLEEP_MILLISEC(1000); desiredJointAngle.angle = (-2.4352 - theta_3) * radian; myYouBotManipulator->getArmJoint(3).setData(desiredJointAngle); //SLEEP_MILLISEC(1000); desiredJointAngle.angle = (1.7318 + theta_4) * radian; myYouBotManipulator->getArmJoint(4).setData(desiredJointAngle); //SLEEP_MILLISEC(1000); //desiredJointAngle.angle = -3.3760 * radian; //myYouBotManipulator->getArmJoint(3).setData(desiredJointAngle); SLEEP_MILLISEC(5000); desiredJointAngle.angle = (1.7318-0.4 + theta_4) * radian; myYouBotManipulator->getArmJoint(4).setData(desiredJointAngle); SLEEP_MILLISEC(1000) } }
95 } //desiredJointAngle.angle = 0.0 * radian; //myYouBotManipulator->getArmJoint(1).setData(desiredJointAngle); /*/* fold arm (approx. home position) using empirically determined values for the positions */ desiredJointAngle.angle = 0.1 * radian; myYouBotManipulator->getArmJoint(1).setData(desiredJointAngle); desiredJointAngle.angle = 0.011 * radian; myYouBotManipulator->getArmJoint(2).setData(desiredJointAngle); desiredJointAngle.angle = -0.1 * radian; myYouBotManipulator->getArmJoint(3).setData(desiredJointAngle); desiredJointAngle.angle = 0.1 * radian; myYouBotManipulator->getArmJoint(4).setData(desiredJointAngle); LOG(info) << "fold arm"; SLEEP_MILLISEC(4000); } } catch (std::exception& e) { std::cout << e.what() << std::endl; std::cout << "unhandled exception" << std::endl; } /* clean up all variables*/ if (myYouBotBase) { delete myYouBotBase; myYouBotBase = 0; } if (myYouBotManipulator) { delete myYouBotManipulator; myYouBotManipulator = 0; } LOG(info) << "Done.";
96 e return 0; 2. keyboard.cpp 1 #include <iostream> 2 #include <vector> 3 #include <signal.h> 4 #include <ncurses.h> 5 6 #include "youbot/YouBotBase.hpp" 7 8 using namespace std; 9 using namespace youbot; 10 11 bool running = true; 12 13 void sigintHandler(int signal) { 14 running = false; 15 printf("End!\n\r"); 16 } 17 18 int main() { 19 20 signal(SIGINT, sigintHandler); 21 22 try { 23 24 rude::Config configfile; 25 26 if (!configfile.load("../config/applications.cfg")) 27 throw ExceptionOODL("../config/applications.cfg file no found"); 28 29 int ch = 0; 30 double linearVel = 0.05; //meter_per_second 31 double angularVel = 0.2; //radian_per_second 32 configfile.setSection("KeyboardRemoteContol"); 33 linearVel = configfile.getDoubleValue("TanslationalVelocity_[meter_per_second]"); 34 angularVel = configfile.getDoubleValue("RotationalVelocity_[radian_per_second]");
97 35 36 YouBotBase myYouBotBase("youbot-base"); 37 38 JointVelocitySetpoint setVel; 39 quantity<si::velocity> longitudinalVelocity = 0 * meter_per_second; 40 quantity<si::velocity> transversalVelocity = 0 * meter_per_second; 41 quantity<si::angular_velocity> angularVelocity = 0 * radian_per_second; (void) initscr(); /* initialize the curses library */ 44 keypad(stdscr, TRUE); /* enable keyboard mapping */ 45 (void) nonl(); /* tell curses not to do NL->CR/NL on output */ 46 (void) cbreak(); /* take input chars one at a time, no wait for \n */ 47 // (void) echo(); /* echo input - in color */ 48 49 def_prog_mode(); 50 51 refresh(); 52 printf("up = drive forward\n\r" 53 "down = drive backward\n\r" 54 "left = drive left\n\r" 55 "right = drive right\n\r" 56 "y = turn right\n\r" 57 "x = turn left\n\r" 58 "any other key = stop\n\r\n"); 59 refresh(); 60 61 while (running) { 62 63 ch = getch(); 64 65 switch (ch) { 66 case KEY_DOWN: 67 longitudinalVelocity = -linearVel * meter_per_second; 68 transversalVelocity = 0 * meter_per_second; 69 angularVelocity = 0 * radian_per_second; 70 LOG(info) << "drive backward"; 71 printf("\r"); 72 break; 73 case KEY_UP:
98 e 74 longitudinalVelocity = linearVel * meter_per_second; 75 transversalVelocity = 0 * meter_per_second; 76 angularVelocity = 0 * radian_per_second; 77 LOG(info) << "drive forward"; 78 printf("\r"); 79 break; 80 case KEY_LEFT: 81 transversalVelocity = linearVel * meter_per_second; 82 longitudinalVelocity = 0 * meter_per_second; 83 angularVelocity = 0 * radian_per_second; 84 LOG(info) << "drive left"; 85 printf("\r"); 86 break; 87 case KEY_RIGHT: 88 transversalVelocity = -linearVel * meter_per_second; 89 longitudinalVelocity = 0 * meter_per_second; 90 angularVelocity = 0 * radian_per_second; 91 LOG(info) << "drive right"; 92 printf("\r"); 93 break; 94 case 'y': 95 angularVelocity = angularVel * radian_per_second; 96 transversalVelocity = 0 * meter_per_second; 97 longitudinalVelocity = 0 * meter_per_second; 98 LOG(info) << "turn right"; 99 printf("\r"); 100 break; 101 case 'x': 102 angularVelocity = -angularVel * radian_per_second; 103 transversalVelocity = 0 * meter_per_second; 104 longitudinalVelocity = 0 * meter_per_second; 105 LOG(info) << "turn left"; 106 printf("\r"); 107 break; 108 109 default: 110 longitudinalVelocity = 0 * meter_per_second; 111 transversalVelocity = 0 * meter_per_second; 112 angularVelocity = 0 * radian_per_second; 113 LOG(info) << "stop";
99 114 printf("\r"); 115 break; 116 } 117 118 myYouBotBase.setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity); 119 120 refresh(); 121 SLEEP_MILLISEC(100); 122 } 123 124 setVel.angularVelocity = 0 * radian_per_second; 125 myYouBotBase.getBaseJoint(1).setData(setVel); 126 myYouBotBase.getBaseJoint(2).setData(setVel); 127 myYouBotBase.getBaseJoint(3).setData(setVel); 128 myYouBotBase.getBaseJoint(4).setData(setVel); 129 130 endwin(); 131 SLEEP_MILLISEC(500); 132 133 } catch (std::exception& e) { 134 std::cout << e.what() << std::endl; 135 } catch (...) { 136 std::cout << "unhandled exception" << std::endl; 137 } 138 139 return 0; 140 } 7.2. OCTAVE COMPUTER VISION CODE Morphology function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Morphology function %% %% Author: Alberto Justo Lobato %% %% %%
100 e %% Bachelor's Graduation Thesis: %% %% E-waste material classifier with KUKA youBot and %% %% computer vision %% %% %% %% Vilnius Gediminas Technical University , Lithuania %% %% %% %% Explanation: function responsible of applying %% %% morphological operations, in this case dilation, on %% %% two images to obtain differences between each other. %% %% Moreover, we asked users previously for structuring %% %% element size and also number of times to repeat %% %% binarization until they are satisfied with results. %% %% Finally, we get number of elements of image obtained %% %% from this transformation. %% %% %% %% MATLAB/OCTAVE functions used: %% %% -rgb2gray %% %% -graythresh %% %% -imbinarize %% %% -imfilter %% %% -bwconncomp %% %% -imerode %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [T]=myhomography(I,A) if(islogical(I)) disp('Image is already binarized, so it will not be modified') T=I; return end repeat=1;
101 while(repeat==1) umbral=graythresh(I); BW=im2bw(I,umbral); BW2=im2bw(A,umbral); BW2inv=~BW2; BWinv=~BW; radium=input('Introduce radium of structuring element between 1-5: ') ee=strel('disk',radium); % We apply dilation for spliting elements and detecting them B=imerode(BWinv,ee); B2=imerode(BW2inv,ee); L=~B; L2=~B2; figure imshow(I),title('original image'); figure imshow(A),title('testing image'); figure subplot(1,4,1),imshow(BWinv), title('binarized original image') subplot(1,4,2),imshow(L), title('original image with dilation') subplot(1,4,3),imshow(BW2inv), title('binarized test image') subplot(1,4,4),imshow(L2), title('test image with dilation') % We see split objects after transformations cc=bwconncomp(B); % creating two data structures for knowing nº elements a=cc.NumObjects ccs=bwconncomp(B2); as=cc.NumObjects if (a~=as) disp('Number of elements are really different. Second image has mistakes'); myPCB=0; %% we create a variable called myPCB which value is 0 when it has mistakes and 1 when it is in good conditions
108 e %Next step is simplifying all equations TO1=simplify(TO1); TO2=simplify(TO2); TO3=simplify(TO3); TO4=simplify(TO4); TO5=simplify(TO5); %Obtaining components of our main point r13=TO5(1,3); r23=TO5(2,3); r33=TO5(3,3); 2. Inverseorientation.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Forward kinematics function %% %% Author: Alberto Justo Lobato %% %% %% %% Bachelor's Graduation Thesis: %% %% E-waste material classifier with KUKA youBot and %% %% computer vision %% %% %% %% Vilnius Gediminas Technical University, Lithuania %% %% %% %% Explanation: thanks to this function, we obtain %% %% KUKA youBot parameters for decoupling from 5 DOF to %% %% 3 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 function [myxc,myyc,myzc]=inverseorientation(x,y,z,l5,l6,Q1,Q2,Q3,Q4) %Applying symbolic forward equations r13=cos(Q1)*sin(Q2+Q3+Q4); r23=sin(Q1)*sin(Q2+Q3+Q4); r33=cos(Q2+Q3+Q4); %Position of the point Oc myxc=x-(l5+l6)*r13; myyc=y-(l5+l6)*r23; myzc=z-(l5+l6)*r33; end 3. Inverseposition.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Inverse kinematics position function %% %% Author: Alberto Justo Lobato %% %% %% %% Bachelor's Graduation Thesis: %% %% E-waste material classifier with KUKA youBot and %% %% computer vision %% %% %% %% Vilnius Gediminas Technical University, Lithuania %% %% %% %% Explanation: thanks to this function, we obtain %% %% KUKA youBot angles, putting equations obtained in %% %% theorical part %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 e function [Q2,Q3,D2]= inverseposition(XC,YC,ZC,L1,L2,L3,L4) D=((XC.^2+YC.^2- 2*sqrt(XC.^2+YC.^2)*L1 +L1.^2)+(ZC-L2).^2-13.^2- 14.^2)/(2*13*14); D2=1-D.^2; if D2<0 Q3=0; Q2=0; else Q3=atan2(sqrt(1-D.^2),D); Q2=atan2((sqrt(xc.^2+yc.^2)-L1),ZC-12)- atan2(14*sin(Q3),L3+L4*cos(Q3))); end end
111 8. APPENDIXES 8.1. KUKA YOUBOT ARM SPECIFICATIONS
112 e
113
114 e
115 8.2. MAXON JOINT MOTORS
116 e 8.3. SIEMENS MV440 CAMERA SPECIFICATIONS
117