Bin Picking Tutorial: Setting up Photoneo Bin Picking Studio with STAUBLI robots
Contents
1. Prerequisities
Photoneo Stäubli Interface is compatible with CS9 controler.
Mozno by to islo aj na CS8 len je potrebne spravit upravy v kode. Pre instalaciu photoneo aplikacie je potrebne pouzit Stäubli Robotics Suite a mat k dispozicii licencny kluc
NOTE: Use of Stäubli Robotics Suite 2016.6.1 or higher is highly recommended for Photoneo Stäubli Interface setup.
2. CS9 Controller setup
The following tutorial gives a step by step guide of how to configure your Stäubli CS9 controller and install all necessary VAL3 applications you will need to get the robot interface for Photoneo Binpicking Solution up and running.
This tutorial was originally written using the latest Stäubli Robotics Suite 2016.6.1, however it should be compatible with older versions with minor changes.
2.1 Network configuration
Turn on the CS9 Controller, wait for the Initialization Screen to appear, open the Settings and select the Network option:
In the Network pane, setup your network interfaces. Jeden pre Robot Suite, druhy pre binpicking
3 STAUBLI Robotics Suite
3.1 Create new project
Klikny na new a potom na new cell wizard
Zadaj nazov projektu a cestu
Klikny next
vyber Add a local controller from a remote controller. Pre vyber je Add a local controller je potom potrebne rucne nastavit kontroler a robota
Nastav host kliknut na ...
Nastav IP robota, nastav user name na maintenance. Default heslo spec_cal
klikny na ok a nasledne na next
Ak je vsetko ok, tak sa napise hlaska
3.2 Copy the application
Nakopirovat progamy resp. priecinky (photoneo_common, customer_definitions, main_application) vo windows filesysteme z val3 (miesto kde budu ulozene programy) do vytvoreneho projektu: Project_name\Controller_name\usr\usrapp
V Staubli Robotics Suite kliknut v cell explorer na project_name->controller_name (pravym tlacidlom na controller_name) a vybrat open application a postupne vybrat vsetky 3 aplikacie. Otvarat je potrebne subory typu .pjx
Vysledkom by malo byt otvorene 3 aplikacie znazornene na obrazku
3.3 Nevyhnutne upravy phptoneo_common
3.3.1 Nastavenie fBaseLink
treba nastavit spravnu hodnotu Z offsetu (asi podla tabulky)
3.3.2 Nastavenie socketu
V hornej liste v home kliknut na Physical IO's. V tabulke pravym kliknut na socket a vybrat Edit Board
V novom okne je potrebne kliknut na + a vybrat tcp client
Vyplnit udaje podla fotky
Zopakovat to iste pre tcp server
Na zaver treba skontrolovat, ci globalna premenna sPHOCLIENT a sPHOSERVER su naozaj nalinkovane na vytvorene sockety.
sPHOCLIENT by mal v stlpci lo obsahovat Sockets\PhotoneoClient. Ak nie treba mu vybrat spravny socket dvojklikom na bunku v stlpci lo.
To iste je potrebne skontrolovat aj pre sPHOSERVER, ktory by mal obsahovat Sockets\PhotoneoStateServer.
3.3.3 Nastavenie start a end pose
V globalnych premennych jStartPose a jEndPose, treba nastavit vhodne hodnoty klbovych premmenych pre startovu a koncovu polohu binpickingu
3.4 Transfer files
Na presun suborov existuje nastroj Transfer manager v hornej liste v zalozke home. Po kliknuty na ikonu je potrebne pripojit sa na CS9 pod uzivatelom maintenance s prednastavenym heslom spec_cal
File:Robot staubli conection.png
Na zaver v okne transfer manager, treba zakliknut IO a VAL3 Applications, nasledne >> transfer >>.
3.5 Load Application
Ako prvy krok treba kliknut na tlacidlo na pendante, ktore je znazornene na obrazku zo simulacie
V skaredom ciernobielom okne treba nahrat applikaciu todo napisat aspon kombinaciu tlacidiel
At this point your Robot Controller is configured to work with Photoneo Binpicking Solution. However your VAL3 code must be adopted to meet your application requirements - you need to reteach HOME, START and END poses, update part placing, application logic, etc. The following section of the tutorial provides basic examples of how this can be programmed as well as a detailed explanation of Photoneo VAL3 API.
4. VAL3
Photoneo Staubli interface was designed to be easily integrated into existing application written in VAL3 code. It provides two means which influence the final robot behavior:
- VAL3 API - set of VAL3 requests (or procedures) used to control the bin picking sequence. Requests are defined in photoneo_common application and used within main_module application
- VAL3 CONFIG - customer_definitions application holds an application specific settings such as gripper commands, motion speed, precision and overall bin picking sequence definition.
4.1 VAL3 API
The following API describes the functionality of requests provided by Photoneo Stabli Interface. These requests are intended for high level control of bin picking sequences and are usually called in main_module application.
pho_request_init(jointtarget pho_start_bin_picking_pose, jointtarget pho_end_bin_piking_pose) - request to initialize bin picking application from the Vision Controller side. Start and End Poses defined by the operator from the RAPID side are transferred to the Vision Controller and used in the trajectory planning pipeline as start and terminus points.
pho_wait_for_server() - function to establish a connection to the Vision Controller. Blocking function; suspends the program until a proper connection is established. If the server running on the Vision Controller side is not running or does not respond, an error is raised and the RAPID program is terminated.
scan_request() - request to trigger the next scan and localization. Non-blocking request; the RAPID program continues immediately at the next line.
wait_for_scan_completition() - function to wait for scan to be finished. This should be called after triggering the scan, but not immediately
trajectory_request() - request to start trajectory planning for current goal. Non-blocking function; the RAPID program continues immediately at the next line.
pho_receive_trajectory() - function to receive requested bin picking trajectories (consisting of a sequence of trajectory and gripper operations). This is usually called inside pho_bin_picking() function by default. Blocking function; waits for motion data to be received.
pho_request_scan_and_traj() - function to trigger scan, localization and trajectory planning in a single shot. Blocking function; handy for initial bin picking experiments. For actual production it is more convenient to split this sequence into specific actions and call them accordingly (pho_request_scan & pho_request_trajectory).
pho_request_calib_add_point() - request to add calibration point - a scan is triggered and the calibration is recalculated. Blocking request; the program will not continue until the calibration result is recalculated and has been received by the Robot Controller.
pho_calib_set() - request to set current calibration result to the PhoXi Scanner
pho_calib_reset() - request to reset current calibration and remove all previously added points
pho_bin_picking() - request to execute bin picking operation. This usually receives the requested trajectory and performs motion execution. Blocking function; the program does not continue until the whole sequence is finished. Always make sure that the robot is in pho_start_bin_picking_pose before calling this function.
4.2 RAPID CONFIG
CustomerDefinitions module enables the user to configure several bin picking settings, including gripper command implementations, trajectory speed and precision adjustments.
- open_gripper() - implement function for opening your gripper here
- close_gripper() - implement function for closing your gripper here
- gripper_user_1() - implement custom user gripper command (reserved for future use)
- gripper_user_2() - implement custom user gripper command (reserved for future use)
- gripper_user_3() - implement custom user gripper command (reserved for future use)
- gripper_user_4() - implement custom user gripper command (reserved for future use)
- gripper_user_5() - implement custom user gripper command (reserved for future use)
- gripper_user_6() - implement custom user gripper command (reserved for future use)
- binpicking_settings() - specify speed and precision settings for bin picking trajectories. Adopt the suitable number of trajectories to meet your bin picking setup. (the default setting is 4 trajectories)
- pho_bin_picking_simple() - a very basic bin picking sequence (for experimental purposes)
- pho_bin_picking() - standard bin picking sequence. This flexible, operation-based implementation allows performing bin picking sequences, which consist of various numbers of operations to be performed. Do not edit !!!
4.3 RAPID ERROR HANDLING
Photoneo BP solution provides basic error handling. If an error occurs during bin picking operations, the PHO_OCCURED_ERR flag is set to true. The PHO_ERR_CODE variable contains the code of the specific error which will helps to identify the source of the problem.
PHO_NO_ERR := 0 - Service response from Vision Controller is valid
PHO_SERVICE_ERR := 1 - Service response from Vision Controller is invalid.
PHO_UNKNOWN_REQ := 2 - The Vision Controller received an unknown request.
PHO_COM_FAILURE := 3 - Communication failure due to socket closure.
PHO_BAD_DATA := 4 - Data validation check has failed.
PHO_TIMEOUT := 5 - Communication failure due to socket timeout.
PHO_PLANNING_FAILED := 201 - Trajectory planning has failed
PHO_NO_PART_FOUND := 202 - No part has been localized
PHO_NOT_INITIALIZED := 203 - Bin picking application has not been properly initialized on Vision Controller
PHO_PART_LOST := 204 - Part has been lost during motion execution
PHO_COLLISION_DETECT := 205 - Collision has been detected
PHO_UNKNOWN_ERR := 299 - Unspecified internal error
4.4 MAIN MODULE
The following section provides a detailed explanation of MainModule.mod - the module through which the user's application and Photoneo Bin Picking API are integrated together.
NOTE: If you use a pre-generated program from Robot Studio simulation do not use MainModule.mod directly. The following description serves only as an example of how to use Photoneo RAPID API.
4.4.1 main()
The main() procedure is simply a selection of which particular sub-procedure is about to be executed. Comment bin picking if you want to execute calibration comment calibration line if you want to execute bin picking.
MODULE MainModule ! Copyright (c) 2018 Photoneo s.r.o. ! All rights reserved ! Description: Main bin picking module ! ! Home, start and end binpicking target variables VAR robtarget home_pose; VAR robtarget start_bin_picking_robtarget; VAR robtarget end_bin_picking_robtarget; VAR jointtarget start_bin_picking_jointtarget; VAR jointtarget end_bin_picking_jointtarget; ! Error handling variables VAR num err_counter; CONST num MAX_ERR_COUNT := 2; PROC main() !calibration; ! If bin picking is about to be executed comment this line bin_picking; ! If calibration is about to be executed comment this line ENDPROC
4.4.2 bin_picking()
This is a basic bin picking template. The main program loop is defined here. The sser is can reteach bin picking start and end positions, set IP Address and Port of Vision Controller and adopt the placing part of the code to meet specific workcell and application requirements here.
! BIN PICKING ! This is a basic bin picking template. The main program loop is defined here. User is expected to reteach ! bin picking start and end positions, set IP Address and Port of Vision Controller and adopt placing part ! of the code to meet specific workcell and application requirements here. ! PROC bin_picking() ! Clear error counter for err_handling procedure err_counter := 0; PHO_ERR_CODE := PHO_PLANNING_FAILED; ! ! RETEACH home position for your application home_pose := [[99999.0, 99999.0, 99999.0],[0, 0, 0, 1],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]]; ! ! RETEACH bin picking start and end pose start_bin_picking_robtarget := [[99999.0, 99999.0, 99999.0],[0, 0, 0, 1],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]]; end_bin_picking_robtarget := [[99999.0, 99999.0, 99999.0],[0, 0, 0, 1],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]]; ! ! Convert cartesian position to jointtarget start_bin_picking_jointtarget := CalcJointT(start_bin_picking_robtarget, tool0); end_bin_picking_jointtarget := CalcJointT(end_bin_picking_robtarget, tool0); ! ! Connect to the the Vision Controller, adopt Vision Controller IP address and port here if needed pho_wait_for_server "192.168.1.6", 11004 ; ! ! Send bin picking initialization request to the Vision Controller, ! start and end poses defined above will be used in trajectory planning pipeline pho_request_init start_bin_picking_jointtarget, end_bin_picking_jointtarget; ! ! Move robot away from scanning area - reteach this position for your robot and workcell MoveJ home_pose, v500, z30, tool0; ! ! When robot is away from scanning area, trigger first scan and localization pho_request_scan; ! WHILE true DO scan_again: !==================== PHOTONEO BIN PICKING START =========================== ! Wait until scanning is completed pho_wait_for_scan_completion; ! ! Handle errors if occured IF (PHO_OCCURRED_ERR = TRUE) THEN err_handling; GOTO scan_again; ENDIF ! ! Trigger trajectory planning pho_request_trajectory; ! ! While trajectory is being calculated, move robot to bin picking start position MoveAbsJ start_bin_picking_jointtarget, v1000, z200, tool0; ! ! Execute bin picking application, calculated trajectory is received here pho_bin_picking; !==================== PHOTONEO BIN PICKING END =========================== ! ! Handle errors if occured IF (PHO_OCCURRED_ERR = TRUE) THEN err_handling; GOTO scan_again; ELSE ! Clear error counter for err_handling procedure err_counter := 0; ! !==================== PLACING START================================== ! Move robot from bin picking end position away from scanning area - reteach this position for your robot and workcell ! MoveJ [[171.40,-618.92,669.19],[9.66315E-05,-0.862481,-0.50609,-2.74185E-05],[-1,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v500, z30, tool0; ! ! Triger next scan and localization, trajectory for next cycle is calculated while object is being placed pho_request_scan; ! ! Commands for actual part placing - reteach positions for your robot and workcell ! MoveJ [[171.40,-618.92,669.19],[9.66315E-05,-0.862481,-0.50609,-2.74185E-05],[-1,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v500, z30, tool0; ! open_gripper; ! MoveJ [[171.40,-618.92,669.19],[9.66315E-05,-0.862481,-0.50609,-2.74185E-05],[-1,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v500, z30, tool0; !==================== PLACING END=================================== ENDIF ENDWHILE ENDPROC
4.4.3 calibration()
Reteach calibration positions and call pho_request_calib_add_point() requests after reaching each calibration pose. Users are recommended to run calibration in MANUAL mode in order to have full control over the process. Always make sure that the robot does not collide with the workcell during transitions between specific waypoints.
! CALIBRATION ! Reteach calibration positions and call add calibration point request after reaching each calibration pose ! It it recomended to run calibration in MANUAL mode step by step to have a proper control over the process. ! Always make sure that robot does not collide with workcell during transitions between specific waypoints PROC calibration() ! Connect to the the Vision Controller, adopt Vision Controller IP address and port here if needed pho_wait_for_server "192.168.1.6", 11004; ! ! 1. calibration waypoint MoveJ [[726.48,-170.77,397.89],[0.100326,-0.586168,0.431152,-0.678565],[-1,0,-2,1],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v100, fine, tool0; pho_request_calib_add_point; ! ! 2. calibration waypoint MoveJ [[784.48,103.21,289.54],[0.015591,-0.569148,0.439403,-0.694804],[0,0,-2,1],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v100, fine, tool0; pho_request_calib_add_point; ! ! 3. calibration waypoint MoveJ [[612.57,314.22,592.92],[0.191405,-0.613209,0.508347,-0.573517],[0,0,-2,1],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v100, fine, tool0; pho_request_calib_add_point; ! ! 4. calibration waypoint MoveJ [[1007.35,-482.44,270.24],[0.566579,-0.514948,0.502784,0.40128],[-1,0,-2,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v100, fine, tool0; pho_request_calib_add_point; ! ! 5. calibration waypoint MoveJ [[975.17,-513.44,199.63],[0.615751,-0.53949,0.418442,0.393329],[-1,0,-2,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v100, fine, tool0; pho_request_calib_add_point; ! ! 6. calibration waypoint MoveJ [[813.58,-34.08,404.19],[0.317364,-0.830642,0.138416,-0.436068],[-1,1,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v100, fine, tool0; pho_request_calib_add_point; ! ! Finally set calibration result to the PhoXi Scanner TPWrite "Setting calibration result to the PhoXi Scanner!"; pho_request_calib_set; TPWrite "Calibration complete!"; EXIT; ENDPROC
4.4.4 err_handling()
Several error situations might occur during bin picking procedures. Some problems are more serious, some less. For example, if no part is found or the trajectory planning fails, the program simply attempts to repeat the whole sequence. However, if a communication failure is detected, the program is halted immediately. PHO_ERR_CODE contains the error state from the last response from the Vision Controller.
! ERROR HANDLING ! Shit happens. Several error situations might occur during bin picking procedure. Some of them are more serious some are less. ! For example if no part is found or trajectory planning fails, program just tries to repeat the whole sequence. However if ! communication failure is detected, program is halted immediately. It is possible to adopt this behavior here if needed PROC err_handling() !--Release gripper if needed !open_gripper; ! Move robot to home pose MoveJ home_pose, v500, z30, tool0; !--Display error TPWrite pho_err_info(PHO_ERR_CODE); IF err_counter >= MAX_ERR_COUNT THEN ErrLog 4800, "Photoneo internal error", pho_err_info(PHO_ERR_CODE), "Please reboot the Vision controller and restart application"," ", " "; EXIT; ENDIF ! If planning failed or no part was found, notify user and continue by next scan (Adopt if needed) IF (PHO_ERR_CODE = PHO_PLANNING_FAILED OR PHO_ERR_CODE = PHO_NO_PART_FOUND) THEN TPWrite "NO PART FOUND OR PLANNING PATH FAILED"; pho_request_scan; ! If bin picking has not been initialized or service returned error response, reinitialize and trigger new scan (Adopt if needed) ELSEIF(PHO_ERR_CODE = PHO_NOT_INITIALIZED) THEN pho_request_init start_bin_picking_jointtarget, end_bin_picking_jointtarget; pho_request_scan; ! If bin picking service returned error response, reinitialize and trigger new scan (Adopt if needed) ELSEIF (PHO_ERR_CODE = PHO_SERVICE_ERR ) THEN Waittime 10; pho_request_init start_bin_picking_jointtarget, end_bin_picking_jointtarget; pho_request_scan; ! In case of communication failure, rapid program is terminated immediatelly ELSEIF (PHO_ERR_CODE = PHO_BAD_DATA OR PHO_ERR_CODE = PHO_TIMEOUT OR PHO_ERR_CODE = PHO_COM_FAILURE ) THEN ErrLog 4800, "Photoneo internal error", "Communication failure!", "Please reboot the Vision controller"," "," "; EXIT; ! Otherwise trigger next scan and try to continue ELSE pho_request_scan; ENDIF err_counter := err_counter + 1; ! reset error flag for next cycle PHO_OCCURRED_ERR := FALSE; ENDPROC
5. Runtime
Apply RAPID changes, restart the Robot Controller; if everything is set correctly, you should see the following info screen on the Pendant:
Make sure that the Bin Picking application on the Vision Controller side is running and waiting for a connection:
[[File: ]] (Tu asi pride screenshot z webu)
Open Main Menu, browse to Production Window and Set PP to Main - at the beginning of the main function:
Choose if you want to run the application in AUTO or MANUAL mode and adopt the speed override if required:
Hit the Play button in AUTO mode or Enable + Play button in MANUAL mode and you should see the following application output:
You should receive the notification that the Vision Controller has established a successful connection:
[[File: ]] (Tu asi pride screenshot z webu)
The robot should now start sending requests to the Vision Controller and execute bin picking movements.