Meca500 - Beckhoff TwinCAT3 Integration

Modified on Tue, 14 Mar 2023 at 05:38 PM

Description


This MecaNetwork example features the Meca500 being used with Beckhoff TwinCAT 3 over EtherCAT.

This can be used with different Beckhoff IPCs or other EtherCAT-based PCs.

This example features a simple Square Move pattern that runs in a loop.


Components


Meca500 Robot: Go to site

Meca500 Firmware version 8.1.6 or above is required: Go to site

Beckhoff TwinCAT3: Go to site


Attachments


TwinCAT 3 -SquareMoveDemo: Example Code



User guide: TwinCAT 3 and Mecademic Function Blocks


Beckhoff PLC

Software

The purpose of this document is to guide the user in integrating a Mecademic Robot with TwinCAT. This guide and the examples that are in it were done with version 15.0. 


Installing the ESI file

Proceed as follows:

1. Copy the ESI file into the TwinCAT installation directory: \TwinCAT\3.1\Config\Io\OnboardIo.
2.Create the folder manually if it doesn't exist.
3.Open TwinCAT and click in the menu under TwinCAT > EtherCAT Devices on Reload Device Description.


Prior to scanning your network in the TwinCAT environment, the following command must be sent to the robot in the web interface to change the network configuration from TCP/IP to EtherCAT.

If the previous steps were done correctly, upon scanning your network, you should see the Meca500.




Double-clicking on the robot in the Device tree will bring this configuration window.


In the EtherCAT tab, you will find the robot's EtherCAT address. 


In this example, the address is 1001.


To obtain the SmPdo variables to communicate with the robot, go into the Advanced Settings menu.


And Enable the Create SM/PDO Variables checkbox.


The variables are now created and you will find them in the Device Tree.


If you double-click on the variables (Meca500_SM_2 & Meca500_SM_3), you will find the Data type created by TwinCAT. These can be used in your PLC Project.

 

This Data Type number may change depending on the firmware that you use and should correspond to the Data Type used in the MecaSmPdo Structure.



You can then associate the corresponding Robot Input/Outputs to your code using the Linked to.. button in the Variable Tab of the SmPdo variable.



Using the function blocks

The following function blocks are provided by Mecademic to simplify the usage of the Meca500 with Beckhoff PLCs.

These instructions will be mirroring the commands present in the TCP/IP interface to enable ease of use and standardize the programming structure between the Web Interface and PLC programs.

 

Follow the steps below to use the Add-On Instructions in TwinCAT.

First, select the block that represents the command you want to send to your robot.

Populate the argument(s) field with the values you want to send for the selected command. The command will be sent to the robot on the first scan of the block or when one of the argument(s) values is modified.

If real-time updates are required, sending these instructions by updating the values should be the preferred method. However, it is recommended to update the values before enabling the blocks as this might give better control and prevent multiple instructions from being sent too rapidly if they are not all updated in the same scan.

Once the command has been sent, the sent bit from the block will become true and stay true until one of the arguments is modified or until the block is no longer enabled.

The buffered bit will become true when the MoveID (Internal or External) of the last command received by the robot equals the MoveID of the command sent by the block. When the Buffered bit becomes True it is an acknowledgment from the robot controller that it has received the command and added it to the FIFO command buffer queue.

 

At the end of the Case..Of in the example, you will find this code.

This code reset the Buffered and Sent Flag to False and then allows the sequence to go to the next step when the Robot has acknowledged the command sent.


To prevent communication problems, it is imperative to send one instruction at a time to a given robot. 

We recommend using a Grafcet-like structure, where each step can only execute one instruction.

It is also recommended to only have one instance of an instruction per robot, this facilitates future program debugging.


Motion Commands and MoveID

The way that robot can identify all of the different commands with the motion command number. Each command has its own unique number. The internal MoveID values of the FBs are closely related to the motion command values. Since the MoveID needs to be changed every time a new command is sent to the robot, the function block will alternate between two MoveIDs.

These two numbers will be constructed as such :

32
xx
0/1
Prefix
Motion command
Alternate between 0 and 1

Below are all the commands, their motion command value and their internal FB MoveID:

Commands

Motion Command value

FB MoveID

MoveJoints

1

32010-32011

MovePose

2

32020-32021

MoveLin

3

32030-32031

MoveLinRelTRF

4

32040-32041

MoveLinRelWRF

5

32050-32051

Delay

6

32060-32061

SetBlending

7

32070-32071

SetJointVel

8

32080-32081

SetJointAcc

9

32090-32091

SetCartAngVel

10

32100-32101

SetCartLinVel

11

32110-32111

SetCartAcc

12

32120-32121

SetTRF

13

32130-32131

SetWRF

14

32140-32141

SetConf

15

32150-32151

SetAutoConf

16

32160-32161

SetCheckpoint

17

32170-32171

Gripper

18

32180-32181

GripperVel

19

32190-32191

GripperForce

20

32200-32201

MoveJointsVel

21

32210-32211

MoveLinVelWRF

22

32220-32221

MoveLinVelTRF

23

32230-32231

VelCtrlTimeout

24

32240-32241

SetConfTurn2532250-32251
SetAutoConfTurn2632260-32261
SetTorqueLimits2732270-32271
SetTorqueLimitsCfg2832280-32281
MoveJointsRel2932290-32291
SetValveState3032300-32301
SetGripperRange3132310-32311
MoveGripper3232320-32321

StartOfflineProgram

100

31900-31901

These unique MoveIDs are useful for troubleshooting and knowing which commands were received or not by the robot. It is also important to not use these internal MoveID when using the external MoveID feature of the Function Blocks.


External MoveID

The external MoveID feature can be activated by setting the ExternalStateControl value to 1. When this is enabled, the user will need to input their own MoveID in the FB. The commands will be sent only when the external MoveID value is updated to a new value as with the internal MoveID. This feature can be useful for users who want more in-depth control of their sequence and who want to monitor the commands sent and received by the robot more closely.

It should be noted that this approach needs a careful and thorough understanding of how MoveID is being used in the robot controller and should only be used by more advanced users. It is also important to note that the values of the external MoveID should never be the same as the internal values of FB. If the user tries to input the same value as an internal value the error bit will become true on the FB.


Control Block

The Meca500Control Function Block helps manage the connection of the robot to the PLC. 

The block handles the change of state of the robot slave from the Init state to the Operational State using the Meca500.Connect variable. It can also be used to change back the network configuration from EtherCAT to TCP/IP using the Meca500.DisconnectFromEthercat variable. 

Its last functionality is to automatically handle the Activation, Homing, and reset Paused state & Errors of the robot.

This functionality might not be wanted and should be removed from the function block if not desired.


The sNetID can be found in the configuration of the EtherCAT device.



Please note that these examples are provided as-is by either Mecademic or it's Partners. These can be used as starting point for development and testing but Mecademic or it's partners are not under obligation to provide support and are not liable for any errors or unintended behavior caused by the examples. These examples could be updated over time.


This example was developed with a Beckhoff C6015 Industrial PC for the Meca500 v9.1.5 over Ethercat

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article