Difference between revisions of "2D Camera Integration"

From Wiki
m (Added deprecation warning)
(Article rewritten for the integrated camera interface)
Line 1: Line 1:
''''' The plugin-based approach described in this article is deprecated, please use the integrated camera interface. Please refer to the video tutorial mentioned in [[Konfiguration|this article]] on how to set up the camera. This article will be updated in future. '''''
+
Cameras can be used by CPRog/iRC and the embedded control to pick objects at varying positions. This article explains the hardware and software set up for an IFM O2D camera.
  
Different cameras can be integrated in the CPRog software. This allows to pick parts with a not precisely defined position.
+
Currently supported are the following cameras that do the image processing and object recognition internally:
 +
* IFM O2D
 +
* [[Remote_Variable_Access#Protocol|Cameras that can send TCP/IP messages of the same format as the O2D]]
  
Currently plugins are available for:
+
Not supported are cameras that do not provide object information, e.g. video cameras or webcams. To use such cameras the user needs to implement their own processing application that [[Remote_Variable_Access|sends the data via the CRI or camera interface]] and run it on a separate device (in case of a robot with embedded control).
* IFM O2D, a compact camera with integrated image processing
 
* Matrox camera systems
 
  
Both systems aquire an image and process it internally. Then they send the target position via Ethernet to the CPRog software. Here they are received by an plugin and stored in a variable. This variable can be used in a motion.
+
The entire process is shown in this video (German): [https://youtu.be/OJcislaY9Ek Tutorial Kameraintegration]
  
'''German documentation is available here (german):
 
[https://www.cpr-robots.com/download/Camera/Dokumentation_PlugIn_IFM-O2D_V04.pdf Dokumentation_PlugIn_IFM-O2D_V04.pdf (DE)] The english version of that same documentation is being worked on at the moment.
 
'''
 
 
----------------------------------------
 
 
 
 
 
 
 
'''UNDER CONSTRUCTION. Currently the English translation of the documentation linked above is being generated'''
 
 
=Scope=
 
This document explains the use of an IFM 3D camera in CPRog.
 
 
=Safety=
 
=Safety=
 
* [[file:Caution.png|20px]] Caution! Personal safety has to be ensured during operation.
 
* [[file:Caution.png|20px]] Caution! Personal safety has to be ensured during operation.
Line 32: Line 17:
 
=Mechanical and electrical setup=
 
=Mechanical and electrical setup=
 
[[file:IFM_camera_vectors.png|thumb|right|600px|Preferred camera mounting position]]
 
[[file:IFM_camera_vectors.png|thumb|right|600px|Preferred camera mounting position]]
The camera has to be mounted at ample height above the work-pieces. Care has to be taken to avoid any collisions. For acceptance cone and minimum distance from camera, please look at the IFM-Documentation.
+
The camera has to be mounted at ample height above the workpieces. Care has to be taken to avoid any collisions. Please refer to the documentation of the camera for acceptance cone and minimum distance.
  
*The camera should be mounted parallel to the coordinate axes of the robot, if at all possible. - That means either overhead, in front or from the side. This will simplify calibration significantly (see image on the right).
+
*The camera should be mounted parallel to the coordinate axes of the robot if possible. - That means either overhead, in front or from the side. This will simplify calibration significantly (see image on the right).
  
 
*Power requirements: Connect the leads of the black power cable to a 24V supply:
 
*Power requirements: Connect the leads of the black power cable to a 24V supply:
 
** blue lead: GND
 
** blue lead: GND
** brown lead: 24V (please verify the pin configuration with the IFM-Dokumentation).
+
** brown lead: 24V (please verify the pin configuration with the documentation of the camera).
 
<br clear=all>
 
<br clear=all>
  
Line 45: Line 30:
 
*Plug ethernet cable into camera and PC.
 
*Plug ethernet cable into camera and PC.
 
*Set IP of PC to a free IP in the <code>192.168.0/24</code> range, e.g. <code>192.168.0.50</code>
 
*Set IP of PC to a free IP in the <code>192.168.0/24</code> range, e.g. <code>192.168.0.50</code>
*Camera IP is factory configured for <code>192.168.0.49</code>. So do not use this particular IP on your computer. It belongs to the camera already and you don't want them to be the same.
+
*Camera IP is factory configured for <code>192.168.0.49</code>. So do not use this particular IP on your computer.
 
<br clear=all>
 
<br clear=all>
  
Line 51: Line 36:
 
[[file:IFM_camera_configuration_E2D200.png|thumb|right|600px|IFM Camera TCP/IP setings]]
 
[[file:IFM_camera_configuration_E2D200.png|thumb|right|600px|IFM Camera TCP/IP setings]]
  
The image processing is done entirely in camera. To recognize a work-piece an "application" has to be set up containing the model of the work-piece. The camera settings are configured using the IFM Software efector dualis E2D200.
+
The image processing is done entirely in camera. To recognize a workpiece an "application" has to be set up containing the model of the workpiece. The camera is configured using the IFM Software efector dualis E2D200.
 +
 
 +
Communication with the robot control requires the following settings:
 +
* TCP/IP settings:
 +
** Without embedded control: Keep the factory defaul IP address or use one of your choice in the network of your computer.
 +
** With Raspberry Pi-based embedded control: 192.168.3.49 or a different address in that same network but not 192.168.3.11. Since this ethernet port is used for connecting the computer you may need to use a network switch so you can connect both.
 +
** With Phytec-based embedded control:
 +
*** Ethernet port 2 (recommended): 192.168.4.49 or a different address in that same network but not 192.168.4.11.
 +
*** Ethernet port 1: See Raspberry Pi-based control.
 +
After changing the IP address you may need to update the IP address of your computer as described in section [[2D_Camera_Integration#PC Network Configuration|PC Network Configuration]] otherwise you may not be able to connect to the camera.
  
Communication with the CPRog-Plugin requires the following settings:
 
* General TCP/IP settings: The TCP/IP address and port configuration have to remain the IFM factory defaults.
 
 
* An [[media:TestConfig_IFM-O2D_CPR.zip|example camera configuration]] can be downloaded here - it is set up to recognize a 2 Euro coin in our lighting conditions and camera set up. (Your mileage may vary. This file is provided to make sure that parameters, such as IP and result output are correct.) To get it to actually recognize a coin, read the IFM documentation. The file has to be unzipped before loading it by right clicking on an unused folder in the "Applications" dialogue and selecting "Download to Sensor" followed by right clicking on the same folder and selecting "Activate". Not that the IP configuration of the camera is also updated (to the defaultsettings) when doing that (192.168.0.49).
 
* An [[media:TestConfig_IFM-O2D_CPR.zip|example camera configuration]] can be downloaded here - it is set up to recognize a 2 Euro coin in our lighting conditions and camera set up. (Your mileage may vary. This file is provided to make sure that parameters, such as IP and result output are correct.) To get it to actually recognize a coin, read the IFM documentation. The file has to be unzipped before loading it by right clicking on an unused folder in the "Applications" dialogue and selecting "Download to Sensor" followed by right clicking on the same folder and selecting "Activate". Not that the IP configuration of the camera is also updated (to the defaultsettings) when doing that (192.168.0.49).
 
(Communication with TinyCtrl on an embedded Linux computer requires a different IP address due to the default configuration of that embedded Linux computer, which is itself configured for IP 192.168.4.11 by default. Hence the camera would have to be in the same IP range, e.g. 192.168.4.49. Initially, to simplify the setup, the camera configuration will always be done in Windows and at the very end the IP will be reconfigured to match the IP range of the network adapter in the Linux embedded computer.)
 
 
<br clear=all>
 
<br clear=all>
  
 
[[file:IFM_camera_configuration_E2D200_1.png|thumb|right|600px|IFM Protocol Version settings]]
 
[[file:IFM_camera_configuration_E2D200_1.png|thumb|right|600px|IFM Protocol Version settings]]
*The Protocol Version has to remain in the factory default setting.
+
*The Protocol Version must be V2 and the output format ASCII.
 
<br clear=all>
 
<br clear=all>
  
Line 70: Line 60:
 
** "Result Output" to On
 
** "Result Output" to On
 
** "Model Detail Output" to On  
 
** "Model Detail Output" to On  
 
+
** "Start sring" to "start"
 +
** "Stop string" to "stop"
 +
** "Separator" tp "#"
 +
** "Image output" may be On or Off. Set this to "On" if you want to be able to see the camera's image in CPRog/iRC, otherwise "Off" is recommended
 +
** "Image format" to "Windows bitmap"
 
<br clear=all>
 
<br clear=all>
  
=Plugin Installation=
+
Make sure that the camera recognizes your object reliably enough before proceeding to the next step.
The plugin has to be installed in the Data\Plugins folder as described below for CPRog on Windows and also for the embedded computer (Linux). If the communication between your robot and the Windows PC is via the white PCAN-USB adapter and the camera is connected to your Windows PC, you just need to follow the CPRog instructions and can skip over the TinyCtrl instructions. If not, you have an embedded computer built into your robot or the control cabinet. The software running on that embedded computer is called TinyCtrl. In that case you need to follow both, the CPRog and the TinyCtrl instructions below.
 
===CPRog===
 
[[file:IFM_camera_plugin_directory.png|thumb|right|600px|Plugins Directory]]
 
A plugin is required to use the IFM camera. It connects via ethernet to the camera and translates and transmits the data received from the camera to the robot control electronics.
 
  
Download, unzip and copy the following files in the zip file below to <code>C:\CPRog\Data\Plugins\</code>
+
=Setting up the robot control=
* [[media:ConfigSmartCameraIFMO2D.zip|ConfigSmartCameraIFMO2D.zip]]
+
==Calibration and configuration with CPRog/iRC==
 +
[[File:Camera_Configuration.jpeg|thumb|right|600px|Configuration in CPRog/iRC]]
 +
[[file:IFM_camera_vectors.png|thumb|right|600px|Measure the parameters off your camera setup]]
  
An example program ([[media:Example_IFM_Camera.zip|Example_IFM_Camera.xml]]) can be saved to <code>C:\CPRog\Data\Programs\</code> and unzipped.
+
Now that the camera is ready to deliver object model and position information the robot control needs to be set up to connect to the camera and calculate the object/pick positions in 3D space.
<br clear=all>
 
  
===TinyCtrl===
+
* Start CPRog/iRC and connect it to the robot if you are using one with embedded control.
For TinyCtrl only the xml file contained in [[media:ConfigSmartCameraIFMO2D.zip|ConfigSmartCameraIFMO2D.zip]] is required.  
+
* Open the camera configuration: File -> Configure Interfaces -> Cameras
 +
* Add a new camera of type "IFM O2D".
  
It needs to be copied into the folder <code>/home/root/TinyCtrl/Data/Plugins</code> on the embedded computer.  
+
The configuration area should look similar to the screenshot on the right.
  
After that the robot has to be restarted. [[FTP_and_putty_Access|Here]] is a guide that explains how to gain access to the embedded computer to copy files.
+
===General settings===
 +
These settings refer to the connection to the camera and enable it to be used in a robot program.
  
=Use of the plugin within a robot program=
+
* '''Enabled''': This enables the camera in CPRog/iRC. If it is disabled the values from the simulation section will be used. Keep this disabled if you are using an embedded control, otherwise CPRog/iRC might prevent the embedded control from receiving data from the camera.
[[file:CPRog_Program_Editor_Camera_PLugin_Commands.png|thumb|600px|Commands to get the camera up and running]]
+
* '''Image enabled''': If an image is received it will be shown in the camera status section in CPRog/iRC.
Three commands have to be inserted in the Program editor to get the camera up and running. These commands can be added via the menu item "Advanced Commands"
+
* '''Name''': This name identifies the camera in the robot program.
 +
* '''Description''': An optional description, this setting has no effect.
 +
* '''IP address''': IP address of the camera as set up earlier in this article.
 +
* '''Port''': Port number of the camera, by default 50010.
  
*In the first line a position variable is defined. This variable is used to store the target position.
+
===Geometry settings===
*in the second line a Number variable is defined. This variable is used to store the model type. Once the camera has recognized an object it is set to <code>-1</code>.
+
These settings are used to calibrate the camera so that the correct positions in 3D space are calculated from the received data. Refer to the image on the right on how to measure these values.
*The command "PlugInTargetPos" calls a plugin that returns a target position. It takes the following arguments
 
** Name of the plugin to be used (here "PluginSmartCameraIFMO2D").
 
**a variable for the target position
 
**a variable for the model type.
 
*The plugin overwrites only the X, Y, Z and A (=rotation around Z) values. The rotation values B and C remain as they were. Therefore, upon definition of the variable the robot should already have been positioned so that it can grip the object with the current B and C values.
 
 
 
The [[media:Example_IFM_Camera.zip|example program]] uses the plugin. It moves the robot to a starting position and asks the plugin for a target position.
 
[[file:Example_IFM_Camera.png|thumb|600px|Example Program]]
 
 
 
When the variable "modelclassvar" becomes <code>-1</code> a small up and down movement is carried out.
 
 
 
Otherwise the robot will move to the target position by using the command "LinearByVariable".
 
 
 
==Plugin Configuration Dialogue==
 
In general, a new program should always be run in simulation prior to using it on the actual robot. To run the program in simulation simply click the plug button in CPRog to disconnect the robot. As soon as the Status light in CPRog changes (from red or green) to grey, you are in simulation mode.
 
 
 
When running the program for the first time, the plugin configuration window opens. '''Do not close this window. Keep it open! If an error message appears, confirm the error message with "OK", "yes" or "no"''' Here the camera position needs be configured.
 
 
 
[[file:IFM_camera_config.png]]
 
 
 
* This is the place where the '''IP-Address''' of the camera, which has been left at the default setting earlier in this how-to (192.168.0.49), has to be entered.
 
* The default settings in this configuration window are identical to the IFM defaults.
 
 
 
* '''Pixel-to-coordinate-conversion''': The camera outputs the object position results in pixels and hands it over to the plugin. To calculate the robot target position the pixel values have to be multiplied with the scaling factor. The scaling factor is dependent on the distance between camera and the surface the camera looks at (see next section).
 
 
 
* '''Geometry Setup''': The position of the camera has to be defined relative to the robot. This is necessary to transfer the target position (in camera pixels) into an absolute position in the robot coordinate system.
 
  
 +
* '''Scaling''': The camera outputs the object position results in pixels and hands it over to the plugin. To calculate the robot target position the pixel values have to be multiplied with the scaling factor. The scaling factor is dependent on the distance between camera and the surface the camera looks at (see next section).
 
* '''Origin''': The position of the camera in the robot coordinate system (x/y/z value).
 
* '''Origin''': The position of the camera in the robot coordinate system (x/y/z value).
 +
* '''Look Vector''': The viewing direction of the camera. In the image the camera looks down in negative Z direction.
 +
* '''Up Vector''': This vector defines the rotation of the camera around the target axis, i.e. top and bottom in a 2D image.
 +
* '''Pick Distance''': Is the distance between the top of the workpiece and the camera.
  
* '''Look Vec(tor)''': The viewing direction of the camera. In the image above, the camera looks down onto the work surface that the robot sits on, hence it looks in negative Z direction.
+
===Simulation settings===
* '''Up Vec(tor)''': This vector defines the rotation of the camera around the target axis, i.e. top and bottom in a 2D image.
+
The simulation settings are used when the camera is not enabled in CPRog/iRC. Simulation is not available in the embedded control. These values simulate the information received from the camera before transformation to 3D space, therefore the simulated object position will differ from these values.
* '''Pick Distance''': Is the distance between the top of the work-piece and the camera.
+
* '''Sim X''' and '''Sim Y''': Simulated object position in camera image space (usually 0-640 and 0-480)
 +
* '''Sim A''': object orientation
 +
* '''Model class'''
  
*'''Example''': Work-piece located in the center below the camera would produce a target position (120, 120, 35)
+
Click "Save Project" to save the changes in CPRog/iRC and the embedded control (if connected). Test the settings carefully, preferably in simulation first, with a low override. Watch whether the robot collides with the ground surface or object.
 +
<br clear=all>
  
*'''Test Configuration''': For testing purposes the plugin can be configured so that it produces a target position, even when the camera is disconnected. This is so that a program can be tested in simulation mode: When the tick before "Override Camera" is set target position and model class defined in the line below is returned by the plugin.
+
==Camera status==
*'''Status''': Here the status of the camera connected is shown, i.e. the connection status and the current target position in pixels and mm.
+
[[File:IRC_CameraStatus.PNG|thumb|500px|The status area shows the camera status and object information]]
  
* To apply any changes made in this window, the '''"Update"''' button needs to be clicked. The changes will then be uploaded to the camera and also saved in the camera configuration file, so that they are not lost after restart.
+
Once configured the status area in CPRog/iRC will show the status of the camera and the position and model class of the recognized object. If the camera image is enabled it will be shown there as well.
 +
<br clear=all>
  
===Status===
+
==Using the camera in a robot program==
During operation the values that the camera returns (position and model type) can be checked in the in the "variables" tab at the bottom of CPRog.
+
[[file:Example_IFM_Camera.png|thumb|600px|Example Program]]
 
 
[[file:IFM_plugin_status_cprog.png]]
 
 
 
==Calibration==
 
'''Note''': Please always set the "Pick Distance" initially, so that there are several cm of space between surface and robot arm. Set the override percentage to a low value, so that the robot moves slowly while testing. Be prepared to stop the program by clicking the "stop" button (or using the emergency stop).
 
 
 
'''The values in the image below are only examples.'''
 
 
 
 
 
[[file:IFM_camera_vectors.png|thumb|center]]
 
 
 
The followings steps need to be carried out for a successful calibration
 
 
 
# '''Mount the camera''' and write a motion program that uses the camera (or use the example program provided above).
 
# Manually '''measure the camera position''' in the robot coordinate system using a ruler and enter the results in the fields "Origin", "Look Vec", "Up Vec" und "Pick Distance".
 
#'''Center point''': Test whether the robot grips a work-piece located in the center of the field of view of the camera. It is significantly easier to configure a camera that is mounted parallel or at right angles relative to the robot coordinate system. Odd angles complicate the calibration. Ideally the camera is located parallel to the work surface looking down on it and not looking down at the work surface at e.g. 60 degrees.
 
#*Place an object directly below the center of the camera, so that the pixel position 320 and 240 is shown in the status section of the plugin window. That is the center of the field of view of the camera.
 
#* Jog the robot to above that position. Axis 5 has to be orthogonal to the work surface (parallel to Z). Now adapt the values in the fiel "Origin", so that they reflect the robot position.
 
#* Leave the work-piece where it is and test a program that uses the camera (you could use the example program provided above). If necessary correct the "Origin" values.
 
# '''Orientation''': Check the orientation of the camera
 
#*Move the work-piece slightly in X direction. Check whether the position shown in the "status" section of the plugin window changes in the right direction. If it does not, the "Up Vec" needs to be updated to reflect the correct position of the camera.
 
 
 
==Calibration==
 
'''Note''': Please always set the "Pick Distance" initially, so that there are several cm of space between surface and robot arm. Set the override percentage to a low value, so that the robot moves slowly while testing. Be prepared to stop the program by clicking the "stop" button (or using the emergency stop).
 
 
 
The followings steps need to be carried out for a successful calibration
 
 
 
# '''Mount the camera''' and write a motion program that uses the camera (or use the example program provided above).
 
# Manually '''measure the camera position''' in the robot coordinate system using a ruler and enter the results in the fields "Origin", "Look Vec", "Up Vec" und "Pick Distance".
 
#'''Center point''': Test whether the robot grips a work-piece located in the center of the field of view of the camera. It is significantly easier to configure a camera that is mounted parallel or at right angles relative to the robot coordinate system. Odd angles complicate the calibration. Ideally the camera is located parallel to the work surface looking down on it and not looking down at the work surface at e.g. 60 degrees.
 
#*Place an object directly below the center of the camera, so that the pixel position x=0 and y=0 is shown in the status section of the plugin window. That is the center of the field of view of the camera.
 
#* Jog the robot to above that position. Axis 5 has to be orthogonal to the work surface (parallel to Z). Now adapt the values in the fiel "Origin", so that they reflect the robot position.
 
#* Leave the work-piece where it is and test a program that uses the camera (you could use the example program provided above). If necessary correct the "Origin" values.
 
# '''Orientation''': Check the orientation of the camera
 
#*Move the work-piece slightly in X direction. Check whether the Position shown in the "status" section of the plugin window changes in the right direction. If it does not, the "Up Vec" needs to be updated.
 
# If you do not have an embedded linux computer as part of your control electronics, you can now reset and enable the robot and try out the program in the real world. You may have to adapt the scaling factor, if you find that the robot does find the center point but does not move far enough in X or Y direction, when the recognized object is not in the center.
 
# If you do have an embedded Linux computer, '''take a screenshot of the settings of the plugin configuration dialogue or write them down.''' You will need them, if you have an embedded Linux computer as part of your control electronics.
 
 
 
==TinyCtrl==
 
The embedded linux computer, which is part of the robolink DCi robot or can be purchased as an option for the DIN rail control electronics, uses a program called TinyCtrl. TinyCtrl is the Linux equivalent to CPRog. The embedded computer is used so that a robot can be run without an external Windows PC.
 
 
 
===Configure new IP address===
 
When an embedded computer is used, the camera needs to be connected to the embedded computer, after it has been configured as described above. The first step to connecting the camera to the embedded system is to configure the correct IP address (192.168.'''4'''.49):
 
# Close CPRog
 
# Start the IFM Object Recognition software and connect to your sensor, which should still be connected to your Windows PC (in this tutorial that is IP 192.168.0.49).
 
# Go to "Applications" and select the tab called "Network Parameters" in the lower part of the window.
 
#* Configure '''IP address''' to <code>192.168.4.49</code>
 
#* Configure '''Subnet Mask''' to <code>255.255.255.0</code>
 
#* Configure '''Gateway''' to <code>192.168.4.201</code>
 
#* Click "Assign". The camera will now loose connection to your windows PC.
 
#* Connect the green LAN cable between Camera and Embedded Linux Computer. The correct port to use is the lower (ETH1) port of the DIN Rail embedded computer or the left LAN port of the robolink DCi embedded computer.
 
#* ''(The IP configured here will later on be referenced in the plugin configuration file. The second network adapter (ETH1 of the Linux embedded system) is by default configured for 192.168.4.11. So do not use that particular IP here))''
 
  
===Install and update the configuration file===
+
The screenshot shows how the camera can be used in a robot program.
Now connect to your Linux embedded computer via LAN.
+
# Declare two variables using the store command: A position variable for the object position and a number variable for the model class.
 +
# Use the Camera command to copy object information into the variables. This command does not wait, if no new information is available it will return the previous values again. If no object is recognized the model class will be -1, the position value must not be used in that case.
 +
# Use an If statement to check whether the model class is greater than -1.
 +
# In that case you may proceed to use the object position. In CPRog/iRC and TinyCtrl earlier than V12 only the cartesian object position is available, you can not use joint commands to move to the object. Joint commands in V12 and later may be faster than linear commands.
  
*Use any of the methods outlined [[FTP_and_putty_Access|in this link]] to edit the configuration file located in <code>/home/root/TinyCtrl/Data/Plugins/ConfigSmartCameraIFMO2D.xml</code>. The FTP method is usually easiest for someone with no prior experience in Linux terminal.
+
[[File:Example_IFM_Camera_NoOrientation.PNG|thumb|600px|Overwrite the object orientation if the robot moves slowly]]
*Find this line in the configuration file:
+
'''Attention 1:''' Your robot might moves to the object slower than usual, especially if your robot has no orientation axis (e.g. gantries and deltas). To fix this you can overwrite the orientation values of the target position variable. The approach show in the screenshot should work in all cases. If you are using a gantry, delta or SCARA without orientation axis / 4th axis you can use the constant A,B,C values shown in the Infocenter instead of using the additional CurrentPosition variable.
**<code><Cam0Geometry MaxWaitTime="5" ScaleX = "0.25" ScaleY="0.25" OriginX="120" OriginY="120" OriginZ="335" LookX="0" LookY="0" LookZ="-1" UpX="0" UpY="1" UpZ="0" ZDistance="300" SimX="350" SimY="-100" SimA="350" SimModelClass="4"/>"</code>
 
**Update the OrgingX, OriginY, OriginZ, LookX, LookY, LookZ, UpX, UpY, UpZ values and the ZDistance values with the values that you have noted down or made a screenshot of in the calibration step [[file:IFM_camera_config.png|thumb]].
 
  
*After editing and saving that file (ConfigSmartCameraIFMO2D.xml) into the directory <code>/home/root/TinyCtrl/Data/Plugins/</code> on the Linux computer.
+
'''Attention 2:''' In case of robot arms: Linear commands may not be able to move to your object position from each position. Make sure your object can be reached reliably or use a joint command to move close to the gripping position and use a linear command for the last cm if necessary.
*Power cycle the robot.
 
*Start CPRog and upload the unzipped [[media:Example_IFM_Camera.zip|example program]] that you have used earlier in this tutorial.
 
*Check, if the robot moves to the correct position when the coin is placed in the center below the camera.
 
* Check, if the robot moves too far or not far enough, when placing the coin outside the center in X and Y direction.
 
** You will likely need to change the scaling factors ('''ScaleX''' and '''ScaleY''') in the config file on the Linux computer (ConfigSmartCameraIFMO2D.xml) to make the robot move the right distance, when the work piece is located off-center. The scaling factor is essentially the factor for the conversion between pixels and mm.
 
  
 +
[[media:CameraExample.zip|You can download the example program here.]]
  
[[Category:CPRog]][[Category:CPRog Plugins]]
+
[[Category:CPRog]][[Category:TinyCtrl]]

Revision as of 16:32, 9 June 2021

Cameras can be used by CPRog/iRC and the embedded control to pick objects at varying positions. This article explains the hardware and software set up for an IFM O2D camera.

Currently supported are the following cameras that do the image processing and object recognition internally:

Not supported are cameras that do not provide object information, e.g. video cameras or webcams. To use such cameras the user needs to implement their own processing application that sends the data via the CRI or camera interface and run it on a separate device (in case of a robot with embedded control).

The entire process is shown in this video (German): Tutorial Kameraintegration

Safety

  • Caution.png Caution! Personal safety has to be ensured during operation.
  • Caution.pngThis is especially relevant during configuration and set up of the camera application. All motion has to be carried out at slow speeds.
  • Caution.pngThe operator has to be ready to stop the robot
  • Caution.pngIt is recommended that all programs are tested in the simulation prior to moving the robot.

Mechanical and electrical setup

Preferred camera mounting position

The camera has to be mounted at ample height above the workpieces. Care has to be taken to avoid any collisions. Please refer to the documentation of the camera for acceptance cone and minimum distance.

  • The camera should be mounted parallel to the coordinate axes of the robot if possible. - That means either overhead, in front or from the side. This will simplify calibration significantly (see image on the right).
  • Power requirements: Connect the leads of the black power cable to a 24V supply:
    • blue lead: GND
    • brown lead: 24V (please verify the pin configuration with the documentation of the camera).


PC Network Configuration

PC network address configuration
  • Plug ethernet cable into camera and PC.
  • Set IP of PC to a free IP in the 192.168.0/24 range, e.g. 192.168.0.50
  • Camera IP is factory configured for 192.168.0.49. So do not use this particular IP on your computer.


Camera configuration

IFM Camera TCP/IP setings

The image processing is done entirely in camera. To recognize a workpiece an "application" has to be set up containing the model of the workpiece. The camera is configured using the IFM Software efector dualis E2D200.

Communication with the robot control requires the following settings:

  • TCP/IP settings:
    • Without embedded control: Keep the factory defaul IP address or use one of your choice in the network of your computer.
    • With Raspberry Pi-based embedded control: 192.168.3.49 or a different address in that same network but not 192.168.3.11. Since this ethernet port is used for connecting the computer you may need to use a network switch so you can connect both.
    • With Phytec-based embedded control:
      • Ethernet port 2 (recommended): 192.168.4.49 or a different address in that same network but not 192.168.4.11.
      • Ethernet port 1: See Raspberry Pi-based control.

After changing the IP address you may need to update the IP address of your computer as described in section PC Network Configuration otherwise you may not be able to connect to the camera.

  • An example camera configuration can be downloaded here - it is set up to recognize a 2 Euro coin in our lighting conditions and camera set up. (Your mileage may vary. This file is provided to make sure that parameters, such as IP and result output are correct.) To get it to actually recognize a coin, read the IFM documentation. The file has to be unzipped before loading it by right clicking on an unused folder in the "Applications" dialogue and selecting "Download to Sensor" followed by right clicking on the same folder and selecting "Activate". Not that the IP configuration of the camera is also updated (to the defaultsettings) when doing that (192.168.0.49).


IFM Protocol Version settings
  • The Protocol Version must be V2 and the output format ASCII.


IFM IO configuration
  • Select you newly created project and click on the edit button on the LEFT.
  • Then click on "Process Interface" and "Change Settings". The window "IO configuration" appears.
  • In the "TCP/IP settings" set
    • "Result Output" to On
    • "Model Detail Output" to On
    • "Start sring" to "start"
    • "Stop string" to "stop"
    • "Separator" tp "#"
    • "Image output" may be On or Off. Set this to "On" if you want to be able to see the camera's image in CPRog/iRC, otherwise "Off" is recommended
    • "Image format" to "Windows bitmap"


Make sure that the camera recognizes your object reliably enough before proceeding to the next step.

Setting up the robot control

Calibration and configuration with CPRog/iRC

File:Camera Configuration.jpeg
Configuration in CPRog/iRC
Measure the parameters off your camera setup

Now that the camera is ready to deliver object model and position information the robot control needs to be set up to connect to the camera and calculate the object/pick positions in 3D space.

  • Start CPRog/iRC and connect it to the robot if you are using one with embedded control.
  • Open the camera configuration: File -> Configure Interfaces -> Cameras
  • Add a new camera of type "IFM O2D".

The configuration area should look similar to the screenshot on the right.

General settings

These settings refer to the connection to the camera and enable it to be used in a robot program.

  • Enabled: This enables the camera in CPRog/iRC. If it is disabled the values from the simulation section will be used. Keep this disabled if you are using an embedded control, otherwise CPRog/iRC might prevent the embedded control from receiving data from the camera.
  • Image enabled: If an image is received it will be shown in the camera status section in CPRog/iRC.
  • Name: This name identifies the camera in the robot program.
  • Description: An optional description, this setting has no effect.
  • IP address: IP address of the camera as set up earlier in this article.
  • Port: Port number of the camera, by default 50010.

Geometry settings

These settings are used to calibrate the camera so that the correct positions in 3D space are calculated from the received data. Refer to the image on the right on how to measure these values.

  • Scaling: The camera outputs the object position results in pixels and hands it over to the plugin. To calculate the robot target position the pixel values have to be multiplied with the scaling factor. The scaling factor is dependent on the distance between camera and the surface the camera looks at (see next section).
  • Origin: The position of the camera in the robot coordinate system (x/y/z value).
  • Look Vector: The viewing direction of the camera. In the image the camera looks down in negative Z direction.
  • Up Vector: This vector defines the rotation of the camera around the target axis, i.e. top and bottom in a 2D image.
  • Pick Distance: Is the distance between the top of the workpiece and the camera.

Simulation settings

The simulation settings are used when the camera is not enabled in CPRog/iRC. Simulation is not available in the embedded control. These values simulate the information received from the camera before transformation to 3D space, therefore the simulated object position will differ from these values.

  • Sim X and Sim Y: Simulated object position in camera image space (usually 0-640 and 0-480)
  • Sim A: object orientation
  • Model class

Click "Save Project" to save the changes in CPRog/iRC and the embedded control (if connected). Test the settings carefully, preferably in simulation first, with a low override. Watch whether the robot collides with the ground surface or object.

Camera status

The status area shows the camera status and object information

Once configured the status area in CPRog/iRC will show the status of the camera and the position and model class of the recognized object. If the camera image is enabled it will be shown there as well.

Using the camera in a robot program

Example Program

The screenshot shows how the camera can be used in a robot program.

  1. Declare two variables using the store command: A position variable for the object position and a number variable for the model class.
  2. Use the Camera command to copy object information into the variables. This command does not wait, if no new information is available it will return the previous values again. If no object is recognized the model class will be -1, the position value must not be used in that case.
  3. Use an If statement to check whether the model class is greater than -1.
  4. In that case you may proceed to use the object position. In CPRog/iRC and TinyCtrl earlier than V12 only the cartesian object position is available, you can not use joint commands to move to the object. Joint commands in V12 and later may be faster than linear commands.
Overwrite the object orientation if the robot moves slowly

Attention 1: Your robot might moves to the object slower than usual, especially if your robot has no orientation axis (e.g. gantries and deltas). To fix this you can overwrite the orientation values of the target position variable. The approach show in the screenshot should work in all cases. If you are using a gantry, delta or SCARA without orientation axis / 4th axis you can use the constant A,B,C values shown in the Infocenter instead of using the additional CurrentPosition variable.

Attention 2: In case of robot arms: Linear commands may not be able to move to your object position from each position. Make sure your object can be reached reliably or use a joint command to move close to the gripping position and use a linear command for the last cm if necessary.

You can download the example program here.