165
UNIVERSITY OF OSLO Department of Informatics An Autonomous and Vendor Independent Robot-based Palletizing System Master thesis (60 sp). Master in Electronics and Computer Technology, Microelectronics / Robotics and Intelligent Systems. Sigurd Salvesen August 10, 2009

An Autonomous and Vendor Independent Robot-based Palletizing

Embed Size (px)

Citation preview

Page 1: An Autonomous and Vendor Independent Robot-based Palletizing

UNIVERSITY OF OSLODepartment of Informatics

An Autonomous andVendor IndependentRobot-basedPalletizing System

Master thesis (60 sp).Master in Electronicsand ComputerTechnology,Microelectronics /Robotics andIntelligent Systems.

Sigurd Salvesen

August 10, 2009

Page 2: An Autonomous and Vendor Independent Robot-based Palletizing
Page 3: An Autonomous and Vendor Independent Robot-based Palletizing

Abstract

Robots has during the last decades taken an important role in the industry.These industrial robot systems are doing predefined jobs over and over again.One typical example is a palletizing system, where robots are used to pick uppackages from the end of a production line, and thereafter placing it on a palletfor the hence of transport. Many problems could occur, like for instance whatto do when new and unknown packages of different size and shapes occursat irregular intervals at the production line? The system may not tackle this.Situations like this could be dangerous for humans.

A robot could be looked at with three aspects - mechanical, electrical andsoftware. The latter one can be unnecessarily complicated since the robot man-ufactures often develop their own programming languages and developmenttools. This gives the robot manufactures control over their products, whichis positive in many ways, e.g. stability, security, performance etc. From aconsumer’s view this unfortunately tends to be quite expensive - only highlyqualified personnel could install and upgrade the system and you may not usespare parts or new products from other robot manufactures.

With the goal to develop an autonomous robot-based system that shouldtackle these problem, the task is divided into three parts:

Robot frameworks - The system should be able to support robots from dif-ferent manufactures with as little adjustment as possible. Therefore the controlsystem is moved to a standard computer. What are the pros and cons? Whatabout the lack of standards for robot communication and control in the roboticindustry?

Vision system - To be able to tackle new and unknown packages of differentsize and shapes occurring at irregular intervals at the production line theyhave to be detected in some way. The implemented vision system uses twostandard webcams, in contrast to more traditional machine vision solutionswhere special sensors and sophisticated cameras are used. Its task is to detectnew packages, and measure their height, width and depth.

Packing algorithms - Traditional pallet loading systems place packages bysome predefined schemes. Since the system should be autonomous, a algo-

I

Page 4: An Autonomous and Vendor Independent Robot-based Palletizing

rithm for automatically generating a good pallet scheme (in reasonable time) isimplemented.

The control system and vision system is developed mainly using the Cycling’74 Max and Jitter for the graphical interface, vision system and state machine,and Java for the packing algorithms and robot communication (SOAP). It hasbeen emphasized to create objects that can easily be modified or replaced whenneeded.

The presented solution could run under Microsoft Windows and Mac OS X ondifferent hardware. The robot communication has to be replaced or modifiedif another robot than Motoman NX100 and the NX100 robot controller is to beused.

II

Page 5: An Autonomous and Vendor Independent Robot-based Palletizing

Preface

This report describes my work undertaken for my Master Degree in Electron-ics and Computer Technology, Microelectronics from the University of Oslo.The work is handed out at the research group Robotics and Intelligent Systems(ROBIN) at the Department of Informatics.

First of all, I would like to thank my supervisor, Associate Professor MatsHøvin, for excellent guidance, creative inputs, and for always inspiring me.Thanks also to my co-supervisor, Associate Professor Omid Mirmotahari, forhis constructive inputs and guidance whenever Mats was not around.

Last, but not least, I want to thank my family and my dear Ragnhild Mariefor their support and for always believing in me.

Sigurd SalvesenAugust 10, 2009

Oslo

III

Page 6: An Autonomous and Vendor Independent Robot-based Palletizing

IV

Page 7: An Autonomous and Vendor Independent Robot-based Palletizing

Contents

1 Introduction 11.1 Background for the Thesis . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Goals for the Thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Introduction to Robotics . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 Introduction to Vision Systems . . . . . . . . . . . . . . . . . . . . . . 21.5 Introduction to Packing Algorithms . . . . . . . . . . . . . . . . . . . 31.6 Thesis Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.7 Short Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Background 52.1 Robotics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.1.1 Programming Robots . . . . . . . . . . . . . . . . . . . . . . . . 52.1.2 Vendor Specific Software . . . . . . . . . . . . . . . . . . . . . . 62.1.3 Microsoft Robotics Developer Studio . . . . . . . . . . . . . . 62.1.4 Real-Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.1.5 Product Example: FPT Standard Palletizer . . . . . . . . . . . 7

2.2 Vision Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.2.1 Traditional Machine Vision . . . . . . . . . . . . . . . . . . . . 10

2.3 The Pallet Loading Problem . . . . . . . . . . . . . . . . . . . . . . . . 102.3.1 Traditional Pallet Schemes . . . . . . . . . . . . . . . . . . . . . 122.3.2 The Distributor’s Pallet Packing Problem . . . . . . . . . . . . 122.3.3 Manufacturer’s Pallet Loading Problem . . . . . . . . . . . . . 122.3.4 Fundamental Heuristics and Algorithms . . . . . . . . . . . . 12

3 Used Tools 153.1 Motoman IA20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.1.1 Working Area & Physical Dimensions . . . . . . . . . . . . . . 163.1.2 Technical Facts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.1.3 Package Gripper . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

3.2 Motoman NX100 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.2.1 Communication Features . . . . . . . . . . . . . . . . . . . . . 18

V

Page 8: An Autonomous and Vendor Independent Robot-based Palletizing

3.2.2 Additional Features . . . . . . . . . . . . . . . . . . . . . . . . . 193.2.3 Touch Screen Pendant . . . . . . . . . . . . . . . . . . . . . . . 19

3.3 Cycling ’74 Max/MSP/Jitter . . . . . . . . . . . . . . . . . . . . . . . . 193.3.1 Introduction to Max . . . . . . . . . . . . . . . . . . . . . . . . . 203.3.2 Introduction to Jitter . . . . . . . . . . . . . . . . . . . . . . . . 213.3.3 Robot Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.3.4 Pure Data - An Alternative to Max . . . . . . . . . . . . . . . . 24

3.4 Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.4.1 Why Choose Java? . . . . . . . . . . . . . . . . . . . . . . . . . . 253.4.2 Java Runtime in Max . . . . . . . . . . . . . . . . . . . . . . . . 263.4.3 Sun Java Real-Time System . . . . . . . . . . . . . . . . . . . . 26

3.5 SOAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273.5.1 Skeleton of a SOAP Message . . . . . . . . . . . . . . . . . . . . 273.5.2 Sample SOAP Messages . . . . . . . . . . . . . . . . . . . . . . . 28

4 Robot Control System 294.1 System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.2 Moving Software from Specialized Hardware to a Standard Per-

sonal Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.2.1 Quality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.2.2 Needs for Real-Time . . . . . . . . . . . . . . . . . . . . . . . . 32

4.3 Selecting Development Framework . . . . . . . . . . . . . . . . . . . . 324.3.1 Microsoft Robotics Developer Studio . . . . . . . . . . . . . . 324.3.2 Cycling ’74 Max and Jitter . . . . . . . . . . . . . . . . . . . . . 33

4.4 Graphical User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 344.5 State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

4.5.1 The States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.5.2 Concurrency and Synchronization . . . . . . . . . . . . . . . . 354.5.3 Global Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4.6 Robot Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . 394.6.1 Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . 394.6.2 Programming the Robot Controller . . . . . . . . . . . . . . . 404.6.3 Communication Handler - A Max External . . . . . . . . . . . 42

4.7 Pick and Place Packages . . . . . . . . . . . . . . . . . . . . . . . . . . 434.7.1 A Test Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

4.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

5 Vision System 495.1 Traditional Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495.2 A Two Camera Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

5.2.1 Camera 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

VI

Page 9: An Autonomous and Vendor Independent Robot-based Palletizing

5.2.2 Camera 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515.2.3 Pseudocode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

5.3 Camera Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525.4 Detecting Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

5.4.1 Known Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 545.5 Measuring Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

5.5.1 Relative Depth and Width . . . . . . . . . . . . . . . . . . . . . 565.5.2 Absolute Height, Depth, Width and Position . . . . . . . . . . 595.5.3 Failed Attempts . . . . . . . . . . . . . . . . . . . . . . . . . . . 595.5.4 Known Errors and Problems . . . . . . . . . . . . . . . . . . . . 65

5.6 Test Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665.6.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

5.7 Summary and Discussion . . . . . . . . . . . . . . . . . . . . . . . . . 69

6 Packing Algorithms 716.1 Fitness of Packing Algorithms . . . . . . . . . . . . . . . . . . . . . . . 716.2 Overview of Java Classes . . . . . . . . . . . . . . . . . . . . . . . . . . 72

6.2.1 PalletConfig - Searching after Packing Schemes . . . . . . . . 736.3 Next Fit - A First Attempt . . . . . . . . . . . . . . . . . . . . . . . . . 74

6.3.1 Pseudocode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756.3.2 Java Implementations . . . . . . . . . . . . . . . . . . . . . . . 756.3.3 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

6.4 Next Fit With Row Rotation . . . . . . . . . . . . . . . . . . . . . . . . 766.4.1 Java Implementation . . . . . . . . . . . . . . . . . . . . . . . . 766.4.2 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

6.5 A Block Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 786.5.1 Pseudocode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796.5.2 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

6.6 Test Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806.7 PalletHandler - A Max External . . . . . . . . . . . . . . . . . . . . . . 816.8 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

6.8.1 Pallet Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836.8.2 3D View of the Pallet . . . . . . . . . . . . . . . . . . . . . . . . 83

6.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

7 Conclusions 857.1 Robot Control System . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

7.1.1 Max for Robot Control . . . . . . . . . . . . . . . . . . . . . . . 857.1.2 Standardization . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

7.2 Vision System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867.3 Packing Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

VII

Page 10: An Autonomous and Vendor Independent Robot-based Palletizing

8 Further Work 878.1 Robot Control System . . . . . . . . . . . . . . . . . . . . . . . . . . . . 878.2 Vision System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 878.3 Packing Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

A Source Code 89A.1 Robot Communication Handler . . . . . . . . . . . . . . . . . . . . . . 89A.2 NX100 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97A.3 Packing Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98A.4 Max Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122A.5 Max Patchers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123A.6 JavaScripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

Bibliography 149

VIII

Page 11: An Autonomous and Vendor Independent Robot-based Palletizing

List of Figures

2.1 Product example: FPT Standard Palletizer (©FPT [4]) . . . . . . . . . 82.2 Some topics related to vision systems . . . . . . . . . . . . . . . . . . 92.3 An example of an advanced modern vision system: Mars Explo-

ration Rover with stereo sight (NASA/JPL/Cornell University) . . . 112.4 Illustration of the Next Fit heuristic and a block algorithm . . . . . 13

3.1 Motoman IA20 robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.2 Motoman IA20’s dimensions [6] . . . . . . . . . . . . . . . . . . . . . 173.3 Motoman IA20’s working area [6] . . . . . . . . . . . . . . . . . . . . 173.4 Remote device for the Motoman NX100 robot controller . . . . . . 183.5 Motoman NX100 robot controller - Dimensions [9] . . . . . . . . . . 193.6 Max/Jitter example: Subpatch "video_grab" . . . . . . . . . . . . . . 203.7 Max/Jitter example: Patcher Mode . . . . . . . . . . . . . . . . . . . . 223.8 Max/Jitter example: Patcher Mode - Locked . . . . . . . . . . . . . . 223.9 Max/Jitter example: Patching presentation . . . . . . . . . . . . . . . 233.10 Max’s Java Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

4.1 System overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.2 Main window of the control system developed in Max (patch: robot-

based_pallet_loading_system) . . . . . . . . . . . . . . . . . . . . . . . 344.4 The state controller patch (patch: state_controller) . . . . . . . . . 354.3 Flowchart over the system . . . . . . . . . . . . . . . . . . . . . . . . . 364.5 State synchronization (patch: semaphore) . . . . . . . . . . . . . . . 374.6 State synchronization (patch: semaphore2) . . . . . . . . . . . . . . 374.7 Source code NX100-program with semaphore illustration . . . . . 404.9 Place package (patch: robot_place_package) . . . . . . . . . . . . . . 454.8 Pick package (patch: robot_pick_package) . . . . . . . . . . . . . . . 464.10 A test setup with the 7 axis Motoman IA20 snake robot . . . . . . 47

5.1 Vision overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515.2 Camera control window (patch: camera_control) . . . . . . . . . . . 535.3 Grab video matrix (patch: grab_above) . . . . . . . . . . . . . . . . . 54

IX

Page 12: An Autonomous and Vendor Independent Robot-based Palletizing

5.4 Demonstration of the principle of optical flow. Generated by DougHatfield (Wikipedia [22]). . . . . . . . . . . . . . . . . . . . . . . . . . . 55

5.5 Detect package (patch: vision_detect_package) . . . . . . . . . . . . 555.6 Measure aspect ratio depth vs. width (patch: vision_measure_depth 575.7 Results of morphological operations: a) Original image. b) Dilated

image. c) Eroded image. d) Closed image. e) Opened image. . . . . 585.8 Video input type: normal (patch: large_view) . . . . . . . . . . . . . 595.9 Video input type: black & white (patch: large_view) . . . . . . . . . 605.10 Video input type: threshold (patch: large_view) . . . . . . . . . . . . 605.11 Video input type: open (patch: large_view) . . . . . . . . . . . . . . . 615.12 Video input type: binedge (patch: large_view) . . . . . . . . . . . . . 615.13 Large preview of camera 1 (patch: large_view2) . . . . . . . . . . . . 625.14 Measure height and width (patch: vision_measure_width_height) . 635.15 Calculate height (calc_height) . . . . . . . . . . . . . . . . . . . . . . . 635.16 Calculate width (patch: calc_width) . . . . . . . . . . . . . . . . . . . 645.17 Measure depth (patch: calc_depth) . . . . . . . . . . . . . . . . . . . . 645.18 Calculate placement (patch: calc_placement) . . . . . . . . . . . . . 645.19 OpenCV error message . . . . . . . . . . . . . . . . . . . . . . . . . . . 655.20 A test setup of the vision system . . . . . . . . . . . . . . . . . . . . . 675.21 White box used during tests of the vision system . . . . . . . . . . . 685.22 Milk used during tests of the vision system . . . . . . . . . . . . . . 68

6.1 Packing scheme - Next Fit . . . . . . . . . . . . . . . . . . . . . . . . . 746.2 Packing scheme - Next Fit with all packages rotated . . . . . . . . . 746.3 Packing scheme - Next Fit with optimal row rotation . . . . . . . . . 776.4 Packing scheme - 4 block algorithm . . . . . . . . . . . . . . . . . . . 796.5 4 block structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806.6 Packing algorithm in Max (patch: package_find_placement) . . . . 826.7 2D view of a pallet scheme . . . . . . . . . . . . . . . . . . . . . . . . . 836.8 3D view of a pallet with one package . . . . . . . . . . . . . . . . . . 846.9 3D view of a pallet with many packages . . . . . . . . . . . . . . . . 84

A.1 Max patch: robotbased_pallet_loading_system . . . . . . . . . . . . 123A.2 Max patch: state_controller . . . . . . . . . . . . . . . . . . . . . . . . 124A.3 Max patch: semaphore . . . . . . . . . . . . . . . . . . . . . . . . . . . 124A.4 Max patch: semaphore2 . . . . . . . . . . . . . . . . . . . . . . . . . . 125A.5 Max patch: camera_control . . . . . . . . . . . . . . . . . . . . . . . . 126A.6 Max patch: grab_above . . . . . . . . . . . . . . . . . . . . . . . . . . . 127A.7 Max patch: video_preview_above . . . . . . . . . . . . . . . . . . . . . 127A.8 Max patch: grab_front . . . . . . . . . . . . . . . . . . . . . . . . . . . 128A.9 Max patch: video_preview_front . . . . . . . . . . . . . . . . . . . . . 128

X

Page 13: An Autonomous and Vendor Independent Robot-based Palletizing

A.10Max patch: vision_detect_package . . . . . . . . . . . . . . . . . . . . 129A.11Max patch: visualizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129A.12Max patch: vision_measure_depth . . . . . . . . . . . . . . . . . . . . 130A.13Max patch: video_preview . . . . . . . . . . . . . . . . . . . . . . . . . 131A.14Max patch: large_view . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131A.15Max patch: vision_measure_width_height . . . . . . . . . . . . . . . 132A.16Max patch: video_preview2 . . . . . . . . . . . . . . . . . . . . . . . . 133A.17Max patch: large_view2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 133A.18Max patch: calc_height . . . . . . . . . . . . . . . . . . . . . . . . . . . 134A.19Max patch: calc_width . . . . . . . . . . . . . . . . . . . . . . . . . . . 134A.20Max patch: calc_depth . . . . . . . . . . . . . . . . . . . . . . . . . . . 134A.21Max patch: calc_placement . . . . . . . . . . . . . . . . . . . . . . . . 135A.22Max patch: package_find_placement . . . . . . . . . . . . . . . . . . . 136A.23Max patch: simulation_add_packages . . . . . . . . . . . . . . . . . . 137A.24Max patch: add_package_group . . . . . . . . . . . . . . . . . . . . . . 137A.25Max patch: add_package . . . . . . . . . . . . . . . . . . . . . . . . . . 137A.26Max patch: random_numbers . . . . . . . . . . . . . . . . . . . . . . . 138A.27Max patch: activate_input . . . . . . . . . . . . . . . . . . . . . . . . . 138A.28Max patch: add_package_settings . . . . . . . . . . . . . . . . . . . . 139A.29Max patch: empty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139A.30Max patch: simulation_pallet . . . . . . . . . . . . . . . . . . . . . . . 140A.31Max patch: robot_pick_package . . . . . . . . . . . . . . . . . . . . . . 141A.32Max patch: x1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142A.33Max patch: y1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142A.34Max patch: z1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142A.35Max patch: rotation1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143A.36Max patch: z2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143A.37Max patch: robot_place_package . . . . . . . . . . . . . . . . . . . . . 144A.38Max patch: x3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145A.39Max patch: y3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145A.40Max patch: z3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145A.41Max patch: rotation3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146A.42Max patch: z4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

XI

Page 14: An Autonomous and Vendor Independent Robot-based Palletizing

List of Tables

5.1 Items used during tests of the vision system . . . . . . . . . . . . . 665.2 Test results of the vision system . . . . . . . . . . . . . . . . . . . . . 66

6.1 Test results of the packing algorithms . . . . . . . . . . . . . . . . . 81

XII

Page 15: An Autonomous and Vendor Independent Robot-based Palletizing

Chapter 1

Introduction

1.1 Background for the Thesis

Loading packages on a pallet for transport was traditionally a job carried out byhumans beings. The job could often be heavy and monotonous. During the lastdecades industrial robots of various kind has replaced the human operators.There are several benefits to be gained, like reduction in number of employees,avoid monotone and non-ergonomics working position, higher speed and per-haps higher quality (in the means that the work is done the exactly same wayover and over again).

There are however some disadvantages to this robotification. Fore the firstthe robot are often programmed to place just known types of packages byfollowing some kind of placing-map of the pallet made in advance. Advancedruntime algorithms for generating such placing-maps may even find new andbetter solution than a human brain could come up with.

Traditional robotic systems perform only predefined tasks. When unfore-seen conditions arise the robot (hopefully) stops. If not, it could be dangerousto its surroundings, which may include people. One of the most typical exam-ple perhaps of such a system - a robot-based system for loading packages on apallet, is the basis of this thesis.

1.2 Goals for the Thesis

The project’s goal is to evaluate a control system for automatically handlingpackages from a production line, and placing them on a pallet. The system ormore precise an experimental version of it, will be developed as a part of thisthesis for the evaluation purpose. One of the goals is to look at possibilities for

1

Page 16: An Autonomous and Vendor Independent Robot-based Palletizing

making the system autonomous. This means that the system should be ableto find solutions to unfamiliar problems. Primary to this is to find out howpacket handling and placement can be conducted even if there is new types ofpackages arriving at the production line. A system like this could be used inthe manufacturing industry, which creates large quantities of the same product.Algorithms for this problem area is known under the term The Manufacturer’sPallet Loading Problem (MPLP).

The second goal is to make the control system vendor and platform inde-pendent. Many robot manufacturers use their own standards and create theirown programming languages and development tools. This makes the develop-ment process and upgrades unnecessarily expensive since it often only couldbe handled by high-skilled technicians. It is desirable that the control systemshould be vendor independent when it comes to such things as computers, op-erating systems and cameras. Robots from different vendors with necessaryadjustments should be easy to take in use.

1.3 Introduction to Robotics

The word robot was introduced by the Czech artist Josef Capek, and was laterpopularized by his brother Karel Capek in the play Rossum’s Universal Robots(R.U.R.) in 1920 [16]. The word robota derives from robota which means workin Czech [13].

The Robotics Institute of America (RIA) has the following definition of arobot: "A robot is a reprogrammable multifunctional manipulator designed tomove material, parts, tools, or specialized devices through variable programmedmotions for the performance of a variety of tasks." [12]. From a technical pointof view Jazar [12] describes robots as complex, versatile devices that contain amechanical structure, a sensory system, and an automatic control system.

Industrial robots has during the last decades replaced more and more work-ers in the industry. Employees doing monotone and repeated tasks could easilyto be replaced by robots. The robots could do these tasks even faster end bet-ter, which in addition to reduced salary costs by time can be quite profitable.As the technology develops, more complex work could be handed by robots.

1.4 Introduction to Vision Systems

A robot has to interact with its environment to be able to do its job. To beable to interact, the robot must be able to sense necessary information from

2

Page 17: An Autonomous and Vendor Independent Robot-based Palletizing

its environment. Robotics applications needs to "see" where to pick and placeobjects, measure distance etc.

Traditionally different types of sensors have been used in robotics applica-tion [13]. Today these have often been replaced with low-priced and powerfuldigital camera chips. Since computing resources normally is not a limit, all thistogether makes computer vision one of the most powerful sensing modalitiesthat currently exists.

From a digital camera source an object can be detected by its shape, colouror combination of shape and colour [1].

1.5 Introduction to Packing Algorithms

Packing is often done by some predefined schemes which tells where to placepackages on the pallet. These schemes traditionally has to be designed andthereafter loaded into the robot control system. Thereby the system has to beupdated at least every time a new package is introduced.

There are two main categories of packing problems; The Distributor’s PalletPacking Problem (DPPP) and The Manufacturer’s Pallet Loading Problem (MPLP).The first one is the problem of loading a pallet of inhomogeneous packagescoming off a production line, while in the latter one the packages are equallysized.

The search space for these problems can be quite enormously...The main reason for searching for new and better packing algorithms is to

reduce shipping costs.

1.6 Thesis Overview

In the following chapter more detailed and related background material forrobotics, computer vision and packing algorithms will be discussed.

A control system for the robot is presented in chapter 4, including statemachine and robot communication. In addition you will also find an overviewof the project as a whole.

The 5th chapter deals with the vision system. A solution based on twostandard webcams associated with processing in Max will be presented.This isfollowed by a chapter about package algorithms, which includes implementa-tions of simple packet algorithms, and issues related to run-time generation ofnew palletizing schemes.

In the last two chapters you’ll find suggestions for further work, and a sum-mary and a conclusion.

3

Page 18: An Autonomous and Vendor Independent Robot-based Palletizing

1.7 Short Conclusion

A control system for the robot is implemented in Cycling ’74 Max/MSP/Jitterwith some components written in JavaScript and Java. The vision system istightly integrated into the control system, and uses 2 standard webcams todetect and measure the size of arriving packages. Finally, a runtime genera-tion of palletizing schemes functionality is also added, with both 2D and 3Dvisualization.

The system has been more vendor independent, since most of the code isplaced on a standard modern computer. The implementation is attempted de-velop as abstract as possible. All this will (hopefully) result in that the requiredproduct specific adaptations will be as small as possible.

The autonomic advantages of the system is that it can detect new types ofpackages and automatically generate palletizing schemes of good quality.

All source code and screenshots of the Max patches can be found in theappendix at the end of this thesis.

4

Page 19: An Autonomous and Vendor Independent Robot-based Palletizing

Chapter 2

Background

This thesis covers three different research fields; robotics control systems, ma-chine vision and packing algorithms. Each of them will be presented in thischapter.

2.1 Robotics

Robotics has a lot in common with computer science and programming, but itis often found to have a high barrier to enter because the term interoperabilitydoesn’t exist. Every robot vendor often makes their own robots with specializedrobot controllers, programming languages, development software etc. There isa lack of reusable components, basically since no standard hardware or hard-ware abstractions exist. Concurrent and distributed programming is hard andis a necessary part in most robotics software projects. Testing in the real-worldis excessively costly and advanced simulation can be complex.

In this project I will try to make a vendor independent system where it wouldbe possible to replace hardware (robot, PC, cameras) and operating system, andstill reuse as much as possible of the code.

2.1.1 Programming Robots

Controlling robots traditionally includes advanced mathematics (kinematics)for moving the robot to a defined place in a defined path.

Modern robots often have the possibility for moving the robot by giving X,Y and Z-coordinates. In a XYZ-coordinate system one define the X, Y and Z axisdata for placing the robot head, while the Tx, Ty and Tz axis data are used torotate the tool mounted on top of the robot’s head.

5

Page 20: An Autonomous and Vendor Independent Robot-based Palletizing

2.1.2 Vendor Specific Software

Most robot manufacturers keep their software hidden [21]. It is impossible tofind out how most robots are programmed. And it is almost as if they had nosoftware in many cases. This is because these companies do not intend theircustomers to do their own programming and they sell complete proprietaryapplication packages rather than general purpose software.

There is very little doubt that robots will be powered by PC technology -even on the industrial side, we are seeing more and more robots that use PC-based technology. As this industry moves forward it will take advantage oftechnology that already exists on the PC.

In computer science the term interoperability describes the ability of soft-ware and hardware on different machines from different vendors to share data.At the time being this term seems to be non-existing within the robot industry.

2.1.3 Microsoft Robotics Developer Studio

One of the newest vendor independent development frameworks for roboticsis the Microsoft Robotics Developer Studio (MRDS) [11]. It makes use of stan-dard programming languages like C#, with some add-ons for required robotfacilities. The main benefits could be summarized as follows:

• Reusable components: Introduces a paradigm with reusable components(web-services) that facilitates reuse.

• Standardization: Introduces a hardware abstraction paradigm.

• Concurrency and distributed computing: Introduces Concurrency and Co-ordination Runtime (CCR) and Decentralized Software Services (DSS) forsimplifying such tasks.

• Simulation: An advance physical simulation package, making it possibleto program robots without having access to one.

• Visual programming: Makes the advanced features more accessible tonewcomers.

Concurrency and Coordination Runtime

The Concurrency and Coordination Runtime (CCR) makes it simple to writeprograms to handle asynchronous input from multiple robotics sensors andoutput to motors and actuators. It enables programmers to create applicationsthat have a high level of synchronicity, so several processes can run in parallel.

6

Page 21: An Autonomous and Vendor Independent Robot-based Palletizing

In the modern computer technology when you have multicore computers,and the ability to really use this new type of computing power depends onprogrammers being able to write applications that can have their parts runningwith a high level of concurrency. CCR is designed with this aim.

Decentralized Software Services

Decentralized Software Services (DSS) is a lightweight .NET-based runtime en-vironment that sits on top of the Concurrency and Coordination Runtime. Itprovides a state-oriented service model that combines the notion of representa-tional state transfer with a system-level approach for building high-performance,scalable applications.

Reuse of Services

In MRDS you can build high-level functions using simple components, provid-ing for reuse of code modules as well as better reliability and replaceability. Forexample, a lower-level sensor service could be integrated into a navigation ser-vice. This is done mainly by creating and programming web-services. It is easyto imagine that such web-services often completely or partly can be reused,modified or replaced later.

2.1.4 Real-Time

Many developers typically think that real-time means "really fast" as in moment-to-moment interaction with the system. Real-time means the ability to reliablyand predictably respond to a real-world event. So real-time is more about tim-ing than speed, but of course many real-time systems are quite fast! The abilityto program a real-time solution means that developers need the appropriatesupport from the system in order to reason in a temporal fashion. Withoutsuch support, this can be very time consuming, if not impossible.

In an robotic installation real-time may be important for handling criticalactuators or sensors. Especially when it comes to safety, and communicationwith other robots or systems.

2.1.5 Product Example: FPT Standard Palletizer

As an example of a modern palletizing system, I’ve picked the FPT StandardPalletizer [4] (see figure 2.1 on the following page), which is a state of the artpalletizing system. It is a complete system including software, robot, claw etc.

7

Page 22: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 2.1: Product example: FPT Standard Palletizer (©FPT [4])

The manual says: "Easy creation/retrieval of the palletizing scheme by meansof the user-friendly FPT Flex Pack software" [4].

Could it be possible to let the packing algorithms generate the palletizingscheme by by itself? Is it possible to create software that can run on differentcomputers, and manage a robot from almost any manufacturer?

2.2 Vision Systems

Of our five senses is vision undoubtedly what we are most dependent on. Com-puters are not able to "see" in the same way as us. While people can rely oninference systems and assumptions, computers must "see" by examining theindividual pixels of images, processing them and try to develop conclusions. Avision system may be used to recognize and locate objects, and perhaps theirmotion. Object can be detected by its shape, colour or an combination of shapeand colour [1]. Vision systems covers a lot of areas in computer science, math-ematics and physics (see figure 2.2 on the next page for an overview).

8

Page 23: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 2.2: Some topics related to vision systems

9

Page 24: An Autonomous and Vendor Independent Robot-based Palletizing

Computer vision (CV) is mainly focused on machine-based image process-ing [23]. Machine vision (MV) is the application of computer vision to industryand manufacturing, and often requires input/output devices and computer net-works to control manufacturing equipment such as robotic arms [23].

Machine vision and computer vision systems are capable of processing im-ages consistently, but computer-based image processing systems are typicallydesigned to perform single, repetitive tasks, and despite significant improve-ments in the field, no machine vision or computer vision system can yet matchsome capabilities of human vision in terms of image comprehension, toleranceto lighting variations and image degradation.

For this project the machine vision system will be used to detect new pack-ages and measure their sizes. In this way the system does not have to knowwhat types of packages that will have to be picked up from the assembly line.

2.2.1 Traditional Machine Vision

A typical machine vision system is often quite technically quite complicatedand consists of many parts. It often consist of one or more camera. A em-bedded processor or a personal computer to process images and sensor data.Analog or digital input/output hardware or communication links to report re-sults. Sensors (optical, magnetic, mechanical) is often used to trigger imageacquisition and processing.

2.3 The Pallet Loading Problem

Packing problems can be thought as an combination of mathematics and puz-zles, and it consists of filling up one or several pallets or containers with asmany packages as possible. This can be done with a search algorithm. A searchalgorithm is an algorithm that takes a problem as input and returns a solutionto the problem, usually after evaluating a number of possible solutions. Theset of all possible solutions to a problem is called the search space, which inpacking problems can be quite enormous.

A brute-force search algorithm searches through the entire search space,which make the process quite time-consuming. Research during the last decadeshave tried to develop informed search algorithms by using e.g. heuristic func-tions to apply knowledge about the structure of the search space, with thepurpose of trying to reduce the amount of time spent searching.

10

Page 25: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 2.3: An example of an advanced modern vision system: Mars ExplorationRover with stereo sight (NASA/JPL/Cornell University)

11

Page 26: An Autonomous and Vendor Independent Robot-based Palletizing

2.3.1 Traditional Pallet Schemes

Packing is often done by some predefined schemes which tells where to placepackages at the pallet. These schemes traditionally has to be designed andthereafter loaded into the robot control system. This makes it necessary toupdate the system every time a new type of package is introduced.

2.3.2 The Distributor’s Pallet Packing Problem

The Distributor’s Pallet Packing Problem (DPPP) is the problem of loading apallet of non-homogeneous items coming off a production line. DPPP is NP-complete which means that it is being complex and difficult to solve within areasonable time span. Common heuristics for the DPPP typically decomposethe problem into two sub-problems; one of pre-scheduling the items on theproduction line and one of packing the items on the pallet.

When it comes to finding the optimal placement of the package at the pallet,there are two main problems. For the first, you may have none or little knowl-edge on the next arriving packages. Secondly the search space for finding anoptimal (or as good as possible) solution is enormous.

2.3.3 Manufacturer’s Pallet Loading Problem

Manufacturer’s Pallet Loading Problem (MPLP) consists on arranging (orthogo-nally and without overlapping) the maximum number of identical (rectangular)packages into a larger rectangle (e.g.. a pallet). Since all the packages are iden-tical you have a complete knowledge of the arriving packages, and you mayconcentrate on finding an optimal packing solution. Although the packing of apallet is a three-dimensional problem, it can be regarded as a two-dimensionaltask since all the layers are equal.

2.3.4 Fundamental Heuristics and Algorithms

There are many algorithms and heuristics for the MPLP. The most fundamentalare the Next Fit (NF) and block algorithms.

Next Fit

The Next Fit (NF) may be used both for the Distributor’s Pallet Packing Problemand the Manufacturer’s Pallet Loading Problem. It has no knowledge about thearriving items. The algorithm may be implemented using a level technique for

12

Page 27: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 2.4: Illustration of the Next Fit heuristic and a block algorithm

arranging the packages in rows. The packages are placed one after one in a rowuntil it is full, and then it will start on a new row. If used on DPPP, the highestitem on the row determines the height of the next row, making the packingfitness worse in cases with large variability in package sizes.

Block Algorithms

The recursive block algorithms is basically dividing a rectangle into regions(normally no more than five) through first-order non-guillotine cuts, as showedin figure 2.4. Packages can be placed inside these blocks. More advanced varia-tions of the algorithm are working recursively for each region. The size given toeach block may have great significance for the outcome of the packing fitness.

13

Page 28: An Autonomous and Vendor Independent Robot-based Palletizing

14

Page 29: An Autonomous and Vendor Independent Robot-based Palletizing

Chapter 3

Used Tools

In this chapter the essential development tools and robotic hardware used inthe experiments will be presented. First, the Motoman IA20 robot is described.The IA20 will later be used to carrying out some practical demonstrations andtests. The IA20 robot is controlled by the Motoman NX100 robot controllerwhich is more thorough described. An NX100 program will later on be devel-oped for being able to control the robot from an computer connected to it.

The Cycling ’74 Max/Jitter framework is also described. Later on an (ma-chine) vision system for package detection and a control system is developedin Max/Jitter. At last the object oriented programming language Java is pre-sented. Java will be used for the communication handling with the robot andsearching for packaging solutions.

3.1 Motoman IA20

The Motoman IA20 robot (see picture 3.1 on the next page) was released latein 2006 [7]. Back then it featured a revolutionary 7-axis actuator-driven designthat enabled amazing freedom of movement [6]. It has a wide area of appli-cations like for instance assembly, packaging, handling machine tending andpart transfer. The standard robot controller used together with IA20 is theMotoman NX100 (see section 3.2 on page 18).

The reason for using Motoman IA20 and NX100 in this project was thatthis robot and robot controller was leased by the research group Robotics andIntelligent Systems (ROBIN) at the University of Oslo during 2008/2009 for otherresearch projects.

15

Page 30: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 3.1: Motoman IA20 robot

3.1.1 Working Area & Physical Dimensions

This "snake robot" has the ability to maneuver in very tight areas. And withits space-saving design, it can straighten out vertically to take up only onesquare foot of floorspace or straighten out horizontally at a height of about twofeet above the floor. All this together allows the manipulator to be positionedbetween machines or out of the normal working area in a floor-, ceiling or wall-mounting configuration. IA20’s physical dimensions is described in figure 3.2on the next page. The vertical reach is as much as 159.8 cm. An detailedoverview over its working area is described in figure 3.3 on the facing page.

3.1.2 Technical Facts

The IA20 robot has a 20 kg payload which should be suitable for most packag-ing installations. And its accuracy of repeatability of �0.1 mm should be quitesufficient.

3.1.3 Package Gripper

In the experimental setups there wasn’t a gripper available at the lab. Howeverthe IA20 has great possibilities for carrying different types of grippers, like forinstance a vacuum claw. As you can see in figure 3.2, there are available airhoses and user wiring connectors that could be used to control an gripper.

16

Page 31: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 3.2: Motoman IA20’s dimensions [6]

Figure 3.3: Motoman IA20’s working area [6]

17

Page 32: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 3.4: Remote device for the Motoman NX100 robot controller

3.2 Motoman NX100

The IA20 robot is controlled by the Motoman NX100 [6] robot controller thatfeatures a robust PC architecture, Windows CE programming pendant and IN-FORM III programming language. The PC architecture [8] offers high-speedprocessing, unmatched memory (60,000 steps, 10,000 instructions). It easilyhandles multiple tasks, and has an ability to control up to FOUR robots and I/Odevices from a single point of control. It also has a built-in collision detection.

3.2.1 Communication Features

The available interfaces are RS-232C and Ethernet [9]. The latter one makes itpossible to access the controller via HTTP, FTP and OPC. It also supports anoptional web server that allows remote monitoring and diagnosis through theInternet or a local network. It has also Fieldbus support of the 15 most commonbrands on the market.

18

Page 33: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 3.5: Motoman NX100 robot controller - Dimensions [9]

3.2.2 Additional Features

The NX100 achieves high-performance path accuracy and vibration control, us-ing improved Advanced Robot Motion (ARM) control algorithms. Best-in-classpath planning features dramatically reduce teaching time. The NX100 uses theenhanced INFORM II programming language [5].

3.2.3 Touch Screen Pendant

With the user friendly touch screen pendant (see figure 3.4 on the precedingpage) running Windows CE operating system, one will have full control of therobot, with complete access to all operations from programming to mainte-nance. The 6.5" full colour LCD touch-screen display and the possibility to cre-ate one’s own user menus eliminates the need for a separate operator’s panel.

3.3 Cycling ’74 Max/MSP/Jitter

Max/MSP/Jitter is an interactive graphical programming environment mainlyused for music, audio and media. Compatible with both Mac and Windows,

19

Page 34: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 3.6: Max/Jitter example: Subpatch "video_grab"

Max/MSP/Jitter provides true cross-platform development. A free runtime ver-sion and the possibility of create standalone applications makes it possible todistribute the software easily.

Max/MSP/Jitter is three things:

• Max is a graphical programming environment that provides user interface,timing, communications and MIDI support.

• MSP for real-time audio synthesis and DSP.

• Jitter for video and matrix data processing.

For the user these three elements appears as one unit, since all the pro-gramming and running the application is done within the same window(s). Thedirect sound-related parts of the software, such as MSP and MIDI support willnot be used in this project (of natural causes).

3.3.1 Introduction to Max

Programming with Max is done in a graphical environment with components(built-in or self-made) that can be added and connected together. This wayof programming instead of conventional programming languages makes Maxextremely visual and interactive. A smooth learning curve makes it possible

20

Page 35: An Autonomous and Vendor Independent Robot-based Palletizing

for non-programmers to immediately start programming. For small projectsthe development time is short. But as with conventional programming, morecomplicated applications will take a lot longer.

A Max document, called a "patcher", can be thought of as a complete audioor video program. But the programs need the Max runtime to run. Max isalso capable of building "stand-alone" applications, which can be executed oncomputers that don’t have Max installed. The application then includes the Maxkernel and the external objects used. Max operates as an interpreter, callingthe native code of external objects according to how they are connected andused in the patcher. The objects are executed right-to-left, then bottom-to-top.Connected objects are executed by a depth-first traversal. The "bang"-message,a trigger signal, is essential in Max, and can be used to create automated orself-running actions in the programs.

The objects that the user fits together to make a patcher are segments ofcode that perform specific functions such as numerical calculations, manipu-lating text, processing audio signals or video matrices. There are objects forinputting and outputting for example video data (see the "jit.dx.grab"-object infigure 3.6 on the facing page), so a patcher can operate as a complete appli-cation. Many of the objects supplied in the Max library are designed as user-interface components: Buttons, sliders, number boxes and so on. Connect aset of objects together by lines or "patch cords", and one will have a real-timeprocessing graph, which might implement something as simple as a stopwatchor a more complicated system.

You can make your own objects, often called externals, using JavaScript,Java or C. JavaScript is the quickest way of making your own objects, and it canbe programmed from Max.

Max provides two distinct ways of organizing and viewing a patcher. InPatcher Mode (see figure 3.7 on the next page) objects are assembled and con-nected with patch cords, and when the patcher is "locked" (see figure 3.8 on thefollowing page) it operates as a user interface via knobs, dials and other GUIobjects. Presentation Mode (see figure 3.9 on page 23) gives you the ability formaking a prettier/simpler design to your application. You select which objectsto view, and can re-size the objects. There are no visible inlets, outlets or patchcords.

3.3.2 Introduction to Jitter

Jitter extends the Max/MSP with real-time manipulation of video and other datasets. In Max/MSP/Jitter all signals are numbers, and since Jitter abstracts alldata as multidimensional matrices, it can most likely use the same objects for

21

Page 36: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 3.7: Max/Jitter example: Patcher Mode

Figure 3.8: Max/Jitter example: Patcher Mode - Locked

22

Page 37: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 3.9: Max/Jitter example: Patching presentation

processing image, audio, 3d vertices’s or any numerical information you canget into the computer.

Jitter is tightly integrated with Max’s graphical programming environmentwhich lets you visually connect data processing objects together with patch-cords to create custom applications. This visual framework provides the powerto build your own unique video effects or whatever your heart desires. In fig-ure 3.7 on the facing page, objects like "jit.rgb2luma" and "jit.op" shows howeasily video can be processed.

Jitter has a great interoperability since it let you easily grab data from videostream, stored movies or connected cameras (see the "jit.dx.grab"-object in fig-ure 3.6 on page 20).

cv.jit - A Collection of Vision Objects

The cv.jit objects are a collection of Max/MSP/Jitter tools for computer vi-sion applications. Its goal is to simplify tasks such as image segmentation,shape and gesture recognition, motion tracking, etc. As you see in figure 3.7on the facing page, edge detection can easily be handed out by the object"cv.jit.binedge".

The collection is based on OpenCV, which is a cross-platform computer vi-sion library originally developed by Intel [19]. It focuses mainly on real-timeimage processing. OpenCV is a open source software .

23

Page 38: An Autonomous and Vendor Independent Robot-based Palletizing

3.3.3 Robot Control

To my knowledge there are little or none research on using Max for robot con-trol in industrial environments. But some research experiments have used Maxin social interaction and performance related robotic installations [14].

In chapter 4 on page 29 Max’s suitability for robotics will be discussed.

3.3.4 Pure Data - An Alternative to Max

Many of the features and ideas from Max are copied into other sound program-ming software. The Open Source project Pure Data [2] (or pd˜ is maybe themost prevalent. Since it is Open Source its free to use. The disadvantages orreasons for not using it in this project as I see it are:

• Lack of (good) documentation.

• The graphical interface is quite bad compared to Max 5.

• C, C++ or FORTRAN (which all are compiled languages) can be used towrite your own objects. Support for a high-level scripting language likeJavaScript would be desirable since it can reduce development time anddoes not have to be compiled.

• The video part doesn’t seem fully comparable to Jitter (hard to tell be-cause of lack of documentation).

• Fewer object available online.

• Max has an great benefit with its watchpoints and debugging possibilities.

On the other hand it is free to use and it is available for Linux. And since it isOpen Source you can study and modify if you want to. Maybe some day Max/M-SP/Jitter, Pure Data and other tools will be interoperable, making it possible toshare objects.

3.4 Java

Java is an object oriented programming language originally developed at SunMicrosystems [18]. Java applications are typically compiled to bytecode thatcan run on any Java Virtual Machine (JVM) regardless of computer architecture.Officially platforms are available for Microsoft Windows, Linux, Mac OS X andSolaris.

24

Page 39: An Autonomous and Vendor Independent Robot-based Palletizing

The syntax of Java is largely derived from C++, but has fewer low-level fa-cilities. Unlike C++, Java was built almost exclusively as an object orientedlanguage. All code is written inside a class (see listing 3.1) and everything is anobject, with the exception of the intrinsic data types.

Graphical user interfaces can relatively easily be made using e.g. the Swinglibrary.�

1 /*2 * Outputs " Hello , World ! " to the terminal , and then e x i t .3 */45 public class HelloWorld {6 public stat ic void main ( String [ ] args ) {7 System . out . println ( " Hello , world ! " ) ;8 }9 }� �

Listing 3.1: HelloWorld example in Java

For a quick introduction to Java programming in Max, you can take a lookat the built-in tutorials or the manual "Writing Max External in Java" [3].

3.4.1 Why Choose Java?

Java, as a programming language, lends itself nicely to rapid prototyping be-cause it is an object oriented language which often promotes code reuse. Onecan take advantage of the features from the standard class libraries, and all thecodes available on the Internet to quickly provide new and desired functional-ity.

Java also handles memory management for one with its built-in garbage col-lector, so one does not need to worry about memory allocation issues presentin C. Java externals are cross-platform. This means that one only need to de-velop and maintain one single binary file for distribution. The same file canbe used for both the Windows and OS X versions of Max. This saves a lot ofprogramming and testing time.

On the other side, since Java is running on a Virtual machine machine, thereare no official low-level facilities like USB and RS-232 available that works onall operating systems.

Another advantage is that Max provides a simple integrated developmentenvironment that allows one to interactively program and compile Java exter-nals without ever leaving the Max patch.

25

Page 40: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 3.10: Max’s Java Runtime

3.4.2 Java Runtime in Max

Accessing the functionality of Java externals in a Max patcher is slightly differ-ent than accessing the functionality of a Max external written in C. C externalsare loaded directly into the Max application environment at runtime, but Javaexternals are loaded into the Max environment and thereafter communicatewith the Max environment through a proxy external object called mxj [3].

mxj is a Max external written in C that interacts with an instance of theJava Virtual Machine (JVM) within the Max environment, and provides the gluethat allows calls from Max to be dispatched to one’s Java code through the JVMand vice versa [3]. Only one JVM is ever created over the lifetime of your Maxapplication and all mxj instances share this single JVM instance to execute theirgiven functionality. This is illustrated in figure 3.10.

3.4.3 Sun Java Real-Time System

In robotic systems there will often be a need of hard real-time. The Sun JavaReal-Time System (Java RTS) is Sun’s commercial implementation of the Real-Time Specification for Java [15]. Implementations of the RTSJ makes standardJava technology more deterministic and enable it to meet rigorous timing re-quirements for mission-critical real-time applications. At the time being Java

26

Page 41: An Autonomous and Vendor Independent Robot-based Palletizing

RTS is only available for Solaris operating system and some Linux distributions.

3.5 SOAP

SOAP, originally defined as Simple Object Access Protocol, is a protocol spec-ification for exchanging structured information in the implementation of WebServices in computer networks [24]. It relies on Extensible Markup Language(XML) as its message format. It also usually relies on other Application Layerprotocols like Remote Procedure Call (RPC) and HTTP for message negotiationand transmission.

The advantages for using SOAP in this experiment is that it is both platformand language independent. And using SOAP over HTTP allows easy communi-cation through proxies and firewalls.

On the other side the main disadvantage may be that SOAP is built on top ofthe verbose XML format. This may result in that fact that SOAP (in some cases)can be considerably slower than competing middleware technologies such asCORBA [24].

3.5.1 Skeleton of a SOAP Message

The construction of a SOAP message is outlined in listing 3.2.�1 <?xml version=" 1.0 " ?>2 <soap:Envelope3 xmlns:soap=" http: //www.w3. org/2001/12/soap�envelope "4 soap:encodingStyle=" http: //www.w3. org/2001/12/soap�encoding ">56 <soap:Header>7 . . .8 </soap:Header>9

10 <soap:Body>11 . . .12 <soap:Fault>13 . . .14 </soap:Fault>15 </soap:Body>1617 </soap:Envelope>� �

Listing 3.2: Skeleton SOAP message

27

Page 42: An Autonomous and Vendor Independent Robot-based Palletizing

3.5.2 Sample SOAP Messages

Listing 3.3 shows an example of a SOAP message of type request, which sendsthe request for the share price of the IBM stock. The response to this requestmessage is received in the form of a response message. This is illustrated inthe listing 3.3.�

1 <?xml version=" 1.0 " ?>2 <soap:Envelope3 xmlns:soap=" http: //www.w3. org/2001/12/soap�envelope "4 soap:encodingStyle=" http: //www.w3. org/2001/12/soap�encoding ">56 <soap:Body xmlns:m=" http: //www. example . org/stock ">7 <m:GetStockPrice>8 <m:StockName>IBM</m:StockName>9 </m:GetStockPrice>

10 </soap:Body>1112 </soap:Envelope>� �

Listing 3.3: Sample SOAP message: Request�1 <?xml version=" 1.0 " ?>2 <soap:Envelope3 xmlns:soap=" http: //www.w3. org/2001/12/soap�envelope "4 soap:encodingStyle=" http: //www.w3. org/2001/12/soap�encoding ">56 <soap:Body xmlns:m=" http: //www. example . org/stock ">7 <m:GetStockPriceResponse>8 <m:Price>34.5</m:Price>9 </m:GetStockPriceResponse>

10 </soap:Body>1112 </soap:Envelope>� �

Listing 3.4: Sample SOAP message: Response

28

Page 43: An Autonomous and Vendor Independent Robot-based Palletizing

Chapter 4

Robot Control System

This chapter starts with an overview of the project and its goals. This is fol-lowed by a discussion of what development framework to select, platform in-teroperability and selection of hardware in terms of e.g. operational stability.

The control system software that have been developed will be presented anddiscussed. The vision system for detecting and measuring packages and pack-ing algorithms will be presented more thoroughly in the following chapters.

4.1 System Overview

The goal of this project is to develop an experimental release of an autonomousand vendor independent robot-based palletizing system. It is necessary with anadvanced system to be able to control the robot. This system could be dividedinto many parts, and the main parts are the control system, vision system forpacket detection and run-time algorithms for generating pallet schemes. Eachof these parts can again be split into several smaller parts. An abstract overviewof the system is illustrated in figure 4.1 on the next page.

4.2 Moving Software from Specialized Hardware to aStandard Personal Computer

Traditionally, the control systems of robot installations have been developed torun completely or partially on an appropriate robot controller, a programmablelogic controller (PLC) [26] or other types of specialized hardware. Such hard-ware can be expensive, difficult to replace, and often more complicated andtime-consuming to program. The idea of this project is to move as much aspossible of the control system off the modern computer.

29

Page 44: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 4.1: System overview

30

Page 45: An Autonomous and Vendor Independent Robot-based Palletizing

The aims of this are:

• Reduce cost (cheaper hardware, and faster / easier programming).

• A more vendor independent system.

• Easier to obtain replacement parts.

• Easier to deploy new hardware and robots.

• Greater degree of reusable code.

4.2.1 Quality

By using standard modern hardware it will probably be far easier to replace anydefective parts. This may increase the systems uptime. But if the electronicparts of such a system have worse quality, it is not inconceivable that theseparts often must be replaced more frequently.

This may be a contradiction to the manufacturers of robot controllers orPLCs, which often add prestige to only select the best component and testingthe product properly in relevant / extreme environments.

There are many terms and standards describing hardware quality. In sys-tems like this the term Mean time to failure (MTTF) which measures the averagetime between failure with the modeling assumption that the failed system is notrepaired. [20].

The following things should be taken into account by the use of moderncomputers in an industrial setting:

• Hard disk drive - Failures may occur.

• Fan - The system often need continuous cooling

• Hardware quality / testing.

There are also on the industry-based issues that modern computers are de-signed for high uptime and placement in more extreme environments. Suchcomputers can run standard operating systems, and often have the same op-portunities for IO.

31

Page 46: An Autonomous and Vendor Independent Robot-based Palletizing

4.2.2 Needs for Real-Time

Specialized hardware and software designed for industrial applications oftenhave built a good support for e.g. hard real-time, in contrast to many operatingsystems on modern computers that in the best case support soft real-time.Microsoft Windows XP is an example of an operating system that is consideredas soft real-time compatible [10].

Cycling ’74 Max/MSP/Jitter is often referred to as a real-time system. Maybethe description could be run-time passed better, but Max is maybe soft real-time, since it never can have "stronger" real-time facilities than the underlyingoperating system. For processes that require high priority Max has somethingcalled overdrive, which allows for other (and often heavier) processes down-graded.

In this project, there are no processes that stand out with a clear need forhard real-time. But in projects where it is found to be necessary, it may beappropriate to place such tasks (e.g. critical sensor handling) in the softwareplaced on the robot controller.

4.3 Selecting Development Framework

Manufacturers of modern industrial robots, which usually develops their owndevelopment frameworks for users to program their robots. In addition, theyoften also develop their own programming languages. All in all, this meansone must have specific knowledge about the actual robot, robot controller andsoftware. On the other hand, these things can make the robot’s potential beexploited to the full.

4.3.1 Microsoft Robotics Developer Studio

Microsoft Robotics Developer Studio (MRDS) is probably among the very latestreleased development tools for robot systems. MRDS has many advantages ina project like this since it is intended to function as a framework for all kindsof robots from all manufacturers. The widely used programming language C#can be used, in addition to several other programming languages. MRDS alsocontains libraries with relevant features like concurrency and synchronization(see section 2.1.3 on page 6), and also distribution of tasks on different devicesand processors (see section 2.1.3 on page 7).

The development is done mainly by creating and programming web-servicesfor the features one want to have. It is easy to imagine that such web-servicesoften completely or partly can be reused later. In addition, it will be easy to

32

Page 47: An Autonomous and Vendor Independent Robot-based Palletizing

replace a Websters for example if one wish to use another robot or other typeof vision system.

There are no weighty reasons why MRDS is not used in this project (apartfrom the experimentation of the pilot), since it has everything required of func-tionality. In the experimental pilot stage of the project I experienced problemswith the stability of webcams in MRDS. The same was experienced by otherpeople’s research group. In addition, there was a solid expertise of the groupand associated research project on the use of Cycling’74 Max, including robotcontrol.

Another reason not to choose MRDS is that at the time being is only officialsupport for the Windows platform.

4.3.2 Cycling ’74 Max and Jitter

Cycling’ 74 Max/Jitter (Max) is not designed to be a robot development tools.But Max has many interesting features such as:

• Graphical user interface.

• Reusable objects, with a wide range of objects and libraries available onthe Internet.

• Seamless use of the IO (cameras, sensors, etc).

• Excellent opportunities for advanced image processing in a simple man-ner.

• Visualization facilities using OpenGL.

• High degree of interoperability - running on both Windows and Max OS X.

• Good opportunity for expanded functionality using JavaScript, Java andC.

The choice fell on Max mainly because of the growing competence of theresearch group and Robotics Intelligent Systems at the Department of Infor-matics, University of Oslo. It is also interesting to see whether Max can be usedfor such purposes or not.

33

Page 48: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 4.2: Main window of the control system developed in Max (patch: robot-based_pallet_loading_system)

4.4 Graphical User Interface

When programming in Max, all or some of the visual objects used when pro-gramming constitute the user interface. This project has not focused very muchon the user interface, so the user interface the user sees is the same as the"programing code" with all the objects and the cables drawn between them. Inthis way it is easier to understand and analyze the system. The user interfaceshould be improved using in the presentation mode if any final version shouldbe developed.

The main window of the control system developed in this project can beseen in figure 4.2. The figure gives an overview of the whole system. Eachsubpatch is clickable if the user wants to adjust settings etc.

4.5 State Machine

A palletizing system has many tasks or processes that will be implemented foreach package to be handled. To get an overview of all the processes and need

34

Page 49: An Autonomous and Vendor Independent Robot-based Palletizing

of concurrency it beam necessary to draw a flowchart (see figure 4.3 on the nextpage).

4.5.1 The States

The six conditions as outlined in the flow chart is implemented in Max. Theresult of this you can see in figure 4.4. The four red or conditional decisionboxes that contains a YES / NO question are in two of the cases implementedusing a delay object, but in the last two cases some synchronization patcheshad to be made.

Figure 4.4: The state controller patch (patch: state_controller)

4.5.2 Concurrency and Synchronization

Process synchronization refers to the idea that multiple processes are to joinup or handshake at a certain point, so as to reach an agreement or commit to acertain sequence of action [27].

As mentioned, two sub-patchers were made to easily deal with synchroniza-tion (see figure 4.5 on page 37 and 4.5 on page 37). Their task is to ensure thatthe next state is not activated before both the two previous have finished.

35

Page 50: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 4.3: Flowchart over the system

36

Page 51: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 4.5: State synchronization (patch: semaphore)

Figure 4.6: State synchronization (patch: semaphore2)

37

Page 52: An Autonomous and Vendor Independent Robot-based Palletizing

Java Implementation

Since a synchronization was needed, a subpatch for such a propose had to bemade. Its task should be to hold the status of the two ongoing states, andenable the next state when both are finished. The easiest solution I found wasto make a Max external in Java:�

1 private boolean left Input = false ;2 private boolean rightInput = false ;34 public void bang ( ) {5 int inlet_num = get Inlet ( ) ;67 i f ( inlet_num == 0) { // leftBang8 left Input = true ;9 } else i f ( inlet_num == 1) { // rightBang

10 rightInput = true ;11 } else i f ( inlet_num == 2) { // a l lFa l se12 left Input = rightInput = false ;13 }1415 i f ( left Input && rightInput ) {16 left Input = rightInput = false ;17 outlet (0 , "bang" ) ;18 }19 }� �

Listing 4.1: Parts of the Semaphore external (for the entire class see listing A.17on page 122)

The bang() method is called from Max every time a new value is submit-ted one of its inlets. The actual inlet where it received the bang message cantell whether a state has finished or the system should be reset. When bothstates have finished, a bang message is sent to Max through its outlet. This willactivate the next state.

4.5.3 Global Data

All use of the send (s) and receive (s) objects to send data is not controlledby the state or states that are active. In many ways such data can be viewedas global data. One must therefore be very particular that only the intendedstates are able to read the sent values. Probably can an advanced solution bemade (patcher or external) with the aim to buffer the data until a new state isactivated, but it can have impact on the simplicity of the system.

38

Page 53: An Autonomous and Vendor Independent Robot-based Palletizing

This problem can be called data synchronization which refers to the ideaof keeping multiple copies of a data set in coherence with one another, or tomaintain data integrity [25].

4.6 Robot Communication

As mentioned earlier, there has been a desire to try to minimize the vendor andproduct-specific code. The main reason is that this code rarely can be reused,in addition, it is often more time-consuming to program. The main idea is toput as little code as possible at the robot controller, since this code is quiteproduct specific.

4.6.1 Synchronization

In order to synchronize the robot control process on the computer with therobot controller, so one need a synchronization mechanism. With use of thissynchronization mechanism the computer could tell the robot to move to thenew position, in addition to knowing whether the robot has completed themovement or not.

For this purpose a (distributed) shared memory communication solutionhas been selected. Since the data memory for NX100 can easily be accessed viaSOAP, and internally on the NX100 it can be read by using simple commands.A solution with a common semaphore have been chosen in this project.

This semaphore is active low, which means that if nothing happens with therobot, the shared variable holds the value 1. When new position variables aresent from the computer to the robot. Then the robot should move to the newposition since the semaphore variable is given the value 0. The robot controlleris continuously reading the semaphore whenever the robot is not moving to anew position. Once the value has been set to 0 it starts the movement of therobot to the new position. When the robot has finished the movement, the robotcontroller sets the semaphore variable equal to 1 again. The computer whichis waiting for the robot to finish moving and therefore continuously reads thesemaphore, will now know that the robot has finished.

How the semaphore synchronization is implemented on NX100 is shown infigure 4.7 on the next page.

Disadvantages

The probably most significant disadvantage with this implementation is thatthe computer continuously sends SOAP messages to request the value of the

39

Page 54: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 4.7: Source code NX100-program with semaphore illustration

semaphore while it waits for the robot to finish. This has probably taken someamount of CPU usage at the robot controller, and thus, it is conceivable thatthe robot movement calculations which done by the robot is executed slower.The ideal solution would be if the SOAP server at the robot controller couldbe set up to first answer the SOAP message when the robot has stopped mov-ing. It is uncertain whether this is possible on the NX100, and it is probably acomplicated job if even possible.

4.6.2 Programming the Robot Controller

The goal is to minimize the required code for robot control. Since the Motomanrobot controller NX100 and the IA20 robot can be controlled in an XYZ coordi-nate system, we must be able to send over X, Y and Z values. Moreover, it mustalso be possible to rotate the claw so that packages can be rotated if necessary.The last feature which is clearly necessary to control, is the status of the claw,in terms of whether it should be open or closed.

It is conceivable that it could be desirable with the ability to send and setdata like e.g. the robot’s movement speed. Such extensions are no problem toadd in the developed solution, since there are available variables at the robotcontroller that can be set via SOAP.

40

Page 55: An Autonomous and Vendor Independent Robot-based Palletizing

Pseudocode

�1 set claw position horizontal2 set semaphore high34 loop forever :5 wait while semaphore is high67 copy new position and rotation from shared memory8 move to new position and rotation9

10 copy gripper status from shared memory11 open/ close gripper1213 set semaphore high� �

Listing 4.2: Pseudocode for NX100 program

Listing 4.2 shows the pseudo code for the NX100 program. The first thingthat happens is that the position variables that control the robot’s head, is setto a horizontal position. Then the shared semaphore is given the value 1, whichmeans that the robot is ready to receive data from the computer.

Then follows the eternal loop (see line 4 in listing 4.2) which is repeateduntil the program is stopped manually at the robot control. The loop is notexecuted as long as the semaphore is high, but starts processing the contentsof the loop immediately when the semaphore has been set to active low.

What follows next in the loop is that the position and rotation values thatwere sent from the computer is copied from the shared memory area over tothe robot controller’s own memory area for position variables. The robot thenmoves to the new position. The gripper status is then copied from the sharedmemory area over to the robot controller’s own memory area. The robot theneither opens or closes the gripper.

At the end of the loop the semaphore value is set to 1. In this way, thecomputers know that the robot has completed the move.

Inform II Implementation

The final code developed for the Motoman NX100 robot controller is programmedin Inform II [5]. The source code can be found in figure 4.7 on the facing pageand listing A.5 on page 97.

41

Page 56: An Autonomous and Vendor Independent Robot-based Palletizing

4.6.3 Communication Handler - A Max External

In order to communicate with the robot from Max, an external called RobotComwas made. Its task is to collect all relevant data from Max, put it into a SOAPmessage and then send it to the robot. Once the robot is finished with themovement, a bang message is sent to Max.

Pseudocode�1 i n i t i a l i z e SOAP cl ient23 loop forever :4 while ( l as t data not received from Max ) :5 receive data67 set semaphore active low89 pack data and semaphore into a SOAP�message

10 send SOAP�message to robot1112 pack get semaphore into a SOAP�message13 send SOAP�message14 receive and read SOAP�message with semaphore status1516 while ( while semaphore is active low ) :17 send SOAP�message18 receive and read SOAP�message with semaphore status1920 send finished to Max� �

Listing 4.3: Pseudocode for communication handler program

The first thing that happens in the pseudocode for the communication han-dler program (see listing 4.3) is that a SOAP client is initialized. This SOAP clientclass will contain information about the robot’s IP-address and port number,and a sketch of a SOAP message where the data can later can be put into.

Then follows an eternal loop. Inside this loop we can find an another loop.This loop receives various data from Max. When the last data has received,the loop stops. A local semaphore variable is created, and set to active low.Then all the data and the semaphore is put into the SOAP message. Then thismessage is sent to the robot.

Afterwards a SOAP request is sent to the robot in order to get the status ofthe shared semaphore to be able to determine whether the robot has completed

42

Page 57: An Autonomous and Vendor Independent Robot-based Palletizing

or not. This is repeated until a positive response is received.Finally, a message is sent to Max telling that the robot has completed.

Java Implementation

The implemented code differs slightly from the pseudocode in terms. The so-lution is not loop-based, but consists of a method of each type of data that canbe received from Max. The actual method is called each time data is received.These methods have a unique Max-syntax [3].

The Java code for the RobotCom external can be found in listing A.1 onpage 89. An standalone Java class for testing the communication without Maxis to be found in listing A.2 on page 91. When the SOAP client was written I hadno knowledge about the good built-in libraries for SOAP setup in Java, so muchof the code could probably have been made easier and prettier.

Java classes developed:

• RobotCom - A Max external for handling the communication with therobot.

• RobotCommunication - Testing the functionality used from Max.

• SendDataToRobot - Generates a SOAP message with the position data. Thedata is sent to the robot.

• WaitRobotFinished - Waits for the robot to finish (the robot controller setsits semaphore variable low (= 0)).

4.7 Pick and Place Packages

Most articulated robots perform tasks by storing a series of positions in itsmemory, and then moving to them at various times in its program sequence. Inorder to be able to pick packages from the production line, and placing themon the pallet, we must define some positions so the robot can move to where itshould. The following 3 positions (P1-P3) has to be defined in each setup:

• 0 cm above the production line, centered at the end (defined as P1).

• Safely position between the production line and pallet (defined as P2).

• 0 cm above the pallet, the lower right corner (defined as P3).

43

Page 58: An Autonomous and Vendor Independent Robot-based Palletizing

To be able to perform the necessary movements, one have to derive evenmore positions based upon position P1 to P3. These new positions needs datalike package size (height, depth and width), package location on the productionline, and placement on the pallet (XYZ).

• 10 cm above package at the production line (defined as PC1, derived fromP1).

• 0 cm above package at the production line (defined as PC2, derived fromP1).

• Safely position between production line and pallet (defined as PC3, equalto P2).

• 20 cm above package placement position at the pallet (defined as PC4,derived from P2).

• 0 cm above package placement position at the pallet (defined as PC5, de-rived from P2).

Pseudocode

From these positions one can define a pseudocode which can be found in list-ing 4.4. This code snippet provides a good overview of the instructions neededto pick up a package and thereafter placing it on a pallet at a specified place.All this must be done in a safe manner so that we avoid collision with other ob-jects or persons nearby. The code is repeated every time a new package arrivesat the production line.�

1 Open gripper .2 Move to PC1 .3 Move to PC2 .4 Close gripper .5 Move to PC1 .6 Move to PC3 .7 Move to PC4 .8 Move to PC5 .9 Open gripper .

10 Move to PC4 .11 Move to PC3 .� �

Listing 4.4: Pseudocode for robot movement

44

Page 59: An Autonomous and Vendor Independent Robot-based Palletizing

Max Implementation

The Max implementation is illustrated in figure 4.8 on the following page and 4.9.As possible to see in these images, the user can easily set the positions P1, P2and P2. Each of the calculated positions PC1-PC5 has one or more of the classMax external PalletHandler, which collects, and then sends the received data tothe robot.

Figure 4.9: Place package (patch: robot_place_package)

45

Page 60: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 4.8: Pick package (patch: robot_pick_package)

46

Page 61: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 4.10: A test setup with the 7 axis Motoman IA20 snake robot

4.7.1 A Test Setup

A test setup was set up in order to test the robot communication and practicaluse of the robot. Two tables were taken in use under testing, where one shouldimagine a production line, while the other would be a pallet where the packageswere placed. A picture of the setup is shown in figure 4.10.

4.8 Summary

The control system is designed with the aim that it should be as vendor inde-pendent as possible when it comes to integrating a new robot, computer, etc.As much as possible of the required program code has been moved over on astandard modern computer, that can be replaced with any standard computer ifnecessary. At the robot controller, the required code for controlling the robothas been minimized to a minimum. The system is developed in Max, where

47

Page 62: An Autonomous and Vendor Independent Robot-based Palletizing

graphical objects easily can be reused, modified or replaced. The software isdeveloped as abstract as possible. Any robot specific requirements for otherinput data, can be easily modified in the implemented Max external RobotCom.

The autonomic advantages of the system will be more visible when thetightly integrated vision system and automatic generation of palletizing schemesare presented in the two following chapters.

No precise standards for robotics has been proposed in this chapter. Thesolution to this challenge, I believe lies in reusable and replaceable services orobjects, together with a universal and platform independent control system.

One thing that has not been emphasized in this chapter is the benefits fromrobot simulation. Simulation of a robot and its surroundings may ensure atime-saving development process, since you do not need access to the robotto test out new solutions and changes. Such simulations are possible to createin Max since it has built-in support for OpenGL. The disadvantage compared tomore traditional and product specific development tools, is that such tool oftenhave ready-made 3D models of a selection of robots and associated equipment.In Max you have to develop the simulation setup yourself.

48

Page 63: An Autonomous and Vendor Independent Robot-based Palletizing

Chapter 5

Vision System

This chapter begins with looking at the possibility of using two standard web-cams instead of advanced cameras and / or sensors for detecting and measur-ing packages. This is followed by a study of Jitter’s simplicity and suitabilitywhen it comes to image processing and previewing. This is summarized in adiscussion of advantages and disadvantages of the implemented solution.

The vision system has the following two missions:

1. Detect new packages at the production line.

2. Measure their width, height and depth.

In this chapter an attempt for developing an vision system for the earliermentioned goals is presented. The system is developed using Max, Jitter andcv.jit - a collection of Max/MSP/Jitter tools for computer vision applications(see section 3.3.2 on page 23). The vision software is an integrated part of thecontrol system presented earlier (see figure 4.2 on page 34). On the left handside of the figure you can see the package detection part, and second and thirdfrom left one can find the measuring parts.

5.1 Traditional Solutions

As described in section 2.2 on page 8, vision systems for industrial systemsoften tends to be advanced and consist of hardware that may be both expensiveand difficult to replace.

There are several solutions to this problem and the solution one choose willvary from one installation to another. The best solution perhaps, which is thefastest and safest in the production is to get the package size from e.g. a PLC.This PLC then needs to retrieve values about the package from a previous place

49

Page 64: An Autonomous and Vendor Independent Robot-based Palletizing

in the process. But this solution require industrial / specialized hardware, andthat communication must operate at all times.

In an automated production, you can usually know the package’s dimen-sions from product range, barcode, sensors, or a predefined production orderfrom the production machine. In some cases it may also know which produc-tion or assembly line the package comes from, as by a limited range of packagescan tell us what type of package that has arrived.

One can find very advanced camera for sale, with built-in processor(s) thatcan calculate and give one all the values one wants, and then transfer themto the robot controller. But these cameras often cost a lot of money, and theintegration between the camera and robot can offer some unfamiliar challengeseach time which also cost money. Very few customers are interested in payingfor an expensive camera solution if it is possible to retrieve information fromanother location without using a camera.

5.2 A Two Camera Solution

In this experiment two standard webcams, which one could find in a everydayelectronic store will be used. The first camera is placed above the productionline, while the second camera is placed in front of the of the production line.The first camera will detect new packages and measure the aspect ratio betweenthe package’s depth and width, while the latter one will measure its height andwidth.

The presented solution is illustrated in figure 5.1 on the facing page. Place-ment of each of the cameras will be explained and discussed in the two follow-ing sections.

5.2.1 Camera 1

The first idea was to make this camera measuring the depth of the package,but the distance between the camera and the top of the package vary due todifferent package heights. Because of this it is not possible to measure absolutevalues. However, it is possible to measure the aspect ratio between the depthand width of the package. This aspect ratio will later on be used to calculatethe depth in millimeters from the width. Since there was also a need to detectnew packages, this camera received two applications.

As you can see in figure 5.1 on the next page, camera 1 is placed above theproduction line. It is located some to the right to avoid getting in the way ofthe robot picking up packages.

50

Page 65: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.1: Vision overview

5.2.2 Camera 2

As one can see in figure 5.1, camera 2 is placed to the left of the productionline. At the end of the production line, there is a "stopper" which stops thepackage (marked with a red square in the figure). This means that there will bea fixed distance between a package and the camera.

It will be possible to calculate the absolute values of the width and height,given the aspect ratio between a camera pixel and millimeters at the packagefront (see figure 5.2 on page 53 for input field). Once the actual width is mea-sured, it is possible to derive the absolute depth using the aspect ratio betweenthe depth and width.

For calculating the height, a second parameter is needed. Camera 2 willnot be able to capture the whole package (because of the "stopper"), but onlythe upper part. The system needs to know the height difference between theproduction line and the top pixels of the camera in millimeters (see figure 5.2on page 53 for input field).

The black plastic strips that one can see in the figure are there to ensurethat only one package is visible from the camera’s location at the same time, aswell as to achieve a higher contrast between the package and its background.

51

Page 66: An Autonomous and Vendor Independent Robot-based Palletizing

5.2.3 Pseudocode

The following pseudocode gives an overview of the process:�1 loop forever :2 detect new package using camera 134 wait for package to be centered underneath camera 156 measure aspect rat io between depth and width using camera 178 wait for package to stand s t i l l at the end of the production l ine9

10 measure width , height and placement using camera 211 calculate depth from width using aspect ratio , width vs . depth� �

Listing 5.1: Pseudocode vision algorithm

This pseudocode is based upon the criteria presented and explained in thetwo previous sections.

5.3 Camera Control

For setup and configuration a camera control subpatch has been made (seefigure 5.2 on the next page). The most essential task for this subpatch is tocapture video data from two selected cameras. The capturing is done by the twosubpatches (see figure 5.3 on page 54 for the subpatch "p grab"). A new videoframe (called Matrix in Max) is sent every 30 ms. The "settings" button allowsone to adjust any parameter available for the active camera (e.g.. brightnessand white balance).

The video stream is converted into luma, which represents the brightnessin an image. Luma represents the achromatic image without any colour infor-mation. This is done because the detection will not take into account coloursof the packages since one has no knowledge about their colours.

As you can see to the left; the thresholding level can be adjusted for eachof the cameras. Upper right, one can adjust the camera height and the aspectratio between a pixel and real millimeters on the package. The last one istypically handed out by measuring a package width a known width, and adjustthe parameter to get the correct output.

52

Page 67: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.2: Camera control window (patch: camera_control)

53

Page 68: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.3: Grab video matrix (patch: grab_above)

5.4 Detecting Packages

Detecting new packages is done by using motion detection. One way of doingthis is by using optical flow (see figure 5.4 on the next page for an example ofoptical flow). The "cv.jit" collection includes an implementation of the Lucas-Kanade method, a two-frame differential method for optical flow [22]. Withthis implementation it is possible to obtain movement horizontally or verticallyin a given direction. Obtaining a certain movement direction is done by the"jit.unpack" object (see figure 5.5 on the facing page). Thereafter "cv.jit.sum" isused to measure the level of movement. If it is higher than the trigger level, anew package is detected.

5.4.1 Known Problems

The detection algorithm has no knowledge of what it detects beyond that themovement is in the specified direction. This means that everything that maymove within the camera’s image area will be able to trigger a false packagedetection, as long as the movement occurs in the right direction. Selecting anappropriate threshold is therefore crucial to avoid false detections.

54

Page 69: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.4: Demonstration of the principle of optical flow. Generated by DougHatfield (Wikipedia [22]).

Figure 5.5: Detect package (patch: vision_detect_package)

55

Page 70: An Autonomous and Vendor Independent Robot-based Palletizing

5.5 Measuring Packages

Measuring the size of a package can be a difficult task. A package should besignificantly brighter or darker than its surroundings for the computer to beable to recognize it. The package itself often contains darker or brighter areas,making the contrast within a package higher than contrast between the packageand its background. The system should work all the time, not just a set of testpackages. Therefore it is difficult to obtain an adequate training set of images.

The subpatch for measuring the aspect ratio between depth and width ofthe package is measured by the first subpatch (see figure 5.6 on the next page),while the last one measures height, width and position, and calculates thedepth (see figure 5.14 on page 63). There is a time delay in between these twoin order to ensuring that the package stands still at the end of the productionline.

5.5.1 Relative Depth and Width

In the subpatch "vision_calculate_depth" one can find a "switch" object. Thisobject activates and stops the calculations to avoid unnecessary use of theCPU.

The first step in the image processing sequence is that the image is thresh-olded. The thresholding of the camera input is handed out by the object "jit.op"(one can see the result in figure 5.10 on page 60). It converts the video intoON and OFF-pixels based on the threshold value set in the subpatch "cam-era_control". The jit.op object offers a numerous of opportunities in termsof mathematical operations on (video) matrices.

The morphological "cv.jit.open" operation consists of performing erodedand dilated operations successively (see figure 5.7 on page 58 for an overviewover morphological operations). The erode stage removes ON pixel noise, whilethe dilate stage returns the shape to a similar area. This operation will makesmall gaps larger. Hopefully this will give a nicer and more correct shape.

In the search of the item in the picture, all connected components, or blobs,will be numbered by its size. A package has often text or dark areas, givingmany connected components. By first performing edge detection, the packagegets more visible. A simple edge detection where ON-pixels stays ON if theyhave at least one OFF neighbor, is used (see figure 5.12 on page 61. It returnsonly edge pixels in the binary image. In the next step this is used to findand identify the connected components, and marks them with a unique value.Thereafter the largest one is selected. Then the largest connected component(only existing) is found again by "cv.jit.label @charmode 1". Now it is possible

56

Page 71: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.6: Measure aspect ratio depth vs. width (patch: vision_measure_depth

57

Page 72: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.7: Results of morphological operations: a) Original image. b) Dilatedimage. c) Eroded image. d) Closed image. e) Opened image.

58

Page 73: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.8: Video input type: normal (patch: large_view)

for "cv.jit.blobs.bounds" to find the relative depth and width from where thebounding box is placed (see figure 5.13 on page 62 for the bounding box).

The result is visualized, and the bounding box is measured in a JavaScript(source code can be found at A.18 on page 147). The result from this script issent into a number box and sent further to the next state.

5.5.2 Absolute Height, Depth, Width and Position

The procedure is the same as for the depth measuring, but with a few excep-tions. The JavaScript is a little different since it calculates the package’s heightby measuring the distance from the top of the camera and the top of the pack-age. It also calculates the placement / position of the package (source code canbe found at A.19 on page 147).

Thereafter height (see figure 5.15 on page 63), width (figure 5.16), depth(figure 5.17) and placement is converted into absolute values in millimeters(figure 5.18).

The output of a measurement is sent to the control system, and will behandled by the packaging algorithm. It is also visualized with number boxes,making it easy to debug or adjust necessary parameters.

5.5.3 Failed Attempts

During the development stage, some experiments with cv.jit objects, whichmake use of the Hough transform [28] for line detection, was tried out. Thealgorithm was too unstable, so the experiment was laid dead. It is difficult to

59

Page 74: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.9: Video input type: black & white (patch: large_view)

Figure 5.10: Video input type: threshold (patch: large_view)

60

Page 75: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.11: Video input type: open (patch: large_view)

Figure 5.12: Video input type: binedge (patch: large_view)

61

Page 76: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.13: Large preview of camera 1 (patch: large_view2)

62

Page 77: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.14: Measure height and width (patch: vision_measure_width_height)

Figure 5.15: Calculate height (calc_height)

63

Page 78: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.16: Calculate width (patch: calc_width)

Figure 5.17: Measure depth (patch: calc_depth)

Figure 5.18: Calculate placement (patch: calc_placement)

64

Page 79: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.19: OpenCV error message

say anything directly about the causes. One possible explanation could be lowresolution and image quality from the webcams.

5.5.4 Known Errors and Problems

The methods for measuring package sizes have been designed with the primarygoal to demonstrate the opportunities that exist within modern image process-ing techniques and applications, like e.g. Jitter. It is doubtless that solutioncould have been developed with more advanced techniques, e.g. corner or edgedetection or template matching. It would be natural to believe that smallererror margins could have been achieved with such techniques.

Camera Position Limitations

In the image area to the camera, it is only the front of the package that shouldbe visible. Neither the sides nor the top surface of the package should be vis-ible. This could result in the package is measured too wide or too tall. Thecameras must therefore be centered in front of / above the package. The cam-era positions will determine how tall and deep packages that can be measured.This problem could (probably) be avoided if a more advanced algorithm hadbeen implemented.

Problems with OpenCV

Now and then some error messages from OpenCV occurs. OpenCV is the un-derlying vision library which cv.jit is built on top of. The problem appears tobe caused by a memory handling error (see figure 5.19). The system needs tobe restarted afterwards.

65

Page 80: An Autonomous and Vendor Independent Robot-based Palletizing

5.6 Test Results

A test setup was set up in order to be able to test the accuracy of the visionsystem. The test setup can be seen in figure 5.20 on the next page.

The following items (see figure 5.21 on page 68 and 5.22 on page 68 forpictures) was used during the tests:

Item# Item Height Width Depth1 White box, standing 144 mm 96 mm 62 mm2 White box, lying 96 mm 144 mm 62 mm3 Milk 180 mm 71 mm 71 mm

Table 5.1: Items used during tests of the vision system

Item MeasuredDepth/Width

ErrorDepth/Width

MeasuredHeight

ErrorHeight

MeasuredWidth

ErrorWidth

MeasuredDepth

ErrorDepth

1 0,66 1,55 % 143,50 mm -0,50 mm 95,94 mm -0,06 mm 62,94 mm 0,94 mm1 0,66 2,15 % 143,50 mm -0,50 mm 95,60 mm -0,40 mm 63,10 mm 1,10 mm1 0,66 2,74 % 144,10 mm 0,10 mm 96,28 mm 0,28 mm 63,93 mm 1,93 mm2 0,45 4,95 % 98,38 mm 2,38 mm 140,00 mm -4,00 mm 63,42 mm 1,42 mm2 0,45 4,74 % 98,38 mm 2,38 mm 140,00 mm -4,00 mm 63,28 mm 1,28 mm2 0,46 5,37 % 98,38 mm 2,38 mm 141,00 mm -3,00 mm 64,16 mm 2,16 mm3 0,96 -3,95 % 175,30 mm -4,70 mm 77,29 mm 6,29 mm 74,35 mm 3,35 mm3 0,96 -3,84 % 175,00 mm -5,00 mm 77,20 mm 6,20 mm 74,34 mm 3,34 mm3 0,97 -2,99 % 175,30 mm -4,70 mm 77,63 mm 6,63 mm 75,38 mm 4,38 mm3 0,97 -3,41 % 175,30 mm -4,70 mm 77,29 mm 6,29 mm 74,74 mm 3,74 mm

Table 5.2: Test results of the vision system

The vision parameters was calibrated with the first item.

5.6.1 Results

The test result shows that the measuring is quite inaccurate. The large marginof error may, as said earlier, be due to poor algorithm and low low-resolutioncamera (see the poor image quality in e.g. figure 5.13 on page 62).

It is also possible that in some of the calculations made in cv.jit objectsor the underlying OpenCV libraries, uses matrices that are smaller than thecamera resolution. In some of the visualization objects in cv.jit, only a 160x120resolution is used.

66

Page 81: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.20: A test setup of the vision system

67

Page 82: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 5.21: White box used during tests of the vision system

Figure 5.22: Milk used during tests of the vision system

68

Page 83: An Autonomous and Vendor Independent Robot-based Palletizing

5.7 Summary and Discussion

In this chapter have been presented a (possibly new) solution to detect andmeasure packages on a production line, with use of two standard webcams.This solution makes the system more autonomous since it now can detect andmeasure a wide range of package types.

Max and Jitter turns out to have infinite possibilities in video processing inan easy manner. There are none ready-made vision solutions in Jitter. This issomething you can find in advanced development tools for machine vision. Adirect comparison with such software could be interesting.

The results of the test setup shows that the implemented vision system doesnot provide desirable degree of accuracy. There is no clear indicia what marginof error is due. It is assumed that cameras of better quality combined withbetter algorithms, could get the margin of error down to an acceptable level.

Screenshots of all the different patches of the vision system can be found inthe appendix at the end of this thesis.

69

Page 84: An Autonomous and Vendor Independent Robot-based Palletizing

70

Page 85: An Autonomous and Vendor Independent Robot-based Palletizing

Chapter 6

Packing Algorithms

As described in section 2.3 on page 10, packing algorithms is a wide area ofresearch. In this chapter some algorithms for the Manufacturer’s Pallet LoadingProblem (MPLP) is presented, discussed and implemented. The implementationalso contains run-time generating of packing schemes. This is a contradictionto traditional systems where such schemes in most cases are made in advance.Since the MPLP can be thought of as a one layer problem (if all layers can beequal), the algorithm only has to generate a packing scheme for one layer.

A Max external named PalletHandler has been made, and will be presentedin this chapter. PalletHandler handles the run-time packing algorithm. Thepallet schemes are visualized in two dimension, while the pallets are visualizedin three dimensions in run-time. This latter visualization shows where eachpackage is to be placed.

It is assumed that all the packages on the pallet are identical, and the algo-rithm therefore only has to run once for every pallet. This equals to the MPLP.The biggest challenge with the run-time generation of packing schemes is theshort amount of time that is disposal to the search algorithm. This means thatthe algorithm must be quite fast. The first package arriving at the productionline must be picked up before the next package arrives. In the same periodthe algorithm must also have produced a good or optimal scheme, so that thepackage can be placed on the pallet, to avoid packages accumulating on theproduction line.

6.1 Fitness of Packing Algorithms

To compare different packing algorithms and heuristics, we need a basis forcomparison. It can be done in two ways. The first one is to count and comparethe number of packages the algorithms manage to fit onto the pallet. The

71

Page 86: An Autonomous and Vendor Independent Robot-based Palletizing

second alternative is to calculate the percentage of covered area of the pallet.It can be done with the following fitness formula (if all the packages are equal):

Fitness � PackageAreal�NumberOf PackagesPalletAreal

6.2 Overview of Java Classes

The following Java classes have developed working with packing algorithms:

• PalletHandler - A Max external for generating and handling pallet schemes.

• PalletOrganizer - Testing the functionality used from Max.

• PalletSearch - Search for different pallet schemes.

• PalletConfig - An abstract class for holding information of a pallet and itspackages.

• PalletConfigRowRotate (extends PalletConfig) - Class for holding informa-tion of a pallet and its packages. A given number of rows are rotated.

• PalletConfigEqualRotate (extends PalletConfig) - Class for holding infor-mation of a pallet and its packages. All packages are either rotated or notrotated.

• PalletConfigBlockHeuristics (extends PalletConfig) - Class for holding in-formation of a pallet and its packages. 4 blocks of various size eachhandled as an individual pallet.

• Pallet - Holding information of a pallet and its packages. Used for run-time palletizing.

• Package - Holding information of a single package. Used for run-timepalletizing.

• DrawPallet - Visualize a pallet scheme.

• PalletLoadingTest - Main class. Generates different tests.

The most important of these classes will be reviewed in this chapter.

72

Page 87: An Autonomous and Vendor Independent Robot-based Palletizing

6.2.1 PalletConfig - Searching after Packing Schemes

The different search algorithms need a data structure to work on. Since Java isan object-oriented languages, it felt natural to use a class structure. PalletCon-fig is an abstract class with the common methods needed by the algorithms.Here follows a simplified version:�

1 public abstract class PalletConfig {2 . . . // private variables34 PalletConfig ( int palletWidth , int palletDepth , int palletHeight ,5 int packageWidth , int packageDepth , int packageHeight ) {6 . . . // set variables7 }89 public int getPalletWidth ( ) { return palletWidth ; }

1011 public int getPalletDepth ( ) { return palletDepth ; }1213 public int getPackageWidth ( ) { return packageWidth ; }1415 public int getPackageDepth ( ) { return packageDepth ; }1617 abstract public void rotate ( int i ) ;1819 abstract public void rotateAll ( ) ;2021 public f loat getFitness ( ) {22 return ( f loat ) ( getPackageDepth ( )23 * getPackageWidth ( ) * getPacakagesPlaced ( ) )24 / ( getPalletDepth ( ) * getPalletWidth ( ) ) ;25 }2627 abstract public int getPacakagesPlaced ( ) ;2829 abstract public PalletConfig clone ( ) ;3031 abstract public Pa l le t convertToPalletFormat ( ) ;32 }� �

Listing 6.1: PalletConfig - An abstract pallet class for searching algorithms

The convertToPalletFormat() method convert the current object into a objectof the Pallet class. The Pallet class is a run-time palletizing class. It containsinformation of where all the packages should be placed. This makes it possible

73

Page 88: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 6.1: Packing scheme - Next Fit

Figure 6.2: Packing scheme - Next Fit with all packages rotated

to switch packing algorithm easily, if only the new algorithm outputs the resultin this format.

6.3 Next Fit - A First Attempt

The Next fit algorithm is a simple packing algorithm (see section 2.3.4 onpage 12 about Next Fit). An expanded variant of this algorithm was imple-mented as a first attempt to generate packing schemes. The expansion con-sists of the possibility of rotating all packages (see figure 6.1 and 6.2). A fitnesscalculation determines whether the packages should be rotated or not.

74

Page 89: An Autonomous and Vendor Independent Robot-based Palletizing

6.3.1 Pseudocode

The following pseudocode explains how the new packing schemes are gener-ated:�

1 boolean rotate = false23 i f f i tness of rotated scheme > fitness of standard scheme :4 rotate = true56 loop forever :7 i f rotate :8 rotate package9

10 i f enough space on current row :11 place package on current row12 else :13 place package on an new row� �

Listing 6.2: Pseudocode packing algorithm - Next Fit

6.3.2 Java Implementations

The algorithm is implemented in the PalletConfigEqualRotate class (see list-ing A.11 on page 106), which is an extension of the PalletConfig class.

The following code is necessary to determine whether the packets shouldbe rotated or not:�

1 public PalletConfig getBest ( ) {2 PalletConfig reversePal let = this . clone ( ) ;34 i f ( isRotated ( ) )5 reversePal let . rotate ( 0 ) ;6 else7 reversePal let . rotateAll ( ) ;89 i f ( getFitness ( ) > reversePal let . getFitness ( ) )

10 return this ;11 else12 return reversePal let ;13 }� �

Listing 6.3: Next Fit - Find best solution

75

Page 90: An Autonomous and Vendor Independent Robot-based Palletizing

The necessary code snippet for calculating the fitness is straight forward:�1 public int getPacakagesPlaced ( ) {2 int sum;34 i f ( rotated )5 sum = ( palletWidth / packageDepth )6 * ( palletDepth / packageWidth ) ;7 else8 sum = ( palletWidth / packageWidth )9 * ( palletDepth / packageDepth ) ;

1011 i f (sum < 0)12 return 0;13 else14 return sum;15 }� �

Listing 6.4: Next Fit - getPacakagesPlaced()

6.3.3 Discussion

In some cases this algorithm generates a acceptable packing schemes, but notall. The algorithm has a few simple calculations, which makes the algorithmvery fast.

6.4 Next Fit With Row Rotation

With the aim to improve the packing results from the previous algorithm, asecond modification of my own was added; a variable number of rows can berotated. The number of rotated rows will in most cases provide different fitnessresults.

6.4.1 Java Implementation

The algorithm is implemented in the PalletConfigRowRotate class (see listing A.10on page 104), which also extends the PalletConfig class.

76

Page 91: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 6.3: Packing scheme - Next Fit with optimal row rotation

The following code is necessary to determine whether the packets shouldbe rotated or not:�

1 public PalletConfig getBest ( ) {2 PalletConfig bestPal let = this . clone ( ) ;3 PalletConfig currPal let = this . clone ( ) ;45 for ( int i = 0; i <= getMaxRows ( ) ; i ++) {6 currPal let . rotate ( i ) ;78 i f ( currPal let . getFitness ( ) > bestPal let . getFitness ( ) )9 bestPal let = currPal let . clone ( ) ;

10 }1112 return bestPal let ;13 }� �

Listing 6.5: Find the best row rotation

77

Page 92: An Autonomous and Vendor Independent Robot-based Palletizing

Calculating the number of packages that will fit onto the pallet, is slightlymore advanced with optional number of rotated rows:�

1 public int getPacakagesPlaced ( ) {2 int currPosY = 0;3 int packagesPlaced = 0;4 int i = 0;56 // Rotated rows7 for ( ; i < rowsRotated ; i ++) {8 i f ( ( currPosY + packageWidth ) > palletDepth )9 break ;

1011 packagesPlaced += palletWidth / packageDepth ;1213 currPosY += packageWidth ;14 }1516 // None�rotated rows17 for ( ; i < getMaxRows ( ) ; i ++) {18 i f ( ( currPosY + packageDepth ) > palletDepth )19 break ;2021 packagesPlaced += palletWidth / packageWidth ;22 currPosY += packageDepth ;23 }2425 return packagesPlaced ;26 }� �

Listing 6.6: Next Fit - getPacakagesPlaced()

6.4.2 Discussion

This algorithm generates better packing schemes than the previous algorithm.The necessary calculations are still few and simple, which makes the algorithmfast.

6.5 A Block Algorithm

The two preceding algorithms can, in many cases, not find an optimal packingscheme. So I started looking at the possibility of the dividing the pallet into sec-

78

Page 93: An Autonomous and Vendor Independent Robot-based Palletizing

tions. The choice fell on the four sectors (see figure 6.4). After some researchit turned out that this is a fairly common way to solve packing problems. Thenumber of sectors and their shape varies from one algorithm to another.

The idea is that the packages should have an equal rotation inside each ofthe four sectors. The algorithm task then becomes to find the optimal distri-bution of the sizes of the sectors. In order to reduce the otherwise huge searchspace, it is necessary with some interceptions. Therefore, sectors can only havesizes that are a multiple of the package’s width or depth.

Figure 6.4: Packing scheme - 4 block algorithm

6.5.1 Pseudocode

Figure 6.5 on the following page illustrates the four sections of the pallet.The size of the four blocks can be set by the following algorithm:�

1 choose a within the pal let ’ s width2 choose c within a ’ s width3 choose d within the pal let ’ s depth4 choose h within d ’ s depth56 b , e , f and g are given the remaining space� �

Listing 6.7: Pseudocode packing algorithm - A 4 block algorithm

In most cases, it is possible to search through all possible solutions to findthe optimal solution (often called brute force). The size of the search spacedepends on the package size in relation to the pallet size. Larger differenceprovides a larger search space.

Another strategy is to try out random sizes, and select the best result isachieved. With a high number of attempts, will be possible to achieve accept-

79

Page 94: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 6.5: 4 block structure

able results. The algorithm takes the same amount of time regardless of thesize of the search room, but the chance to find an optimal solution is reduced.

6.5.2 Discussion

This algorithm generates better packing schemes than the previous algorithm.The necessary calculations are still few and simple, which makes the algorithmfast.

This algorithm usually produces good or optimal solutions, but it will notalways manage to find the optimal solutions in the most difficult cases.

6.6 Test Results

The test data used by Pureza et al. [17] is used to compare the implementedalgorithms and Pureza et al.’s algorithm.

80

Page 95: An Autonomous and Vendor Independent Robot-based Palletizing

# Packages PlacedPallet Size Package Size Next Fit

Equal Rota-tion

Next FitRow Rota-tion

Block Algo-rithm

Pureza et al. al-gorithm [17]

Max. ExecutionTime, Block Al-gorithm

First order (22, 16) (5, 3) 21 22 22 23* 16 msproblems (57, 44) (12, 5) 33 38 40 41* 16 ms

(86, 82) (15, 11) 35 38 41 42* 15 ms(42, 39) (9, 4) 40 42 44 45* 16 ms(124, 81) (21, 10) 40 42 46 47* 16 ms(40, 25) (7, 3) 40 44 46 47* 16 ms(52, 33) (9, 4) 40 44 46 47* 16 ms(56, 52) (12, 5) 44 45 47 48* 15 ms(87, 47) (7, 6) 84 94 95 97* 16 ms(67, 44) (6, 5) 91 96 97 97* 16 ms

Superior order (43, 26) (7, 3) 48 52 52 53* 16 msproblems (63, 44) (8, 5) 60 64 68 69* 16 ms

(61, 35) (10, 3) 66 70 70 71* 16 ms(61, 38) (6, 5) 72 76 76 77* 16 ms(61, 38) (10, 3) 72 76 76 77* 16 ms(93, 46) (13, 4) 77 81 81 82* 16 ms(141, 71) (13, 8) 85 91 95 96* 16 ms(106, 59) (13, 5) 88 95 95 95 16 ms(74, 46) (7, 5) 90 92 96 96 16 ms(86, 52) (9, 5) 90 96 98 98 16 ms(108, 65) (10, 7) 90 95 99 99 16 ms

Table 6.1: Test results of the packing algorithms

The results marked with * is the optimal number of packages.One can clearly see the improvements from eg. the Next Fit algorithm to the

block algorithm. The block algorithm produces quite good results (keeping inmind that this is a difficult dataset). It also proves to be quick.

6.7 PalletHandler - A Max External

All the algorithms was developed in Java, and thereby an interface to themfrom Max was needed. A Max external called PalletHandler was made (the Javacode can be found in the listing A.6 on page 98). Its task is to generate newpacking schemes, and tell where each packet should be placed. For each packetthat the vision system detects, placement coordinates for the package at palletis sent to Max. These coordinates are used to calculate the robots movements.

6.8 Visualization

Visualization of both the packing scheme and the pallet is needed to be able toeasily analyze the performance of the algorithms.

81

Page 96: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 6.6: Packing algorithm in Max (patch: package_find_placement)

82

Page 97: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 6.7: 2D view of a pallet scheme

6.8.1 Pallet Scheme

The packing schemes is visualized using the Swing library in Java. The Draw-Pallet class (see listing A.15 on page 116) draws the pallet and its packages.

6.8.2 3D View of the Pallet

Max has great support for the use of OpenGL. OpenGL was used to visualizethe pallet and its packages in three dimensions (see figure 6.8 on the next pageand 6.8 on the following page). The implemented solution supports only 100packages, but it should be possible to extend if needed.

6.9 Summary

Three relatively simple algorithms were implemented in Java. The most ad-vanced of them, a block algorithm, is currently used when generating newpacking schemes. The algorithm is robust and relatively quick.

An external Max has been developed to take care of the whole process fromgenerating packing schemes to specify where each and every package is to beplaced on the pallet.

A two and three dimensional visualization of the packing schemes and thepallet, is also implemented.

83

Page 98: An Autonomous and Vendor Independent Robot-based Palletizing

Figure 6.8: 3D view of a pallet with one package

Figure 6.9: 3D view of a pallet with many packages

84

Page 99: An Autonomous and Vendor Independent Robot-based Palletizing

Chapter 7

Conclusions

A control system for the robot is implemented in Max, with some externalswritten in JavaScript and Java. The vision system is tightly integrated into thecontrol system, and uses 2 standard webcams to detect and measure packagesizes. Finally, runtime generation of palletizing schemes functionality is alsoadded, with both 2D and 3D visualization.

7.1 Robot Control System

The control system is designed with the aim that it should be as vendor inde-pendent as possible when it comes to integrating a new robot, computer, etc.As much as possible of the required program code has been moved over on astandard computer, that can be replaced with any standard computer if neces-sary. At the robot controller, the required code for controlling the robot hasbeen minimized to a minimum.

7.1.1 Max for Robot Control

Max is a very flexible development framework, but the target group does notcontain robotic systems. Therefore one has to experiment on one’s own towork out solutions. The needed functionality can mostly be found in Max’swide range of objects. When needs are not be met in Max, the possibility towrite externals JavaScript, Java or C is good to have.

7.1.2 Standardization

No precise standards for robotics have been proposed in this chapter. Thesolution to this challenge, I believe lies in reusable and replaceable services

85

Page 100: An Autonomous and Vendor Independent Robot-based Palletizing

or objects, together with a universal and platform independent control systemplaced on a standard computer.

7.2 Vision System

A (possibly new) solution based on two webcams is presented. These webcamsare used to detect and measure packages. The implementation in Max and Jittershows that there are plenty of opportunities when it comes to video processing.The disadvantage is however that there are none ready-made vision solutionsin Jitter.

The results of the test setup shows that the implemented vision systemdoes not provide desirable degree of accuracy. The results of the test setupshows that the implemented vision system does not provide desirable degreeof accuracy. It is assumed that cameras of better quality combined with betteralgorithms, could get the margin of error down to an acceptable level.

7.3 Packing Algorithms

Three relatively simple algorithms were implemented using Java. The mostadvanced of them, a block algorithm, is currently used when generating newpacking schemes. A two dimensional visualization of the packing schemes anda three dimensional visualization of the pallet, is also implemented.

86

Page 101: An Autonomous and Vendor Independent Robot-based Palletizing

Chapter 8

Further Work

Things take time. This project, covers large research areas such as robotics,code re-usage, interoperability, vision systems and packaging algorithms. Itis clearly many things that could be studied further both in terms of a widerscope and more thorough.

8.1 Robot Control System

It would be desirable to create a collection of Max objects with the functionalityneeded in a robot control system. A simulation framework for robot cells inOpenGL might also be useful.

A comparison between the development methodology, limitations, code re-usage e.g. between Max, Microsoft Robotics Developer Studio and other devel-opment tools could be useful.

8.2 Vision System

More advanced packet recognition algorithms should be implemented in orderto achieve better results in the form of lower error margin. It could also beinteresting to compare Max and Jitter with machine vision frameworks frome.g. NI LabVIEW.

8.3 Packing Algorithms

Optimal packing requires advanced algorithms. Run-time packing also needsfast algorithms. It could therefore be useful to do a deeper study of algorithms

87

Page 102: An Autonomous and Vendor Independent Robot-based Palletizing

suitable for run-time palletizing.Other factors such as the packages weight or the stability of pallet, may be

important in some cases, and should have been looked into.

88

Page 103: An Autonomous and Vendor Independent Robot-based Palletizing

Appendix A

Source Code

This chapter contains all the source code and Max patchers developed duringthis thesis.

A.1 Robot Communication Handler

Listing A.1: RobotCom.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A communication handler for the Motoman NX100 Robot Control ler5 * (SOAP ) .6 * @class RobotCom � A Max object for handling the communication with the robot .7 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .8 * @info Some small parts of the code i s made by Mats Hovin .9 */

1011 public class RobotCom extends MaxObject {12 SendDataToRobot sendData = null ;13 WaitRobotFinished checkFinished = null ;1415 private boolean robotEnabled = false ; // Default : robot disconnected1617 private int xAxis = 0;18 private int yAxis = 0;19 private int zAxis = 0;20 private int rotation = 0;21 private int claw = 0;2223 private stat ic f inal String [ ] INLET_ASSIST = new String [ ] { " in le t 1 help " } ;24 private stat ic f inal String [ ] OUTLET_ASSIST = new String [ ] { " outlet 1 help " } ;2526 public RobotCom( boolean bang , boolean reset , int x , int y , int z ,27 int rotation , int claw , int robot_enabled , String robot_adress ) {28 declareInlets (new int [ ] { DataTypes . ALL , DataTypes . ALL , DataTypes . ALL ,29 DataTypes . ALL , DataTypes . ALL , DataTypes . ALL , DataTypes . ALL ,30 DataTypes . ALL , DataTypes .MESSAGE } ) ;31 declareOutlets (new int [ ] { DataTypes . ALL } ) ;

89

Page 104: An Autonomous and Vendor Independent Robot-based Palletizing

3233 set InletAssist (new String [ ] { "bang to output " , "bang to reset " , "x " ,34 "y" , "z" , " rotation " , " claw " , " robot_enabled " ,35 " robot_adress (URL) " } ) ;36 setOutletAssist (new String [ ] { " finished " } ) ;3738 try {39 checkFinished = new WaitRobotFinished ( ) ; // Get data ( semaphore )40 } catch ( Exception e ) {41 post ( "RobotCom: unhandled error � nxClientGet0 = new NxClientGet0 ( ) ; " ) ;42 post ( " e : " + e ) ;43 }44 }4546 public void bang ( ) {47 int inlet_num = get Inlet ( ) ;48 post ( "RobotCom: banged at : " + inlet_num ) ;4950 i f ( inlet_num == 0) { // bang51 post ( "RobotCom: bang � send data to robot " ) ;52 i f ( robotEnabled ) {53 post ( "RobotCom: Robot connected . " ) ;5455 } else {56 post ( "RobotCom: Robot disconnected . " ) ;57 }5859 post ( "RobotCom: Sending data to robot (bang received from Max ) . " ) ;60 post ( "RobotCom: Data � x : " + xAxis + " | y : " + yAxis + " | z : "61 + zAxis + " | rotation : " + rotation + " | claw : " + claw62 + " | robotEnabled : " + robotEnabled ) ;6364 // Send data to robot65 i f ( robotEnabled ) {66 try {67 sendData . put ( xAxis , yAxis , zAxis , rotation , claw ) ;68 } catch ( Exception e ) {69 post ( "RobotCom: unhandled error � nxClientPutArray . put " ) ;70 post ( " e : " + e ) ;71 }72 }7374 post ( "RobotCom: Waiting for robot to f inish . " ) ;7576 // Waiting for robot to f in i sh77 i f ( robotEnabled ) {78 try {79 checkFinished . waiting ( ) ;80 } catch ( Exception e ) {81 post ( "RobotCom: unhandled error � nxClientGet0 . waiting ( ) ; " ) ;82 post ( " e : " + e ) ;83 }84 }8586 post ( "RobotCom: Robot finished " ) ;8788 outlet (0 , "bang" ) ; // Send finished to Max8990 } else i f ( inlet_num == 1) { // reset91 post ( "RobotCom: reset " ) ;92 }93

90

Page 105: An Autonomous and Vendor Independent Robot-based Palletizing

94 }9596 public void in le t ( int i ) {97 int inlet_num = get Inlet ( ) ;9899 i f ( inlet_num == 2) { // x

100 xAxis = i * 1000;101102 } else i f ( inlet_num == 3) { // y103 yAxis = i * 1000;104105 } else i f ( inlet_num == 4) { // z106 zAxis = i * 1000;107108 } else i f ( inlet_num == 5) { // rotation109 rotation = i * 100;110111 } else i f ( inlet_num == 6) { // claw112 claw = i ;113114 } else i f ( inlet_num == 7) { // robot enabled ( robot connected ? )115 i f ( i == 0)116 robotEnabled = false ;117 else118 robotEnabled = true ;119 }120 }121122 public void in le t ( String s , Atom[ ] l i s t ) {123 int inlet_num = get Inlet ( ) ;124125 i f ( inlet_num == 8) { // robot adress126 i f ( s != null ) { // l i s t . i sS tr ing ( )127 sendData = new SendDataToRobot ( s ) ;128 }129 }130 }131 }� �

Listing A.1: RobotCom.java

Listing A.2: RobotCommunication.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A communication handler for the Motoman NX100 Robot Control ler5 * (SOAP ) .6 * @class RobotCommunication � Testing the funct ional i ty used from Max.7 * @authors Mats Hovin ( matsh@ifi . uio . no ) , Sigurd Salvesen , sigurdsa@ifi . uio . no .8 * @info Original ly code by Mats Hovin . Rewritten & modified by Sigurd Salvesen .9 */

1011 public class RobotCommunication {12 stat ic SendDataToRobot sendData = null ;13 stat ic WaitRobotFinished checkFinished = null ;14 stat ic boolean robotEnabled ;1516 public stat ic void main ( String [ ] args ) throws Exception {17 i f ( args . length >= 1) {18 System . out . println ( "Robot disconnected . " ) ;

91

Page 106: An Autonomous and Vendor Independent Robot-based Palletizing

19 robotEnabled = false ;20 } else {21 System . out . println ( "Robot connected . " ) ;22 robotEnabled = true ;2324 // generating SOAP�messages25 sendData = new SendDataToRobot ( ) ; // Send data26 checkFinished = new WaitRobotFinished ( ) ; // Get data ( semaphore )27 }2829 run ( ) ;30 }3132 // Test functions used from Max33 public stat ic void run ( ) {34 // Run forever35 while ( true ) {36 System . out . println ( "� � � � � � � �" ) ;37 System . out . println ( "Ready for data . " ) ;3839 System . out . println ( " All data received from Max. " ) ;40 System . out . println ( " Sending data to robot . " ) ;4142 // Send data to robot43 i f ( robotEnabled )44 try {45 sendData . put (1 , 1 , 1 , 1 , 1 ) ;46 } catch ( Exception e ) {47 e . printStackTrace ( ) ;48 }4950 System . out . println ( " Waiting for robot to f inish . " ) ;5152 // Waiting for robot to f in i sh53 i f ( robotEnabled )54 try {55 checkFinished . waiting ( ) ;56 } catch ( Exception e ) {57 e . printStackTrace ( ) ;58 }59 }60 }61 }� �

Listing A.2: RobotCommunication.java

Listing A.3: SendDataToRobot.java�1 import com. cycling74 .max . * ;2 import java . io . * ;3 import java . net . * ;45 /* *6 * @description A communication handler for the Motoman NX100 Robot Control ler7 * (SOAP ) .8 * @class SendDataToRobot � Generates a SOAP message with the posi t ion data . The9 * data i s sent to the robot .

10 * @authors Mats Hovin ( matsh@ifi . uio . no ) , Sigurd Salvesen , sigurdsa@ifi . uio . no .11 * @info Original ly code by Mats Hovin . Rewritten & modified by Sigurd Salvesen .12 */13

92

Page 107: An Autonomous and Vendor Independent Robot-based Palletizing

14 public class SendDataToRobot {15 private String nxUrlString = " http ://192.168.255.1:8080 " ;16 private String [ ] part = new String [12 ] ; // SOAP�message elements1718 SendDataToRobot ( ) {19 in i t ( ) ;20 }2122 SendDataToRobot ( String nxUrlString ) {23 this . nxUrlString = new String ( nxUrlString ) ;24 in i t ( ) ;25 }2627 private void i n i t ( ) {28 // Send data message :29 part [0 ] = " <?xml version =\"1.0\" encoding=\"utf�8\"?>"30 + "<soap : Envelope "31 + " xmlns : soap=\"http ://schemas . xmlsoap . org/soap/envelope/\" "32 + " xmlns : soapenc="33 + " \" http ://schemas . xmlsoap . org/soap/encoding/\" "34 + " xmlns : types=\"http :// tempuri . org/encodedTypes\" "35 + " xmlns : xsi =\"http ://www.w3. org/2001/XMLSchema�instance \" "36 + " xmlns : xsd=\"http ://www.w3. org/2001/XMLSchema\" "37 + " xmlns : cs=\"urn : CoreService\"> "38 + "<soap : Header><Token></Token></soap : Header><soap : Body>"39 + "<q1 : NxPutVarData xmlns : q1=\"urn : CoreService\"> "40 + "<sData href=\"#id1 \" /></q1 : NxPutVarData>"41 + "<soapenc : Array id =\" id1 \" xmlns : q2=\"urn : CoreService \" "42 + " soapenc : arrayType=\"q2 :VAR�DATA[10]\" > "43 + "<Item href=\"#id2 \" /><Item href=\"#id3 \" />"44 + "<Item href=\"#id4 \" /><Item href=\"#id5 \" />"45 + "<Item href=\"#id6 \" /><Item href=\"#id7 \" />"46 + "<Item href=\"#id8 \" /><Item href=\"#id9 \" />"47 + "<Item href=\"#id10\" /><Item href=\"#id11\" />"48 + "</soapenc : Array>" ;4950 for ( int i = 1; i <= 10; i ++)51 part [ i ] = makeSoapElement ( i ) ;5253 part [11] = " </ulValue></q12 :VAR�DATA> "54 + " </soap : Body></soap : Envelope> " ;55 }5657 // Generate SOAP�message elements58 private String makeSoapElement ( int i ) {59 int id = i + 1;60 int q = i + 2;61 String start = " " ;6263 i f ( i != 1)64 start = "</ulValue></q" + Integer . toString (q � 1) + " :VAR�DATA> " ;6566 // Semaphore�element67 i f ( i == 10)68 i = 0;6970 return start + " <q" + Integer . toString (q ) + " :VAR�DATA id =\" id "71 + Integer . toString ( id ) + " \" xsi : type=\"q" + Integer . toString (q )72 + " :VAR�DATA\" xmlns : q" + Integer . toString (q )73 + " =\"urn : CoreService\"> "74 + "<usType xsi : type=\"xsd : unsignedShort\">3</usType>"75 + "<usIndex xsi : type=\"xsd : unsignedShort\"> "

93

Page 108: An Autonomous and Vendor Independent Robot-based Palletizing

76 + Integer . toString ( i ) + "</usIndex> "77 + " <ulValue xsi : type=\"xsd : int \"> " ;78 }7980 public void put ( int xAxis , int yAxis , int zAxis , int rotation , int claw )81 throws Exception {82 // index 0: Handshake83 // index 1: xAxis84 // index 2: yAxis85 // index 3: zAxis86 // index 4: Rotation87 // index 5: Claw88 // . . . . . . : unused8990 String unusedVariable = "0" ;91 String semaphore = "0" ; // Semaphore at the NX1009293 // Putting the SOAP�message together94 String soap = part [0 ] + part [1 ] + Integer . toString ( xAxis ) + part [2 ]95 + Integer . toString ( yAxis ) + part [3 ]96 + Integer . toString ( zAxis ) + part [4 ]97 + Integer . toString ( rotation ) + part [5 ]98 + Integer . toString ( claw ) + part [6 ] + unusedVariable99 + part [7 ] + unusedVariable + part [8 ] + unusedVariable

100 + part [9 ] + unusedVariable + part [10] + semaphore101 + part [11 ] ;102103 byte [ ] byArr = soap . getBytes ( ) ;104 String SOAPAction = " " ;105 URL url = new URL( nxUrlString ) ;106107 // I n i t i a l i z e connection108 URLConnection connection = url . openConnection ( ) ;109 HttpURLConnection httpConn = ( HttpURLConnection ) connection ;110111 httpConn . setRequestProperty ( "Content�Length " ,112 String . valueOf ( byArr . length ) ) ;113 httpConn . setRequestProperty ( "Content�Type" , " text /xml ; charset=utf�8" ) ;114 httpConn . setRequestProperty ( "SOAPAction" , SOAPAction ) ;115 httpConn . setRequestMethod ( "POST" ) ;116 httpConn . setDoOutput ( true ) ;117 httpConn . setDoInput ( true ) ;118119 // Send data120 OutputStream out = httpConn . getOutputStream ( ) ;121 out . write ( byArr ) ;122 out . close ( ) ;123124 // Read data125 InputStreamReader i s r = new InputStreamReader ( httpConn . getInputStream ( ) ) ;126 BufferedReader in = new BufferedReader ( i s r ) ;127 in . close ( ) ;128 }129 }� �

Listing A.3: SendDataToRobot.java

Listing A.4: WaitRobotFinished.java�1 import com. cycling74 .max . * ;2 import java . io . * ;

94

Page 109: An Autonomous and Vendor Independent Robot-based Palletizing

3 import java . net . * ;45 /* *6 * @description A communication handler for the Motoman NX100 Robot Control ler7 * (SOAP ) .8 * @class WaitRobotFinished � Waits for the robot to f in i sh ( the robot9 * contro l ler se t s i t ’ s semaphore variable low ( = 0 ) ) .

10 * @authors Mats Hovin ( matsh@ifi . uio . no ) , Sigurd Salvesen , sigurdsa@ifi . uio . no .11 * @info Original ly code by Mats Hovin . Rewritten & modified by Sigurd Salvesen .12 */1314 public class WaitRobotFinished {15 private String nxUrlString = " http ://192.168.255.1:8080 " ; // Robot address16 private URL url ;17 private byte [ ] byteMessage ;1819 WaitRobotFinished ( ) throws Exception {20 String uT ;2122 uT = " <?xml version =\"1.0\" encoding=\"utf�8\"?>"23 + "<soap : Envelope "24 + " xmlns : soap=\"http ://schemas . xmlsoap . org/soap/envelope/\" "25 + " xmlns : soapenc=\"http ://schemas . xmlsoap . org/soap/encoding/\" "26 + " xmlns : types=\"http :// tempuri . org/encodedTypes\" "27 + " xmlns : xsi =\"http ://www.w3. org/2001/XMLSchema�instance \" "28 + " xmlns : xsd=\"http ://www.w3. org/2001/XMLSchema\" "29 + " xmlns : cs=\"urn : CoreService\"> "30 + "<soap : Header><Token></Token></soap : Header>"31 + "<soap : Body>"32 + "<q1 : NxGetVarData xmlns : q1=\"urn : CoreService\"> "33 + "<sData href=\"#id1 \" /></q1 : NxGetVarData>"34 + "<soapenc : Array id =\" id1 \" xmlns : q2=\"urn : CoreService \" "35 + " soapenc : arrayType=\"q2 :VAR�INFO[1]\" > "36 + "<Item href=\"#id2 \" />"37 + "</soapenc : Array>"38 + "<q3 :VAR�INFO id =\" id2 \" xsi : type=\"q3 :VAR�INFO\" "39 + "xmlns : q3=\"urn : CoreService\"> "40 + "<usType xsi : type=\"xsd : unsignedShort\">3</usType>"41 + "<usIndex xsi : type=\"xsd : unsignedShort\">0</usIndex></q3 :VAR�INFO>"42 + "</soap : Body></soap : Envelope> " ;4344 byteMessage = uT . getBytes ( ) ;45 url = new URL( nxUrlString ) ;46 }4748 // Waiting for the robot to f in i sh49 public void waiting ( ) throws Exception {50 while ( semaphoreHigh ( ) == false )51 ;52 }5354 // Check i f the robot has f inished55 private boolean semaphoreHigh ( ) throws Exception {56 boolean semaphoreHigh = false ;5758 // I n i t i a l i z e connection59 String SOAPAction = " " ;60 URLConnection connection = url . openConnection ( ) ;61 HttpURLConnection httpConn = ( HttpURLConnection ) connection ;6263 httpConn . setRequestProperty ( "Content�Length " ,64 String . valueOf ( byteMessage . length ) ) ;

95

Page 110: An Autonomous and Vendor Independent Robot-based Palletizing

65 httpConn . setRequestProperty ( "Content�Type" , " text /xml ; charset=utf�8" ) ;66 httpConn . setRequestProperty ( "SOAPAction" , SOAPAction ) ;67 httpConn . setRequestMethod ( "POST" ) ;68 httpConn . setDoOutput ( true ) ;69 httpConn . setDoInput ( true ) ;7071 // Send data72 OutputStream out = httpConn . getOutputStream ( ) ;73 out . write ( byteMessage ) ;74 out . close ( ) ;7576 // Read data77 InputStreamReader i s r = new InputStreamReader ( httpConn . getInputStream ( ) ) ;78 BufferedReader in = new BufferedReader ( i s r ) ;7980 String inputLine ;8182 while ( ( inputLine = in . readLine ( ) ) != null ) {83 i f ( inputLine . indexOf ( "<item>1" ) > 0)84 semaphoreHigh = true ;85 }8687 in . close ( ) ;8889 return semaphoreHigh ;90 }91 }� �

Listing A.4: WaitRobotFinished.java

96

Page 111: An Autonomous and Vendor Independent Robot-based Palletizing

A.2 NX100 Program

Listing A.5: nx100.inform�1 NOP2 SETE P000 (4 ) 180003 SETE P000 (5 ) 04 SETE P000 (7 ) 14475 SET D000 16 *WAIT7 JUMP *WAIT IF D000=18 SETE P000 (1 ) D0019 SETE P000 (2 ) D002

10 SETE P000 (3 ) D00311 SETE P000 (6 ) D00412 /* Add code : open/ close gripper */13 MOVL P000 V=80.014 SET D000 115 JUMP *WAIT16 END� �

Listing A.5: nx100.inform

97

Page 112: An Autonomous and Vendor Independent Robot-based Palletizing

A.3 Packing Algorithm

Listing A.6: PalletHandler.java�1 import com. cycling74 .max . * ;2 import java . awt . * ;3 import javax . swing . * ;45 /* *6 * @description A system for generating / searching for good/ optimal pa l l e t7 * configuration for an autonomous robot�based pa l l e t loading8 * system .9 * @class PalletHandler � A Max object for generating and handling pa l l e t

10 * schemas .11 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .12 */1314 public class PalletHandler extends MaxObject {15 private int packageHeight = 0;16 private int packageWidth = 0;17 private int packageDepth = 0;1819 private int palletHeight = 0;20 private int palletWidth = 0;21 private int palletDepth = 0;2223 private boolean reset = true ; // no package placed2425 private int x = 0;26 private int y = 0;27 private int z = 0;28 private boolean rotate = false ;29 private int packageNumber = 0;3031 private float errorMargin = 0;3233 private Pa l le t pal let = null ;3435 DrawPallet palletWindow = null ;3637 private stat ic f inal String [ ] INLET_ASSIST = new String [ ] { " in le t 1 help " } ;38 private stat ic f inal String [ ] OUTLET_ASSIST = new String [ ] { " outlet 1 help " } ;3940 public PalletHandler ( boolean bang , boolean reset , f loat packageHeight ,41 f loat packageWidth , f loat packageDepth , int palletHeight ,42 int palletWidth , int palletDepth , f loat errorMargin ) {43 declareInlets (new int [ ] { DataTypes . ALL , DataTypes . ALL , DataTypes . ALL ,44 DataTypes . ALL , DataTypes . ALL , DataTypes . ALL , DataTypes . ALL ,45 DataTypes . ALL , DataTypes . ALL } ) ;46 declareOutlets (new int [ ] { DataTypes . ALL , DataTypes . ALL , DataTypes . ALL ,47 DataTypes . ALL , DataTypes . ALL , DataTypes . ALL , DataTypes . ALL ,48 DataTypes . ALL , DataTypes . ALL } ) ;4950 set InletAssist (new String [ ] { "bang to output " , "bang to reset " ,51 "package height " , "package width " , "package depth" ,52 " pal let height " , " pal let width " , " pal let depth" , " error margin" } ) ;53 setOutletAssist (new String [ ] { " finished " , "x" , "y " , "z" , " rotate " ,54 " package_height " , "package_width " , "package_depth " ,55 "package_number" } ) ;56 }

98

Page 113: An Autonomous and Vendor Independent Robot-based Palletizing

5758 public void bang ( ) {59 int inletNum = get Inlet ( ) ;60 post ( " PalletHandler : banged at : " + inletNum ) ;6162 i f ( inletNum == 0) { // bang63 post ( " PalletHandler : bang � output placement ( x , y , z ) " ) ;6465 i f ( pa l let == null | | reset ) {66 // Generate a new pal le t scheme67 PalletSearch scheme = new PalletSearch ( palletWidth ,68 palletDepth ,69 palletHeight ,70 packageWidth ,71 packageDepth ,72 packageHeight ) ;7374 pal let = scheme .makeScheme ( ) ;7576 pal let . visual ize ( ) ;77 }7879 Package currPackage = pal let . getCurrPackage ( true ) ;8081 packageHeight = currPackage . getHeight ( ) ;82 packageWidth = currPackage . getWidth ( ) ;83 packageDepth = currPackage . getDepth ( ) ;8485 x = currPackage . getX ( ) ;86 y = currPackage . getY ( ) ;87 z = currPackage . getZ ( ) ;8889 rotate = currPackage . getRotated ( ) ;90 packageNumber = currPackage . getPackageNumber ( ) ;9192 sendPos ( ) ;9394 } else i f ( inletNum == 1) { // reset95 post ( " PalletHandler : reset " ) ;96 reset ( ) ;97 }98 }99

100 public void in le t ( int i ) {101 int inletNum = get Inlet ( ) ;102103 i f ( inletNum == 5) { // pa l l e t height104 palletHeight = i ;105106 } else i f ( inletNum == 6) { // pa l l e t width107 palletWidth = i ;108109 } else i f ( inletNum == 7) { // pa l l e t depth110 palletDepth = i ;111 }112 }113114 public void in le t ( f loat f ) {115 int inletNum = get Inlet ( ) ;116117 i f ( inletNum == 2) {118 f loat dif f = Math . abs ( packageHeight � f ) ;

99

Page 114: An Autonomous and Vendor Independent Robot-based Palletizing

119120 i f ( ! reset && dif f > errorMargin )121 il legalPackageSize ( " height " , d i f f ) ;122 else123 packageHeight = ( int ) f + 1;124125 } else i f ( inletNum == 3) {126 f loat dif f = Math . abs ( packageWidth � f ) ;127128 i f ( ! reset && dif f > errorMargin )129 il legalPackageSize ( "width " , d i f f ) ;130 else131 packageWidth = ( int ) f + 1;132133 } else i f ( inletNum == 4) {134 f loat dif f = Math . abs ( packageDepth � f ) ;135136 i f ( ! reset && dif f > errorMargin )137 il legalPackageSize ( "depth" , d i f f ) ;138 else139 packageDepth = ( int ) f + 1;140141 } else i f ( inletNum == 8) {142 post ( " PalletHandler : new errorMargin : " + f ) ;143 errorMargin = f ;144 }145 }146147 // Reset pa l l e t ( empty pa l l e t )148 public void reset ( ) {149 reset = true ;150 }151152 // Send X , Y and Z�posi t ion and rotation at the pa l l e t to Max153 public void sendPos ( ) {154 i f ( reset ) {155 reset = false ;156 } else {157 }158159 outlet (0 , true ) ;160 outlet (1 , x ) ;161 outlet (2 , y ) ;162 outlet (3 , z ) ;163 outlet (4 , rotate ) ;164 outlet (5 , packageHeight ) ;165 outlet (6 , packageWidth ) ;166 outlet (7 , packageDepth ) ;167 outlet (8 , packageNumber ) ;168 }169170 // New package s ize d i f f . > error_margin171 public void i l legalPackageSize ( String side , f loat dif f ) {172 post ( " PalletHandler : empty il legalPackageSize ( side : " + side173 + " | d i f f : " + di f f + " ) " ) ;174 }175176 }� �

Listing A.6: PalletHandler.java

100

Page 115: An Autonomous and Vendor Independent Robot-based Palletizing

Listing A.7: PalletOrganizer.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A system for generating / searching for good/ optimal pa l l e t5 * configuration for an autonomous robot�based pa l l e t loading6 * system .7 * @class PalletOrganizer � Testing the funct ional i ty used from Max.8 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .9 */

1011 public class PalletOrganizer {12 private stat ic int palletWidth = 300;13 private stat ic int palletDepth = 282;14 private stat ic int palletHeight = 200;15 private stat ic int packageWidth = 23;16 private stat ic int packageDepth = 29;17 private stat ic int packageHeight = 15;1819 private stat ic Pa l le t pal let = null ;2021 public stat ic void main ( String [ ] args ) {22 run ( ) ;23 }2425 // Test functions used from Max26 public stat ic void run ( ) {27 PalletSearch scheme = new PalletSearch ( palletWidth , palletDepth ,28 palletHeight , packageWidth ,29 packageDepth , packageHeight ) ;3031 pal let = scheme .makeScheme ( ) ;3233 pal let . visual ize ( ) ;34 }35 }� �

Listing A.7: PalletOrganizer.java

Listing A.8: PalletSearch.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A system for generating / searching for good/ optimal pa l l e t5 * configuration for an autonomous robot�based pa l l e t loading6 * system .7 * @class PalletSearch � Search for di f ferent pa l l e t schemas8 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .9 */

1011 public class PalletSearch {12 private int palletWidth ;13 private int palletDepth ;14 private int palletHeight ;15 private int packageWidth ;16 private int packageDepth ;17 private int packageHeight ;1819 private PalletConfigBlockHeuristics bestPalletBlocks ;

101

Page 116: An Autonomous and Vendor Independent Robot-based Palletizing

2021 PalletSearch ( int palletWidth , int palletDepth , int palletHeight ,22 int packageWidth , int packageDepth , int packageHeight ) {23 this . palletWidth = palletWidth ;24 this . palletDepth = palletDepth ;25 this . palletHeight = palletHeight ;26 this . packageWidth = packageWidth ;27 this . packageDepth = packageDepth ;28 this . packageHeight = packageHeight ;29 }3031 public PalletConfig search ( boolean print , boolean display ) {32 System . out . flush ( ) ;3334 long start = System . currentTimeMillis ( ) ;3536 // � � � � � � � � � � � � � � � � � � �37 // Block BRUTE FORCE38 // � � � � � � � � � � � � � � � � � � �39 bestPalletBlocks = new PalletConfigBlockHeuristics ( palletWidth ,40 palletDepth ,41 palletHeight ,42 packageWidth ,43 packageDepth ,44 packageHeight ) ;45 PalletConfigBlockHeuristics currPal let =46 ( PalletConfigBlockHeuristics ) bestPalletBlocks . clone ( ) ;4748 int currPackageDepth ;49 int currPackageWidth ;5051 int count = 0;5253 for ( int run = 0; run < 2; run++) {54 i f ( run == 0) {55 currPackageDepth = packageDepth ;56 currPackageWidth = packageWidth ;57 } else {58 currPackageDepth = packageWidth ;59 currPackageWidth = packageDepth ;60 }6162 for ( int a = 0; a <= palletWidth / currPackageWidth ; a++) {63 currPal let . setA ( a * currPackageWidth ) ;6465 for ( int c = 0; c <= currPal let . getA ( ) / currPackageDepth ; c++) {66 currPal let . setC ( c * currPackageDepth ) ;6768 for ( int d = 0; d <= palletDepth / currPackageWidth ; d++) {69 currPal let . setD (d * currPackageWidth ) ;7071 for ( int h = 0; h <= currPal let . getD ( )72 / currPackageDepth ; h++) {73 currPal let . setH (h * currPackageDepth ) ;7475 i f ( currPal let . getFitness ( ) > bestPalletBlocks76 . getFitness ( ) )77 bestPalletBlocks = currPal let . clone ( ) ;7879 count++;80 }81 }

102

Page 117: An Autonomous and Vendor Independent Robot-based Palletizing

82 }83 }84 }8586 long end = System . currentTimeMillis ( ) ;8788 i f ( print )89 System . out . print ( bestPalletBlocks . getPacakagesPlaced ( ) + " \ t " ) ;9091 i f ( display )92 new DrawPallet ( bestPalletBlocks , " Block ( brute force ) : "93 + bestPalletBlocks . getFitness ( ) ,94 640, 340);9596 i f ( print )97 System . out . println ( ( end � start ) + " (ms) " ) ;9899 return bestPalletBlocks ;

100 }101102 public Pa l le t makeScheme ( ) {103 PalletConfig palletConfig = search ( true , true ) ;104105 Pa l le t pal let = palletConfig . convertToPalletFormat ( ) ;106 pal let . setCurrPackage ( pal let . getFirstPackage ( ) ) ;107108 return pal let ;109 }110 }� �

Listing A.8: PalletSearch.java

Listing A.9: PalletConfig.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A system for generating / searching for good/ optimal pa l l e t5 * configuration for an autonomous robot�based pa l l e t loading6 * system .7 * @class PalletConfig � An abstract c lass for holding information of a pa l l e t8 * and i t ’ s packages .9 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .

10 */1112 public abstract class PalletConfig {13 protected int palletWidth ;14 protected int palletDepth ;15 protected int palletHeight ;16 protected int packageWidth ;17 protected int packageDepth ;18 protected int packageHeight ;1920 PalletConfig ( int palletWidth , int palletDepth , int palletHeight ,21 int packageWidth , int packageDepth , int packageHeight ) {22 this . palletWidth = palletWidth ;23 this . palletDepth = palletDepth ;24 this . palletHeight = palletHeight ;25 this . packageWidth = packageWidth ;26 this . packageDepth = packageDepth ;27 this . packageHeight = packageHeight ;

103

Page 118: An Autonomous and Vendor Independent Robot-based Palletizing

28 }2930 public int getPalletWidth ( ) {31 return palletWidth ;32 }3334 public int getPalletDepth ( ) {35 return palletDepth ;36 }3738 public int getPackageWidth ( ) {39 return packageWidth ;40 }4142 public int getPackageDepth ( ) {43 return packageDepth ;44 }4546 abstract public void rotate ( int i ) ;4748 abstract public void rotateAll ( ) ;4950 public f loat getFitness ( ) {51 return ( f loat ) ( getPackageDepth ( ) * getPackageWidth ( ) * getPacakagesPlaced ( ) )52 / ( getPalletDepth ( ) * getPalletWidth ( ) ) ;53 }5455 abstract public int getPacakagesPlaced ( ) ;5657 abstract public PalletConfig clone ( ) ;5859 abstract public Pa l le t convertToPalletFormat ( ) ;60 }� �

Listing A.9: PalletConfig.java

Listing A.10: PalletConfigRowRotate.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A system for generating / searching for good/ optimal pa l l e t5 * configuration for an autonomous robot�based pa l l e t loading6 * system .7 * @class PalletConfigRowRotate � Class for holding information of a pa l l e t and8 * i t ’ s packages � A given number of rows are rotated .9 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .

10 */1112 public class PalletConfigRowRotate extends PalletConfig {13 private int rowsRotated ;1415 PalletConfigRowRotate ( int palletWidth , int palletDepth , int packageWidth ,16 int packageDepth , int packageHeight ) {17 super ( palletWidth , palletDepth , 0 , packageWidth , packageDepth ,18 packageHeight ) ;1920 this . rowsRotated = 0;21 }2223 PalletConfigRowRotate ( int palletWidth , int palletDepth , int packageWidth ,

104

Page 119: An Autonomous and Vendor Independent Robot-based Palletizing

24 int packageDepth , int packageHeight , int rowsRotated ) {25 super ( palletWidth , palletDepth , 0 , packageWidth , packageDepth ,26 packageHeight ) ;2728 this . rowsRotated = rowsRotated ;29 }3031 public void rotate ( int i ) {32 rowsRotated = i ;33 }3435 public void rotateAll ( ) {36 rowsRotated = 9999;37 }3839 public int getRotatedRows ( ) {40 return rowsRotated ;41 }4243 // Return the maximum numbers of rows that f i t s into the pa l l e t44 public int getMaxRows ( ) {45 i f ( packageDepth < packageWidth )46 return palletDepth / packageDepth ;47 else48 return palletDepth / packageWidth ;49 }5051 // Count the number of packages that f i t s into the pa l l e t52 public int getPacakagesPlaced ( ) {53 int currPosY = 0;54 int packagesPlaced = 0;55 int i = 0;5657 // Rotated rows58 for ( ; i < rowsRotated ; i ++) {59 i f ( ( currPosY + packageWidth ) > palletDepth )60 break ;6162 packagesPlaced += palletWidth / packageDepth ;6364 currPosY += packageWidth ;65 }6667 // None�rotated rows68 for ( ; i <= getMaxRows ( ) ; i ++) {69 i f ( ( currPosY + packageDepth ) > palletDepth )70 break ;7172 packagesPlaced += palletWidth / packageWidth ;7374 currPosY += packageDepth ;75 }7677 return packagesPlaced ;78 }7980 // Find the optimal number of rows rotated81 public PalletConfig getBest ( ) {82 PalletConfig bestPal let = this . clone ( ) ;83 PalletConfig currPal let = this . clone ( ) ;8485 for ( int i = 0; i <= getMaxRows ( ) ; i ++) {

105

Page 120: An Autonomous and Vendor Independent Robot-based Palletizing

86 currPal let . rotate ( i ) ;8788 i f ( currPal let . getFitness ( ) > bestPal let . getFitness ( ) )89 bestPal let = ( PalletConfigRowRotate ) currPal let . clone ( ) ;90 }9192 return bestPal let ;93 }9495 // Make a copy96 public PalletConfig clone ( ) {97 return new PalletConfigRowRotate ( palletWidth , palletDepth ,98 packageWidth , packageDepth ,99 packageHeight , rowsRotated ) ;

100 }101102 // Convert to Pa l l e t c lass format103 public Pa l le t convertToPalletFormat ( ) {104 // Not implemented105 return null ;106 }107 }� �

Listing A.10: PalletConfigRowRotate.java

Listing A.11: PalletConfigEqualRotate.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A system for generating / searching for good/ optimal pa l l e t5 * configuration for an autonomous robot�based pa l l e t loading6 * system .7 * @class PalletConfigEqualRotate � A class for holding information of a pa l l e t8 * and i t ’ s packages � All packages are ei ther rotated or not rotated9 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .

10 */1112 public class PalletConfigEqualRotate extends PalletConfig {13 private boolean rotated ;1415 PalletConfigEqualRotate ( int palletWidth , int palletDepth , int palletHeight ,16 int packageWidth , int packageDepth , int packageHeight ) {17 super ( palletWidth , palletDepth , palletHeight , packageWidth ,18 packageDepth , packageHeight ) ;1920 rotated = false ;21 }2223 PalletConfigEqualRotate ( int palletWidth , int palletDepth , int palletHeight ,24 int packageWidth , int packageDepth , int packageHeight ,25 boolean rotated ) {26 super ( palletWidth , palletDepth , palletHeight , packageWidth ,27 packageDepth , packageHeight ) ;2829 this . rotated = rotated ;30 }3132 public void rotate ( int i ) {33 i f ( i == 0)34 rotated = false ;

106

Page 121: An Autonomous and Vendor Independent Robot-based Palletizing

35 else36 rotated = true ;37 }3839 public void rotateAll ( ) {40 rotated = true ;41 }4243 public boolean isRotated ( ) {44 return rotated ;45 }4647 // Count the number of packages that f i t s into the pa l l e t48 public int getPacakagesPlaced ( ) {49 int sum;5051 i f ( rotated )52 sum = ( palletWidth / packageDepth ) * ( palletDepth / packageWidth ) ;53 else54 sum = ( palletWidth / packageWidth ) * ( palletDepth / packageDepth ) ;5556 i f (sum < 0)57 return 0;58 else59 return sum;60 }6162 // Find the optimal number of rows rotated63 public PalletConfig getBest ( ) {64 PalletConfig reversePal let = this . clone ( ) ;6566 i f ( isRotated ( ) )67 reversePal let . rotate ( 0 ) ;68 else69 reversePal let . rotateAll ( ) ;7071 i f ( getFitness ( ) > reversePal let . getFitness ( ) )72 return this ;73 else74 return reversePal let ;75 }7677 // Make a copy78 public PalletConfig clone ( ) {79 return new PalletConfigEqualRotate ( palletWidth , palletDepth ,80 palletHeight , packageWidth ,81 packageDepth , packageHeight , rotated ) ;82 }8384 // Convert to Pa l l e t c lass format85 public Pa l le t convertToPalletFormat ( ) {86 // Not implemented87 return null ;88 }89 }� �

Listing A.11: PalletConfigEqualRotate.java

Listing A.12: PalletConfigBlockHeuristics.java�1 import com. cycling74 .max . * ;

107

Page 122: An Autonomous and Vendor Independent Robot-based Palletizing

23 /* *4 * @description A system for generating / searching for good/ optimal pa l l e t5 * configuration for an autonomous robot�based pa l l e t loading6 * system .7 * @class Pal letConfigBlockHeurist ics � Class for holding information of a8 * pa l l e t and i t ’ s packages � 4 blocks of various s ize each handled as an9 * individual pa l l e t .

10 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .11 */1213 public class PalletConfigBlockHeuristics extends PalletConfig {14 private int a ;15 private int e ;1617 private int f ;18 private int h ;1920 private int c ;21 private int g ;2223 private int b ;24 private int d ;2526 private PalletConfig block1 ;27 private PalletConfig block2 ;28 private PalletConfig block3 ;29 private PalletConfig block4 ;3031 PalletConfigBlockHeuristics ( int palletWidth , int palletDepth ,32 int palletHeight , int packageWidth , int packageDepth ,33 int packageHeight ) {34 super ( palletWidth , palletDepth , palletHeight , packageWidth ,35 packageDepth , packageHeight ) ;3637 block1 = null ;38 block2 = null ;39 block3 = null ;40 block4 = null ;4142 setA ( 0 ) ;43 setC ( 0 ) ;44 setD ( 0 ) ;45 setH ( 0 ) ;46 }4748 public void rotate ( int i ) {49 } // Not in use5051 public void rotateAll ( ) {52 } // Not in use5354 public int getA ( ) {55 return a ;56 }5758 public void setA ( int a ) {59 this . a = a ;60 e = palletWidth � a ;61 }6263 public int getE ( ) {

108

Page 123: An Autonomous and Vendor Independent Robot-based Palletizing

64 return e ;65 }6667 public int getF ( ) {68 return f ;69 }7071 public int getH ( ) {72 return h ;73 }7475 public void setH ( int h) {76 this . h = h ;77 f = palletDepth � h ;78 }7980 public int getC ( ) {81 return c ;82 }8384 public void setC ( int c ) {85 this . c = c ;86 g = palletWidth � c ;87 }8889 public int getG ( ) {90 return g ;91 }9293 public int getB ( ) {94 return b ;95 }9697 public int getD ( ) {98 return d ;99 }

100101 public void setD ( int d) {102 this . d = d ;103 b = palletDepth � d ;104 }105106 private void printVariables ( ) {107 System . out . println ( "A: " + a ) ;108 System . out . println ( "B : " + b ) ;109 System . out . println ( "C: " + c ) ;110 System . out . println ( "D: " + d ) ;111 System . out . println ( "E : " + e ) ;112 System . out . println ( "F : " + f ) ;113 System . out . println ( "G: " + g ) ;114 System . out . println ( "H: " + h ) ;115 }116117 public int getPalletWidth ( ) {118 return palletWidth ;119 }120121 public int getPalletDepth ( ) {122 return palletDepth ;123 }124125 public int getPackageWidth ( ) {

109

Page 124: An Autonomous and Vendor Independent Robot-based Palletizing

126 return packageWidth ;127 }128129 public int getPackageDepth ( ) {130 return packageDepth ;131 }132133 public int getPackageDepth ( int i ) {134 return 0;135 }136137 public int getPackageWidth ( int i ) {138 return 0;139 }140141 public PalletConfig getBlock1 ( ) {142 return block1 ;143 }144145 public PalletConfig getBlock2 ( ) {146 return block2 ;147 }148149 public PalletConfig getBlock3 ( ) {150 return block3 ;151 }152153 public PalletConfig getBlock4 ( ) {154 return block4 ;155 }156157 // Search for best rotation with given block s izes158 public int getPacakagesPlaced ( ) {159 block1 = new PalletConfigEqualRotate ( getA ( ) , getB ( ) , palletHeight ,160 packageWidth , packageDepth ,161 packageHeight ) ;162 block2 = new PalletConfigEqualRotate ( getC ( ) , getD ( ) , palletHeight ,163 packageWidth , packageDepth ,164 packageHeight ) ;165 block3 = new PalletConfigEqualRotate ( getE ( ) , getF ( ) , palletHeight ,166 packageWidth , packageDepth ,167 packageHeight ) ;168 block4 = new PalletConfigEqualRotate ( getG ( ) , getH ( ) , palletHeight ,169 packageWidth , packageDepth ,170 packageHeight ) ;171172 PalletConfig block1_rotated = block1 . clone ( ) ;173 PalletConfig block2_rotated = block2 . clone ( ) ;174 PalletConfig block3_rotated = block3 . clone ( ) ;175 PalletConfig block4_rotated = block4 . clone ( ) ;176177 block1_rotated . rotateAll ( ) ;178 block2_rotated . rotateAll ( ) ;179 block3_rotated . rotateAll ( ) ;180 block4_rotated . rotateAll ( ) ;181182 int sum1 = block1 . getPacakagesPlaced ( )183 + block2_rotated . getPacakagesPlaced ( )184 + block3_rotated . getPacakagesPlaced ( )185 + block4 . getPacakagesPlaced ( ) ;186187 int sum2 = block1_rotated . getPacakagesPlaced ( )

110

Page 125: An Autonomous and Vendor Independent Robot-based Palletizing

188 + block2 . getPacakagesPlaced ( ) + block3 . getPacakagesPlaced ( )189 + block4_rotated . getPacakagesPlaced ( ) ;190191 i f (sum1 >= sum2) {192 block2 . rotateAll ( ) ;193 block3 . rotateAll ( ) ;194 } else {195 block1 . rotateAll ( ) ;196 block4 . rotateAll ( ) ;197 }198199 return block1 . getPacakagesPlaced ( ) + block2 . getPacakagesPlaced ( )200 + block3 . getPacakagesPlaced ( ) + block4 . getPacakagesPlaced ( ) ;201 }202203 // Make a copy204 public PalletConfigBlockHeuristics clone ( ) {205 PalletConfigBlockHeuristics newPallet = new PalletConfigBlockHeuristics (206 palletWidth ,207 palletDepth ,208 palletHeight ,209 packageWidth ,210 packageDepth ,211 packageHeight ) ;212213 newPallet . setA ( getA ( ) ) ;214 newPallet . setC ( getC ( ) ) ;215 newPallet . setD ( getD ( ) ) ;216 newPallet . setH ( getH ( ) ) ;217218 newPallet . getFitness ( ) ; // Fix block 1�4219220 return newPallet ;221 }222223 // Convert to Pa l l e t c lass format224 public Pa l le t convertToPalletFormat ( ) {225 Pa l le t pal let = new Pa l le t ( palletWidth , palletDepth , palletHeight ) ;226227 // Add layers228 for ( int z = 0; (z + packageHeight ) <= palletHeight ; z += packageHeight ) {229 // Add packages from the 4 blocks to current layer230 placePackages (0 , getD ( ) , z , getBlock1 ( ) , pa l let ) ;231 placePackages (0 , 0 , z , getBlock2 ( ) , pa l let ) ;232 placePackages ( getA ( ) , getH ( ) , z , getBlock3 ( ) , pa l let ) ;233 placePackages ( getC ( ) , 0 , z , getBlock4 ( ) , pa l let ) ;234 }235236 return pal let ;237 }238239 // Add packages from one block240 private void placePackages ( int startX , int startY , int z ,241 PalletConfig palletBlock , Pa l le t newPallet ) {242 int currX = 0;243 int currY = 0;244245 int packageWidth = palletBlock . getPackageWidth ( ) ;246 int packageDepth = palletBlock . getPackageDepth ( ) ;247248 boolean rotated = false ;249

111

Page 126: An Autonomous and Vendor Independent Robot-based Palletizing

250 i f ( ( ( PalletConfigEqualRotate ) palletBlock ) . isRotated ( ) ) {251 packageWidth = palletBlock . getPackageDepth ( ) ;252 packageDepth = palletBlock . getPackageWidth ( ) ;253254 rotated = true ;255 }256257 // Add packages258 while ( currY + packageDepth <= palletBlock . getPalletDepth ( ) ) {259 currX = 0;260261 while ( currX + packageWidth <= palletBlock . getPalletWidth ( ) ) {262 // Generate placement (X� and Y�coordinates )263 int packageX = startX + currX ;264 int packageY = startY + currY ;265266 newPallet267 . addPackage (new Package (268 packageWidth ,269 packageDepth ,270 packageHeight ,271 rotated ,272 packageX ,273 packageY ,274 z ,275 newPallet . getPackagesPlaced ( ) + 1 ) ) ;276277 newPallet . increasePackagesPlaced ( ) ;278 currX += packageWidth ;279 }280281 currY += packageDepth ;282 }283 }284 }� �

Listing A.12: PalletConfigBlockHeuristics.java

Listing A.13: Pallet.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A system for generating / searching for good/ optimal pa l l e t5 * configuration for an autonomous robot�based pa l l e t loading6 * system .7 * @class Pa l l e t � Holding information of a pa l l e t and i t ’ s packages .8 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .9 */

1011 public f inal class Pa l le t {12 private int width ;13 private int depth ;14 private int height ;1516 private int packagesPlaced = 0;1718 private Package firstPackage = null ;19 private Package currPackage = null ;2021 public Pa l le t ( int width , int depth , int height ) {

112

Page 127: An Autonomous and Vendor Independent Robot-based Palletizing

22 this . width = width ;23 this . depth = depth ;24 this . height = height ;25 }2627 public int getWidth ( ) {28 return width ;29 }3031 public int getDepth ( ) {32 return depth ;33 }3435 public int getHeight ( ) {36 return depth ;37 }3839 public void setFirstPackage ( Package p) {40 firstPackage = p ;41 setCurrPackage (p ) ;42 }4344 public void setCurrPackage ( Package p) {45 currPackage = p ;46 }4748 public Package getFirstPackage ( ) {49 return firstPackage ;50 }5152 public Package getCurrPackage ( ) {53 return currPackage ;54 }5556 public Package getCurrPackage ( boolean move) {57 Package p = getCurrPackage ( ) ;5859 i f (move)60 setCurrPackage (p . getNextPackage ( ) ) ;6162 return p ;63 }6465 public Package getNextPackage ( ) {66 currPackage = currPackage . getNextPackage ( ) ;67 return getCurrPackage ( ) ;68 }6970 public void addPackage ( Package p) {71 i f ( getFirstPackage ( ) == null ) {72 setFirstPackage (p ) ;73 } else {74 getCurrPackage ( ) . setNextPackage (p ) ;75 p . setPrevPackage ( getCurrPackage ( ) ) ;76 setCurrPackage (p ) ;77 }78 }7980 public int getPackagesPlaced ( ) {81 return packagesPlaced ;82 }83

113

Page 128: An Autonomous and Vendor Independent Robot-based Palletizing

84 public void setPackagesPlaced ( int number) {85 packagesPlaced = number ;86 }8788 public int increasePackagesPlaced ( ) {89 packagesPlaced++;9091 return packagesPlaced ;92 }9394 public void visual ize ( ) {95 new DrawPallet ( this , " Visualization of pal let " , 50 , 50) ;96 }97 }� �

Listing A.13: Pallet.java

Listing A.14: Package.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A system for generating / searching for good/ optimal pa l l e t5 * configuration for an autonomous robot�based pa l l e t loading6 * system .7 * @class Package � Holding information of a s ingle package8 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .9 */

1011 public f inal class Package {12 private int width ;13 private int depth ;14 private int height ;15 private boolean rotated ;1617 private int x ;18 private int y ;19 private int z ;2021 private int packageNumber ;2223 private Package prevPackage = null ;24 private Package nextPackage = null ;2526 public Package ( int width , int depth , int height , boolean rotated , int x ,27 int y , int z , int packageNumber ) {28 this . width = width ;29 this . depth = depth ;30 this . height = height ;31 this . rotated = rotated ;32 this . x = x ;33 this . y = y ;34 this . z = z ;35 this . packageNumber = packageNumber ;36 }3738 public void setPrevPackage ( Package prevPackage ) {39 this . prevPackage = prevPackage ;40 }4142 public void setPrevPackagePointers ( ) {

114

Page 129: An Autonomous and Vendor Independent Robot-based Palletizing

43 i f ( prevPackage != null )44 prevPackage . setNextPackage ( this ) ;45 }4647 public int getDepth ( ) {48 return depth ;49 }5051 public int getWidth ( ) {52 return width ;53 }5455 public int getHeight ( ) {56 return height ;57 }5859 public boolean getRotated ( ) {60 return rotated ;61 }6263 public void setXYZ ( int x , int y , int z ) {64 this . x = x ;65 this . y = y ;66 this . z = z ;67 }6869 public int getX ( ) {70 return x ;71 }7273 public int getY ( ) {74 return y ;75 }7677 public int getZ ( ) {78 return z ;79 }8081 public int getPackageNumber ( ) {82 return packageNumber ;83 }8485 public void setNextPackage ( Package p) {86 nextPackage = p ;87 nextPackage . setPrevPackage ( this ) ;88 }8990 public Package getNextPackage ( ) {91 return nextPackage ;92 }9394 public void print ( boolean [ ] [ ] utskrift , int pos ) {95 for ( int y = 0; y < depth ; y++) {96 for ( int x = pos ; x < pos + width ; x++) {97 utskr i f t [ y ] [ x ] = true ;98 }99 }

100101 i f ( nextPackage != null )102 nextPackage . print ( utskrift , pos + width ) ;103 }104 }

115

Page 130: An Autonomous and Vendor Independent Robot-based Palletizing

� �Listing A.14: Package.java

Listing A.15: DrawPallet.java�1 import com. cycling74 .max . * ;2 import java . awt . * ;3 import javax . swing . * ;45 /* *6 * @description A system for generating / searching for good/ optimal pa l l e t7 * configuration for an autonomous robot�based pa l l e t loading8 * system .9 * @class DrawPallet � Visual ize pa l l e t configuration .

10 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .11 */1213 public class DrawPallet extends Canvas {14 private PalletConfig pal let = null ;15 private Pa l le t pal le tF ina l = null ;1617 public DrawPallet ( PalletConfig pallet , String t i t l e , int x , int y ) {18 this . pa l let = pal let ;19 JFrame frame = new JFrame ( ) ;20 frame . setBounds ( x , y , pal let . getPalletWidth ( ) + 10 ,21 pal let . getPalletDepth ( ) + 30) ;22 frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ) ;23 frame . getContentPane ( ) . add( this ) ;24 frame . setT i t le ( t i t l e ) ;25 frame . setVis ible ( true ) ;26 }2728 public DrawPallet ( Pa l l e t pallet , String t i t l e , int x , int y ) {29 this . pa l le tF ina l = pal let ;30 JFrame frame = new JFrame ( ) ;31 frame . setBounds ( x , y , pal let . getWidth ( ) + 10 , pal let . getDepth ( ) + 30) ;32 frame . setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE ) ;33 frame . getContentPane ( ) . add( this ) ;34 frame . setT i t le ( t i t l e ) ;35 frame . setVis ible ( true ) ;36 }3738 public void paint ( Graphics graphics ) {39 i f ( pa l le tF ina l != null ) { // Pa l l e t format40 drawPackages (0 , 0 , pal letFinal , graphics ) ;4142 graphics . setColor ( Color . blue ) ;43 graphics . drawRect (0 , 0 , pa l letF ina l . getWidth ( ) ,44 pal le tF ina l . getDepth ( ) ) ;4546 } else i f ( ! ( pa l let instanceof PalletConfigBlockHeuristics ) ) {47 drawPackages (0 , 0 , pallet , graphics ) ;4849 graphics . setColor ( Color . blue ) ;50 graphics . drawRect (0 , 0 , pal let . getPalletWidth ( ) ,51 pal let . getPalletDepth ( ) ) ;5253 } else { // Block heur i s t i c s54 PalletConfigBlockHeuristics pallet2 = ( PalletConfigBlockHeuristics ) pal let55 . clone ( ) ;

116

Page 131: An Autonomous and Vendor Independent Robot-based Palletizing

5657 graphics . setColor ( Color .DARK_GRAY) ;58 graphics . f i l lRec t ( pallet2 . getC ( ) , pallet2 . getH ( ) , pallet2 . getA ( )59 � pallet2 . getC ( ) ,60 pallet2 . getD ( ) � pallet2 . getH ( ) ) ;6162 // Draw packages63 drawPackages (0 , pallet2 . getD ( ) , pallet2 . getBlock1 ( ) , graphics ) ;64 drawPackages (0 , 0 , pallet2 . getBlock2 ( ) , graphics ) ;65 drawPackages ( pallet2 . getA ( ) , pallet2 . getH ( ) , pallet2 . getBlock3 ( ) ,66 graphics ) ;67 drawPackages ( pallet2 . getC ( ) , 0 , pallet2 . getBlock4 ( ) , graphics ) ;6869 graphics . setColor ( Color . yellow ) ;70 graphics71 . drawRect (0 , pallet2 . getD ( ) , pallet2 . getA ( ) , pallet2 . getB ( ) ) ;7273 graphics . setColor ( Color . cyan ) ;74 graphics . drawRect (0 , 0 , pallet2 . getC ( ) , pallet2 . getD ( ) ) ;7576 graphics . setColor ( Color . magenta ) ;77 graphics . drawRect ( pallet2 . getA ( ) , pallet2 . getH ( ) , pallet2 . getE ( ) ,78 pallet2 . getF ( ) ) ;7980 graphics . setColor ( Color . green ) ;81 graphics82 . drawRect ( pallet2 . getC ( ) , 0 , pallet2 . getG ( ) , pallet2 . getH ( ) ) ;83 }84 }8586 // Draw packages ( Pa l l e t c lass format )87 private void drawPackages ( int startX , int startY , Pa l le t pal letFinal ,88 Graphics graphics ) {89 Package currPackage = pal le tF ina l . getFirstPackage ( ) ;9091 // Draw only one layer92 while ( currPackage != null && currPackage . getZ ( ) == 0) {93 boolean rotated = currPackage . getRotated ( ) ;9495 drawPackage ( rotated , currPackage . getX ( ) , currPackage . getY ( ) ,96 currPackage . getWidth ( ) , currPackage . getDepth ( ) ,97 graphics ) ;9899 currPackage = currPackage . getNextPackage ( ) ;

100 }101 }102103 // Draw packages104 private void drawPackages ( int startX , int startY , PalletConfig pallet ,105 Graphics graphics ) {106 int currPosX = 0;107 int currPosY = 0;108 int packageWidth ;109 int packageDepth ;110 packageWidth = pal let . getPackageWidth ( ) ;111 packageDepth = pal let . getPackageDepth ( ) ;112113 i f ( pa l let instanceof PalletConfigEqualRotate ) {114 boolean rotated = false ;115116 i f ( ( ( PalletConfigEqualRotate ) pal let ) . isRotated ( ) ) {117 packageWidth = pal let . getPackageDepth ( ) ;

117

Page 132: An Autonomous and Vendor Independent Robot-based Palletizing

118 packageDepth = pal let . getPackageWidth ( ) ;119 rotated = true ;120 }121122 while ( currPosY + packageDepth <= pal let . getPalletDepth ( ) ) {123 currPosX = 0;124125 while ( currPosX + packageWidth <= pal let . getPalletWidth ( ) ) {126 drawPackage ( rotated , startX + currPosX , startY + currPosY ,127 packageWidth , packageDepth , graphics ) ;128129 currPosX += packageWidth ;130 }131132 currPosY += packageDepth ;133 }134 }135 }136137 // Draw a single package138 private void drawPackage ( boolean rotated , int x , int y , int packageDepth ,139 int packageWidth , Graphics graphics ) {140 i f ( rotated )141 graphics . setColor ( Color . pink ) ;142 else143 graphics . setColor ( Color .LIGHT_GRAY ) ;144145 graphics . f i l l Rec t ( x , y , packageDepth , packageWidth ) ;146 graphics . setColor ( Color . black ) ;147 graphics . drawRect ( x , y , packageDepth , packageWidth ) ;148 }149 }� �

Listing A.15: DrawPallet.java

Listing A.16: PalletLoadingTest.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A system for generating / searching for good/ optimal pa l l e t5 * configuration for an autonomous robot�based pa l l e t loading6 * system .7 * @class PalletLoadingTest � Main c lass � Generate di f ferent t e s t s8 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .9 */

1011 public class PalletLoadingTest {12 public stat ic void main ( String [ ] args ) {13 PalletSearch [ ] tests = new PalletSearch [25 ] ;14 boolean print = true ;15 boolean display = false ;1617 System . out . println ( " *** START *** " ) ;18 // th i s . palletWidth = palletWidth ;19 // th i s . palletDepth = palletDepth ;20 // th i s . palletHeight = palletHeight ;21 // th i s . packageWidth = packageWidth ;22 // th i s . packageDepth = packageDepth ;23 // th i s . packageHeight = packageHeight ;24

118

Page 133: An Autonomous and Vendor Independent Robot-based Palletizing

25 // F i r s t order26 System . out . println ( " * F i rs t order * " ) ;2728 tests [0 ] = new PalletSearch (22 , 16 , 0 , 5 , 3 , 0 ) ;29 tests [1 ] = new PalletSearch (57 , 44 , 0 , 12 , 5 , 0 ) ;30 tests [2 ] = new PalletSearch (86 , 82 , 0 , 15 , 11 , 0 ) ;31 tests [3 ] = new PalletSearch (42 , 39 , 0 , 9 , 4 , 0 ) ;32 tests [4 ] = new PalletSearch (124 , 81 , 0 , 21 , 10 , 0 ) ;33 tests [5 ] = new PalletSearch (40 , 25 , 0 , 7 , 3 , 0 ) ;34 tests [6 ] = new PalletSearch (52 , 33 , 0 , 9 , 4 , 0 ) ;35 tests [7 ] = new PalletSearch (56 , 52 , 0 , 12 , 5 , 0 ) ;36 tests [8 ] = new PalletSearch (87 , 47 , 0 , 7 , 6 , 0 ) ;37 tests [9 ] = new PalletSearch (67 , 44 , 0 , 6 , 5 , 0 ) ;3839 tests [ 0 ] . search ( print , display ) ;40 tests [ 1 ] . search ( print , display ) ;41 tests [ 2 ] . search ( print , display ) ;42 tests [ 3 ] . search ( print , display ) ;43 tests [ 4 ] . search ( print , display ) ;44 tests [ 5 ] . search ( print , display ) ;45 tests [ 6 ] . search ( print , display ) ;46 tests [ 7 ] . search ( print , display ) ;47 tests [ 8 ] . search ( print , display ) ;48 tests [ 9 ] . search ( print , display ) ;4950 // Superior order51 System . out . println ( " * Superior order * " ) ;52 tests [10] = new PalletSearch (43 , 26 , 0 , 7 , 3 , 0 ) ;53 tests [11] = new PalletSearch (63 , 44 , 0 , 8 , 5 , 0 ) ;54 tests [12] = new PalletSearch (61 , 35 , 0 , 10 , 3 , 0 ) ;55 tests [13] = new PalletSearch (61 , 38 , 0 , 6 , 5 , 0 ) ;56 tests [14] = new PalletSearch (61 , 38 , 0 , 10 , 3 , 0 ) ;57 tests [15] = new PalletSearch (93 , 46 , 0 , 13 , 4 , 0 ) ;58 tests [16] = new PalletSearch (141 , 71 , 0 , 13 , 8 , 0 ) ;59 tests [17] = new PalletSearch (106 , 59 , 0 , 13 , 5 , 0 ) ;60 tests [18] = new PalletSearch (74 , 46 , 0 , 7 , 5 , 0 ) ;61 tests [19] = new PalletSearch (86 , 52 , 0 , 9 , 5 , 0 ) ;62 tests [20] = new PalletSearch (108 , 65 , 0 , 10 , 7 , 0 ) ;6364 tests [10 ] . search ( print , display ) ;65 tests [11 ] . search ( print , display ) ;66 tests [12 ] . search ( print , display ) ;67 tests [13 ] . search ( print , display ) ;68 tests [14 ] . search ( print , display ) ;69 tests [15 ] . search ( print , display ) ;70 tests [16 ] . search ( print , display ) ;71 tests [17 ] . search ( print , display ) ;72 tests [18 ] . search ( print , display ) ;73 tests [19 ] . search ( print , display ) ;74 tests [20 ] . search ( print , display ) ;7576 // EQUAL ROTATION77 System . out . println ( " \n\n\n** EQUAL ROTATION ** " ) ;7879 // F i r s t order80 System . out . println ( " * F i rs t order * " ) ;81 print (new PalletConfigEqualRotate (22 , 16 , 0 , 5 , 3 , 0)82 . getBest ( )83 . getPacakagesPlaced ( ) ) ;84 print (new PalletConfigEqualRotate (57 , 44 , 0 , 12 , 5 , 0)85 . getBest ( )86 . getPacakagesPlaced ( ) ) ;

119

Page 134: An Autonomous and Vendor Independent Robot-based Palletizing

87 print (new PalletConfigEqualRotate (86 , 82 , 0 , 15 , 11 , 0)88 . getBest ( )89 . getPacakagesPlaced ( ) ) ;90 print (new PalletConfigEqualRotate (42 , 39 , 0 , 9 , 4 , 0)91 . getBest ( )92 . getPacakagesPlaced ( ) ) ;93 print (new PalletConfigEqualRotate (124 , 81 , 0 , 21 , 10 , 0)94 . getBest ( )95 . getPacakagesPlaced ( ) ) ;96 print (new PalletConfigEqualRotate (40 , 25 , 0 , 7 , 3 , 0)97 . getBest ( )98 . getPacakagesPlaced ( ) ) ;99 print (new PalletConfigEqualRotate (52 , 33 , 0 , 9 , 4 , 0)

100 . getBest ( )101 . getPacakagesPlaced ( ) ) ;102 print (new PalletConfigEqualRotate (56 , 52 , 0 , 12 , 5 , 0)103 . getBest ( )104 . getPacakagesPlaced ( ) ) ;105 print (new PalletConfigEqualRotate (87 , 47 , 0 , 7 , 6 , 0)106 . getBest ( )107 . getPacakagesPlaced ( ) ) ;108 print (new PalletConfigEqualRotate (67 , 44 , 0 , 6 , 5 , 0)109 . getBest ( )110 . getPacakagesPlaced ( ) ) ;111112 // Superior order113 System . out . println ( " * Superior order * " ) ;114 print (new PalletConfigEqualRotate (43 , 26 , 0 , 7 , 3 , 0)115 . getBest ( )116 . getPacakagesPlaced ( ) ) ;117 print (new PalletConfigEqualRotate (63 , 44 , 0 , 8 , 5 , 0)118 . getBest ( )119 . getPacakagesPlaced ( ) ) ;120 print (new PalletConfigEqualRotate (61 , 35 , 0 , 10 , 3 , 0)121 . getBest ( )122 . getPacakagesPlaced ( ) ) ;123 print (new PalletConfigEqualRotate (61 , 38 , 0 , 6 , 5 , 0)124 . getBest ( )125 . getPacakagesPlaced ( ) ) ;126 print (new PalletConfigEqualRotate (61 , 38 , 0 , 10 , 3 , 0)127 . getBest ( )128 . getPacakagesPlaced ( ) ) ;129 print (new PalletConfigEqualRotate (93 , 46 , 0 , 13 , 4 , 0)130 . getBest ( )131 . getPacakagesPlaced ( ) ) ;132 print (new PalletConfigEqualRotate (141 , 71 , 0 , 13 , 8 , 0)133 . getBest ( )134 . getPacakagesPlaced ( ) ) ;135 print (new PalletConfigEqualRotate (106 , 59 , 0 , 13 , 5 , 0)136 . getBest ( )137 . getPacakagesPlaced ( ) ) ;138 print (new PalletConfigEqualRotate (74 , 46 , 0 , 7 , 5 , 0)139 . getBest ( )140 . getPacakagesPlaced ( ) ) ;141 print (new PalletConfigEqualRotate (86 , 52 , 0 , 9 , 5 , 0)142 . getBest ( )143 . getPacakagesPlaced ( ) ) ;144 print (new PalletConfigEqualRotate (108 , 65 , 0 , 10 , 7 , 0)145 . getBest ( )146 . getPacakagesPlaced ( ) ) ;147148 // ROW ROTATION

120

Page 135: An Autonomous and Vendor Independent Robot-based Palletizing

149 System . out . println ( " \n\n\n** ROW ROTATION ** " ) ;150151 // F i r s t order152 System . out . println ( " * F i rs t order * " ) ;153 print (new PalletConfigRowRotate (22 , 16 , 5 , 3 , 0 ) . getBest ( )154 . getPacakagesPlaced ( ) ) ;155 print (new PalletConfigRowRotate (57 , 44 , 12 , 5 , 0 ) . getBest ( )156 . getPacakagesPlaced ( ) ) ;157 print (new PalletConfigRowRotate (86 , 82 , 15 , 11 , 0 ) . getBest ( )158 . getPacakagesPlaced ( ) ) ;159 print (new PalletConfigRowRotate (42 , 39 , 9 , 4 , 0 ) . getBest ( )160 . getPacakagesPlaced ( ) ) ;161 print (new PalletConfigRowRotate (124 , 81 , 21 , 10 , 0)162 . getBest ( )163 . getPacakagesPlaced ( ) ) ;164 print (new PalletConfigRowRotate (40 , 25 , 7 , 3 , 0 ) . getBest ( )165 . getPacakagesPlaced ( ) ) ;166 print (new PalletConfigRowRotate (52 , 33 , 9 , 4 , 0 ) . getBest ( )167 . getPacakagesPlaced ( ) ) ;168 print (new PalletConfigRowRotate (56 , 52 , 12 , 5 , 0 ) . getBest ( )169 . getPacakagesPlaced ( ) ) ;170 print (new PalletConfigRowRotate (87 , 47 , 7 , 6 , 0 ) . getBest ( )171 . getPacakagesPlaced ( ) ) ;172 print (new PalletConfigRowRotate (67 , 44 , 6 , 5 , 0 ) . getBest ( )173 . getPacakagesPlaced ( ) ) ;174175 // Superior order176 System . out . println ( " * Superior order * " ) ;177 print (new PalletConfigRowRotate (43 , 26 , 7 , 3 , 0 ) . getBest ( )178 . getPacakagesPlaced ( ) ) ;179 print (new PalletConfigRowRotate (63 , 44 , 8 , 5 , 0 ) . getBest ( )180 . getPacakagesPlaced ( ) ) ;181 print (new PalletConfigRowRotate (61 , 35 , 10 , 3 , 0 ) . getBest ( )182 . getPacakagesPlaced ( ) ) ;183 print (new PalletConfigRowRotate (61 , 38 , 6 , 5 , 0 ) . getBest ( )184 . getPacakagesPlaced ( ) ) ;185 print (new PalletConfigRowRotate (61 , 38 , 10 , 3 , 0 ) . getBest ( )186 . getPacakagesPlaced ( ) ) ;187 print (new PalletConfigRowRotate (93 , 46 , 13 , 4 , 0 ) . getBest ( )188 . getPacakagesPlaced ( ) ) ;189 print (new PalletConfigRowRotate (141 , 71 , 13 , 8 , 0 ) . getBest ( )190 . getPacakagesPlaced ( ) ) ;191 print (new PalletConfigRowRotate (106 , 59 , 13 , 5 , 0 ) . getBest ( )192 . getPacakagesPlaced ( ) ) ;193 print (new PalletConfigRowRotate (74 , 46 , 7 , 5 , 0 ) . getBest ( )194 . getPacakagesPlaced ( ) ) ;195 print (new PalletConfigRowRotate (86 , 52 , 9 , 5 , 0 ) . getBest ( )196 . getPacakagesPlaced ( ) ) ;197 print (new PalletConfigRowRotate (108 , 65 , 10 , 7 , 0 ) . getBest ( )198 . getPacakagesPlaced ( ) ) ;199200 System . out . println ( " *** END *** " ) ;201 }202203 private stat ic void print ( int message ) {204 System . out . println (message ) ;205 }206 }� �

Listing A.16: PalletLoadingTest.java

121

Page 136: An Autonomous and Vendor Independent Robot-based Palletizing

A.4 Max Synchronization

Listing A.17: Semaphore.java�1 import com. cycling74 .max . * ;23 /* *4 * @description A Max object for synchronization5 * @class Semaphore � Checks that both l e f t and right input has been banged6 * before output i s banged .7 * @author Sigurd Salvesen , sigurdsa@ifi . uio . no .8 */9

10 public class Semaphore extends MaxObject {11 private boolean left Input = false ;12 private boolean rightInput = false ;1314 private stat ic f inal String [ ] INLET_ASSIST = new String [ ] { " in le t 1 help " } ;15 private stat ic f inal String [ ] OUTLET_ASSIST = new String [ ] { " outlet 1 help " } ;1617 public Semaphore ( boolean bangLeft , boolean bangRight , boolean a l lFa lse ) {18 declareInlets (new int [ ] { DataTypes . ALL , DataTypes . ALL , DataTypes . ALL } ) ;19 declareOutlets (new int [ ] { DataTypes . ALL } ) ;2021 set InletAssist (new String [ ] { " left Input " , " rightInput " ,22 " set a l l FALSE" } ) ;23 setOutletAssist (new String [ ] { " active " } ) ;24 }2526 public void bang ( ) {27 int inlet_num = get Inlet ( ) ;28 post ( "Semaphore : banged at : " + inlet_num ) ;2930 i f ( inlet_num == 0) { // leftBang31 left Input = true ;32 } else i f ( inlet_num == 1) { // rightBang33 rightInput = true ;34 } else i f ( inlet_num == 2) { // a l lFa l se35 left Input = rightInput = false ;36 }3738 i f ( left Input && rightInput ) {39 post ( "Semaphore : left Input and rightInout TRUE" ) ;40 left Input = rightInput = false ;41 outlet (0 , "bang" ) ;42 }43 }44 }� �

Listing A.17: Semaphore.java

122

Page 137: An Autonomous and Vendor Independent Robot-based Palletizing

A.5 Max Patchers

Figure A.1: Max patch: robotbased_pallet_loading_system

123

Page 138: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.2: Max patch: state_controller

Figure A.3: Max patch: semaphore

124

Page 139: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.4: Max patch: semaphore2

125

Page 140: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.5: Max patch: camera_control

126

Page 141: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.6: Max patch: grab_above

Figure A.7: Max patch: video_preview_above

127

Page 142: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.8: Max patch: grab_front

Figure A.9: Max patch: video_preview_front

128

Page 143: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.10: Max patch: vision_detect_package

Figure A.11: Max patch: visualizer

129

Page 144: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.12: Max patch: vision_measure_depth

130

Page 145: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.13: Max patch: video_preview

Figure A.14: Max patch: large_view

131

Page 146: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.15: Max patch: vision_measure_width_height

132

Page 147: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.16: Max patch: video_preview2

Figure A.17: Max patch: large_view2

133

Page 148: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.18: Max patch: calc_height

Figure A.19: Max patch: calc_width

Figure A.20: Max patch: calc_depth

134

Page 149: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.21: Max patch: calc_placement

135

Page 150: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.22: Max patch: package_find_placement

136

Page 151: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.23: Max patch: simulation_add_packages

Figure A.24: Max patch: add_package_group

Figure A.25: Max patch: add_package

137

Page 152: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.26: Max patch: random_numbers

Figure A.27: Max patch: activate_input

138

Page 153: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.28: Max patch: add_package_settings

Figure A.29: Max patch: empty

139

Page 154: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.30: Max patch: simulation_pallet

140

Page 155: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.31: Max patch: robot_pick_package

141

Page 156: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.32: Max patch: x1

Figure A.33: Max patch: y1

Figure A.34: Max patch: z1

142

Page 157: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.35: Max patch: rotation1

Figure A.36: Max patch: z2

143

Page 158: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.37: Max patch: robot_place_package

144

Page 159: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.38: Max patch: x3

Figure A.39: Max patch: y3

Figure A.40: Max patch: z3

145

Page 160: An Autonomous and Vendor Independent Robot-based Palletizing

Figure A.41: Max patch: rotation3

Figure A.42: Max patch: z4

146

Page 161: An Autonomous and Vendor Independent Robot-based Palletizing

A.6 JavaScripts

Listing A.18: findbox_2.js�1 // global variables2 var tmpmatrix ;3 var height = 0;4 var depth = 0;56 // i n l e t s and out le t s7 in le ts = 1;8 outlets = 4;9

10 function j it_matrix ( inname)11 {12 var matrix_width = inname . arrayLength ;13 var matrix_height = inname [ 0 ] . arrayLength ;1415 // adapt to input16 tmpmatrix = new J i t terMatr ix (4 , " char " , matrix_width , matrix_height ) ;17 tmpmatrix . setinfo ( inname ) ;18 tmpmatrix . frommatrix ( inname ) ;1920 /*21 Plane 1: l e f t coordinate22 Plane 2: top coordinate23 Plane 3: right coordinate24 Plane 4: Bottom coordinate25 */2627 var array = tmpmatrix . getce l l ( 0 ) ;28 width = ( array [3 ] � array [ 1 ] ) ;29 depth = ( array [2 ] � array [ 0 ] ) ;30 depth_vs_width = depth / width ;3132 outlet (0 , "bang" ) ;33 outlet (1 , width ) ;34 outlet (2 , depth ) ;35 outlet (3 , depth_vs_width ) ;36 }� �

Listing A.18: findbox_2.js

Listing A.19: findbox_1.js�1 // global variabels2 var tmpmatrix ;3 var height = 0;4 var width = 0;5 var position = 0;67 // i n l e t s and out le t s8 in le ts = 1;9 outlets = 4;

1011 function j it_matrix ( inname)12 {13 var matrix_width = inname . arrayLength ;14 var matrix_height = inname [ 0 ] . arrayLength ;

147

Page 162: An Autonomous and Vendor Independent Robot-based Palletizing

1516 // adapt to input17 tmpmatrix = new J i t terMatr ix (4 , " char " , matrix_width , matrix_height ) ;18 tmpmatrix . setinfo ( inname ) ;19 tmpmatrix . frommatrix ( inname ) ;2021 /*22 Plane 1: l e f t coordinate23 Plane 2: top coordinate24 Plane 3: right coordinate25 Plane 4: Bottom coordinate26 */2728 var array = tmpmatrix . getce l l ( 0 ) ;29 height = 480 � array [ 1 ] ;30 width = ( array [2 ] � array [ 0 ] ) ;31 position = 320 � ( array [0 ] + ( width / 2 ) ) ;3233 outlet (0 , "bang" ) ;34 outlet (1 , height ) ;35 outlet (2 , width ) ;36 outlet (3 , position ) ;37 }� �

Listing A.19: findbox_1.js

148

Page 163: An Autonomous and Vendor Independent Robot-based Palletizing

Bibliography

[1] Thomas Bräunl. Embedded Robotics: Mobile Robot Design and Applicationswith Embedded Systems. Springer, second edition, 2006.

[2] Pure Data. Pure data - pd community site. http://puredata.info/, Vis-ited: 13. April 2009.

[3] Topher La Fata. Max/msp: Writing max externals in java.http://blog.lib.umn.edu/geers001/compmusprog2007/WritingMaxExternalsInJava.pdf, Visited: 3. August 2009.

[4] FPT. Fpt standard palletizer. http://www.fpt.de/de/downloads/FPT-Palletizer-GB.pdf, Visited: 1. April 2009.

[5] Motoman Inc. Motoman NX100 - Controller Inform II - User’s Manual. Mo-toman Inc., first edition, September 2004.

[6] Motoman Inc. Motoman ia20 (specification sheet). http://www.motoman.com/motomedia/datasheets/IA20.pdf, October 2006.

[7] Motoman Inc. Motoman news release (ia20). http://www.motoman.com/motomedia/pr/2006-IA20robot-b.pdf, September 2006.

[8] Motoman Inc. Motoman news release (nx100). http://www.motoman.com/motomedia/pr/2006-NX100.pdf, September 2006.

[9] Motoman Inc. Robot control system motoman-nx100. http://www.motomanrobotec.si/roboti/nx-100/MRS6100GB.0.L.pdf.

[10] Venturcom Inc. Hard real-time with venturcom rtx on microsoft windowsxp and windows xp embedded. http://msdn.microsoft.com/en-us/library/ms838583.aspx, Visited: 23. March 2009.

[11] J. Jackson. Microsoft robotics studio: A technical introduction. Robotics &Automation Magazine, IEEE, 14(4):82–87, Dec. 2007.

149

Page 164: An Autonomous and Vendor Independent Robot-based Palletizing

[12] Reza N. Jazar. Theory of Applied Robotics: Kinematics, Dynamics, andControl. Springer, first edition, 2007.

[13] Seth Hutchinson Mark W. Spong and M. Vidyasagar. Robot Modeling andControl. Wiley, first edition, 2006.

[14] Marek P. Michalowski, Selma Sabanovic, and Hideki Kozima. A danc-ing robot for rhythmic social interaction. In HRI ’07: Proceedings of theACM/IEEE international conference on Human-robot interaction, pages 89–96, New York, NY, USA, 2007. ACM.

[15] Sun Microsystems. Sun java real-time system. http://java.sun.com/javase/technologies/realtime/, Visited: 2. April 2009.

[16] Store norske leksikon. Robot. http://snl.no/robot, Visited: 10. March2009.

[17] Vitoria Pureza and Reinaldo Morabito. Some experiments with a simpletabu search algorithm for the manufacturer’s pallet loading problem. Com-puters & Operations Research, 33(3):804 – 819, 2006.

[18] Wikipedia the free encyclopedia. Java (programming language). http://en.wikipedia.org/wiki/Java_(programming_language), Visited: 16.April 2009.

[19] Wikipedia the free encyclopedia. Opencv. http://en.wikipedia.org/wiki/Opencv, Visited: 16. April 2009.

[20] Wikipedia the free encyclopedia. Mean time between failures. http://en.wikipedia.org/wiki/MTBF, Visited: 1. July 2009.

[21] Wikipedia the free encyclopedia. Robot software. http://en.wikipedia.org/wiki/Robot_software, Visited: 1. March 2009.

[22] Wikipedia the free encyclopedia. Optical flow. http://en.wikipedia.org/wiki/Optical_flow, Visited: 1. May 2009.

[23] Wikipedia the free encyclopedia. Machine vision. http://en.wikipedia.org/wiki/Machine_vision, Visited: 25. March 2009.

[24] Wikipedia the free encyclopedia. Soap. http://en.wikipedia.org/wiki/SOAP, Visited: 28. July 2009.

[25] Wikipedia the free encyclopedia. Data synchronization. http://en.wikipedia.org/wiki/Data_synchronization, Visited: 4. August 2009.

150

Page 165: An Autonomous and Vendor Independent Robot-based Palletizing

[26] Wikipedia the free encyclopedia. Programmable logic controller. http://en.wikipedia.org/wiki/Programmable_logic_controller, Visited:4. August 2009.

[27] Wikipedia the free encyclopedia. Synchronization (computer science).http://en.wikipedia.org/wiki/Synchronization_(computer_science), Visited: 4. August 2009.

[28] Wikipedia the free encyclopedia. Hough transform. http://en.wikipedia.org/wiki/Hough_transform, Visited: 8. August 2009.

151