Difference between revisions of "Category:EtherCAT:EC SETUP"
(45 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Languages|EtherCAT:EC_SETUP}} | ||
{{Category | {{Category | ||
− | |description=How to | + | |description=How to Set up EtherCAT. |
|frontpage=[[EtherCAT]] | |frontpage=[[EtherCAT]] | ||
+ | ==Introduction== | ||
+ | Before starting to work with the softMC, you must setup the EtherCAT master to work with the slaves.<br/> | ||
+ | You must configure the axes in the system in a certain manner, then invoke certain functions and subroutines in an orderly manner, and make sure no errors occur. | ||
− | + | A CONFIG.PRG and a program file EC_SETUP.PRG exist in the repository, and demonstrate the following process. | |
− | + | ||
− | A CONFIG.PRG and a program file EC_SETUP.PRG exist in the repository, and demonstrate the following process. | + | CONFIG.PRG allocates an array of generic axes by the name Axes[], and sets all the existing axes in the system into this array.<br/> |
− | + | {{Note| Since verison 0.4.15.3rc6 the global axis array systemAxis[] is introduced, and the array Axes[] is made redundant, therefore it is removed from CONFIG.PRG }} | |
− | CONFIG.PRG allocates an array of generic | + | EC_SETUP.PRG and AX_SETUP.PRG use this array to setup the system automatically. |
− | EC_SETUP.PRG and AX_SETUP.PRG use this array to setup the system automatically. | ||
{{Note/Important| | {{Note/Important| | ||
It is critical to maintain the demonstrated order of the EtherCAT setup.<br/>Any change in the given example may result in undefined behavior!}} | It is critical to maintain the demonstrated order of the EtherCAT setup.<br/>Any change in the given example may result in undefined behavior!}} | ||
− | + | ==EC_SETUP.PRG== | |
− | EC_SETUP.PRG is a generic script. Its | + | EC_SETUP.PRG is a generic script. Its purpose is to configure the EtherCAT master and slaves before they are started, start the master, and eventually run additional actions to complete the EtherCAT startup procedure. |
− | run additional actions to complete the EtherCAT | ||
− | EC_SETUP.PRG is written in a manner that easily allows embedding code to configure specific motion drives. | + | EC_SETUP.PRG is written in a manner that easily allows embedding code to configure specific motion drives and IO modules. |
− | This article details the | + | This article details the main steps that occur upon EtherCAT startup as they are executed by EC_SETUP.PRG. |
− | == | + | ==Drive Address== |
− | Each EtherCAT slave has an address. | + | Each EtherCAT slave has an address. Currently this address is determined strictly according to the slave location in the |
− | [[:File:Axystems;EC_master_slave_position_topology.PNG|physical topology]] of the system | + | [[:File:Axystems;EC_master_slave_position_topology.PNG|physical topology]] of the system; that is, the first slave attached to the MC is assigned drive address 1, the second slave in the chain gets slave address 2, and so on. |
− | slave address 2, | ||
+ | An EtherCAT slave can be a motion drive, an IO module or a Gateway. | ||
− | ==PRE-OP | + | ==PRE-OP Mode == |
− | Before the master is started all the slaves are in PRE-OP mode. In this stage the master is created and the system gathers from the slaves | + | Before the master is started all the slaves are in PRE-OP mode. In this stage the master is created and the system gathers information from the slaves in order to create data structures that are used by the master to set up the EtherCAT communication. |
− | + | First, differentiate between '''motion drives''' and '''IO modules'''. For each slave query the slave's Vendor ID and Product Code. | |
− | First, differentiate between ' | + | This data can later be used to identify specific products and create specific configuration for them, as in the [[EtherCAT:EC_INSTALL_STX_CDHD|CDHD Configuration example]]. |
− | This data can later be used to identify specific products and create specific configuration for them, as in the CDHD example. | + | <syntaxhighlight lang="vb"> |
− | < | ||
numOfSlaves = EC_ETHERCAT_INIT | numOfSlaves = EC_ETHERCAT_INIT | ||
− | </ | + | </syntaxhighlight> |
− | Look for an unknown generic DS402 motion drive. If found, remap its PDO's to the required minimum | + | Look for an unknown generic DS402 motion drive. If found, remap its PDOs to the required minimum.<br/> |
− | < | + | You may update the following code by replacing the define GENERIC_DS402_DRIVE_VENDOR with your device's vendor ID, by doing so remapping its PDO's to the required minimum to create sync position motion: |
+ | <syntaxhighlight lang="vb"> | ||
for drive_addr = 1 to numOfSlaves | for drive_addr = 1 to numOfSlaves | ||
if ETSLAVES[drive_addr]->et_slavetype = ECAT_MOTIONSLAVE then | if ETSLAVES[drive_addr]->et_slavetype = ECAT_MOTIONSLAVE then | ||
− | if EC_SLAVES_INFO[drive_addr]->vendor_id = GENERIC_DS402_DRIVE_VENDOR then | + | if EC_SLAVES_INFO[drive_addr]->vendor_id = GENERIC_DS402_DRIVE_VENDOR then ' replace with your product's vendor ID |
call EC_REMAP_MINIMUM_PDOS(drive_addr) | call EC_REMAP_MINIMUM_PDOS(drive_addr) | ||
end if | end if | ||
end if | end if | ||
next | next | ||
− | </ | + | </syntaxhighlight> |
− | Create the EtherCAT Master | + | |
− | < | + | ===Check the EtherCAT Topology for Wiring Errors=== |
+ | EtherCAT topology is sensitive to the direction of the wiring. Each EtherCAT slave has an INPUT connector and an OUTPUT connector.<br/> | ||
+ | The cable that "starts" from the EtherCAT master's OUTPUT must be connected to the INPUT of the first EtherCAT slave. A second cable will "exit" from the OUTPUT of the first slave and get connected to the INPUT of the second slave, etc...<br/> | ||
+ | 'Miswiring' on most occasions means that somewhere in the topology the EtherCAT cable wiring got confused between the INPUT and the OUTPUT connectors.<br/> | ||
+ | This situation results UNDEFINED behavior, even up to making the wrong motor move, which is a safety issue. | ||
+ | {{Note/Important|If a miswiring is detected, an error will be thrown and EC_SETUP.PRG will stop running}} | ||
+ | <syntaxhighlight lang="vb"> | ||
+ | retVal = CHECK_TOPOLOGY | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Create the EtherCAT Master. | ||
+ | <syntaxhighlight lang="vb"> | ||
call EC_CREATE_MASTER | call EC_CREATE_MASTER | ||
− | </ | + | </syntaxhighlight> |
− | Set Motion Cycle Time: 4000, 2000, 1000, 500 or 250[us] | + | Set Motion Cycle Time: 4000, 2000, 1000, 500 or 250 [us] |
− | < | + | <syntaxhighlight lang="vb"> |
− | call EC_SET_BUS_CYCLETIME(4000) ' | + | call EC_SET_BUS_CYCLETIME(4000) ' for a cycle time of 500/250[us], add to FWCONFIG: hpetfreq = 2000 |
− | </ | + | </syntaxhighlight> |
From here on EC_SETUP.PRG uses the gathered information to configure the slaves. A 'For Loop' goes over the slaves and tries to match | From here on EC_SETUP.PRG uses the gathered information to configure the slaves. A 'For Loop' goes over the slaves and tries to match | ||
− | them to already known products (as the CDHD). When found, product specific functions are invoked to create in the master | + | them to already known products (such as the CDHD). When found, product specific functions are invoked to create data structures in the master that elaborate the PDO mapping of the slaves, be it a motion drive or an IO module. This is where you can add your own code to configure your own EtherCAT slave. Just add another case to match your Vendor ID.<br/> |
− | that elaborate the PDO mapping of the slaves, be it a motion drive or an IO module. | + | You may use the already prepared GENERIC_DS402_DRIVE_VENDOR case.<br/> |
− | This is where you can add your own code to configure your own EtherCAT slave. Just add another case to match your Vendor ID. | + | Replace the define GENERIC_DS402_DRIVE_VENDOR with your device's vendor ID, and GENERIC_DS402_DRIVE_PRODUCT_ID with the device's product code: |
+ | |||
+ | <syntaxhighlight lang="vb"> | ||
+ | Case GENERIC_DS402_DRIVE_VENDOR ' replace with your vendor id | ||
− | + | if EC_SLAVES_INFO[drive_addr]->product_code = GENERIC_DS402_DRIVE_PRODUCT_ID then ' replace with your product id | |
− | |||
− | |||
+ | call EC_INSTALL_GENERIC_DRIVE(drive_addr, Counts_Per_Revolution) ' Counts Per motor Revolution | ||
+ | num_Of_Motion_Drives = num_Of_Motion_Drives + 1 | ||
− | + | end if | |
− | + | </syntaxhighlight> | |
− | < | ||
− | |||
− | + | If a Servotronix (STX) CDHD servo motion drive is found, the function [[EtherCAT:EC_INSTALL_STX_CDHD|EC_INSTALL_STX_CDHD]] is invoked. This function sets certain parameters in the drive, creates the PDO map of the CDHD, and queries the drive's PNUM and PDEN to allow calculation of the [[MC-Basic:axis.POSITIONFACTOR|Position Factor]]. | |
− | |||
− | + | For a generic drive, a minimum PDO mapping and default values are used. | |
− | + | The user can add his own code to [[EtherCAT:EC_USER_PREOP_CONFIG|EC_USER_PREOP_CONFIG]] to perform any specific configuration that must take place while the slaves are in PREOP mode. | |
− | |||
− | |||
− | + | After the slave configuration is done the master is started: | |
− | + | <syntaxhighlight lang="vb"> | |
+ | ' Create PDOs mapping, set bus cycle time, sync clocks between the master and the slaves, | ||
+ | ' raise slaves to OP-Mode and sets master's opmode to operational | ||
+ | call EC_STARTMASTER ' Syncs clocks between the master and the slaves, and sets master's opmode to operational | ||
+ | </syntaxhighlight> | ||
− | + | The master attempts to raise all the slaves to OP Mode. If it fails, the procedure is stopped and an error is issued. | |
+ | If it is successful, EtherCAT communication is now online and EC_SETUP.PRG starts the second stage of configuration. | ||
− | Again, a | + | ==OP Mode == |
+ | |||
+ | Again, a For Loop goes over all the slaves. When a motion drive is encountered, EC_SETUP.PRG attaches its drive address to an axis and | ||
attempts to clear its faults. | attempts to clear its faults. | ||
− | < | + | Again, the user can add his own code to [[EtherCAT:EC_USER_SAFEOP_CONFIG|EC_USER_SAFEOP_CONFIG]] and [[EtherCAT:EC_USER_OP_CONFIG|EC_USER_OP_CONFIG]] to perform any specific configuration that must take place while the slaves are in "SAFEOP" or "OP" mode.<br/> |
− | ' Assign slave address to | + | |
− | + | <syntaxhighlight lang="vb"> | |
+ | ' SAFEOP state configuration - Add code to EC_USER_SAFEOP_CONFIG(byval drive_addr as long) | ||
+ | retVal = EC_USER_SAFEOP_CONFIG(drive_addr) | ||
+ | |||
+ | ' OP state configuration - Add code to EC_USER_OP_CONFIG(byval drive_addr as long) | ||
+ | retVal = EC_USER_OP_CONFIG(drive_addr) | ||
+ | |||
+ | ' Assign ECAT bus ID and slave address to an axis | ||
+ | systemAxis(Axis_Attached_To_Drive).busnumber = ECAT_BUSID | ||
+ | systemAxis(Axis_Attached_To_Drive).dadd = drive_addr | ||
' Attempt to clear faults in the drives | ' Attempt to clear faults in the drives | ||
Line 110: | Line 137: | ||
End Try | End Try | ||
− | </ | + | </syntaxhighlight> |
− | All the motion drives are set to | + | |
− | < | + | |
+ | All the motion drives are set to Synchronous Position Mode: | ||
+ | <syntaxhighlight lang="vb"> | ||
' Set drives to sync position mode | ' Set drives to sync position mode | ||
if EC_IS_PDO(Axes[Axis_Attached_To_Drive].dadd, 0x6060, 0) then | if EC_IS_PDO(Axes[Axis_Attached_To_Drive].dadd, 0x6060, 0) then | ||
Line 119: | Line 148: | ||
call EC_SDO_WRITE(Axes[Axis_Attached_To_Drive].dadd, Modes_Of_Operation_6060h, 0, 8, 8) | call EC_SDO_WRITE(Axes[Axis_Attached_To_Drive].dadd, Modes_Of_Operation_6060h, 0, 8, 8) | ||
end if | end if | ||
− | </ | + | </syntaxhighlight> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | ==See Also== | ||
+ | * [[EtherCAT:EC ETHERCAT INIT|EC_ETHERCAT_INIT]] | ||
+ | * [[EtherCAT:EC REMAP MINIMUM PDOS|EC_REMAP_MINIMUM_PDOS]] | ||
+ | * [[EtherCAT:EC CREATE MASTER|EC_CREATE_MASTER]] | ||
+ | * [[EtherCAT:EC SET BUS CYCLETIME|EC_SET_BUS_CYCLETIME]] | ||
+ | * [[EtherCAT:EC GET BUS CYCLETIME|EC_GET_BUS_CYCLETIME]] | ||
+ | * [[EtherCAT:EC STARTMASTER|EC_STARTMASTER]] | ||
+ | * [[EtherCAT:EC CLEAR FAULTS|EC_CLEAR_FAULTS]] | ||
+ | * [[EtherCAT:EC SDO READ|EC_SDO_READ]] | ||
+ | * [[EtherCAT:EC SDO WRITE|EC_SDO_WRITE]] | ||
+ | * [[EtherCAT:EC PDO READ|EC_PDO_READ]] | ||
+ | * [[EtherCAT:EC PDO WRITE|EC_PDO_WRITE]] | ||
+ | * [[EtherCAT:EC IS PDO|EC_IS_PDO]] | ||
+ | * [[EtherCAT:EC_USER_PREOP_CONFIG|EC_USER_PREOP_CONFIG]] | ||
+ | * [[EtherCAT:EC_USER_SAFEOP_CONFIG|EC_USER_SAFEOP_CONFIG]] | ||
+ | * [[EtherCAT:EC_USER_OP_CONFIG|EC_USER_OP_CONFIG]] | ||
}} | }} | ||
− | + | <br/> | |
[[Category:EtherCAT]] | [[Category:EtherCAT]] | ||
[[Category:Control:Offline]] | [[Category:Control:Offline]] |
Latest revision as of 16:18, 3 May 2017
Language: | English |
---|
Category:EtherCAT:EC SETUP How to Set up EtherCAT.
The front page is EtherCAT
Contents
Introduction
Before starting to work with the softMC, you must setup the EtherCAT master to work with the slaves.
You must configure the axes in the system in a certain manner, then invoke certain functions and subroutines in an orderly manner, and make sure no errors occur.
A CONFIG.PRG and a program file EC_SETUP.PRG exist in the repository, and demonstrate the following process.
CONFIG.PRG allocates an array of generic axes by the name Axes[], and sets all the existing axes in the system into this array.
NOTE | |
Since verison 0.4.15.3rc6 the global axis array systemAxis[] is introduced, and the array Axes[] is made redundant, therefore it is removed from CONFIG.PRG |
EC_SETUP.PRG and AX_SETUP.PRG use this array to setup the system automatically.
IMPORTANT | |
It is critical to maintain the demonstrated order of the EtherCAT setup. Any change in the given example may result in undefined behavior! |
EC_SETUP.PRG
EC_SETUP.PRG is a generic script. Its purpose is to configure the EtherCAT master and slaves before they are started, start the master, and eventually run additional actions to complete the EtherCAT startup procedure.
EC_SETUP.PRG is written in a manner that easily allows embedding code to configure specific motion drives and IO modules.
This article details the main steps that occur upon EtherCAT startup as they are executed by EC_SETUP.PRG.
Drive Address
Each EtherCAT slave has an address. Currently this address is determined strictly according to the slave location in the physical topology of the system; that is, the first slave attached to the MC is assigned drive address 1, the second slave in the chain gets slave address 2, and so on.
An EtherCAT slave can be a motion drive, an IO module or a Gateway.
PRE-OP Mode
Before the master is started all the slaves are in PRE-OP mode. In this stage the master is created and the system gathers information from the slaves in order to create data structures that are used by the master to set up the EtherCAT communication.
First, differentiate between motion drives and IO modules. For each slave query the slave's Vendor ID and Product Code. This data can later be used to identify specific products and create specific configuration for them, as in the CDHD Configuration example.
numOfSlaves = EC_ETHERCAT_INIT
Look for an unknown generic DS402 motion drive. If found, remap its PDOs to the required minimum.
You may update the following code by replacing the define GENERIC_DS402_DRIVE_VENDOR with your device's vendor ID, by doing so remapping its PDO's to the required minimum to create sync position motion:
for drive_addr = 1 to numOfSlaves
if ETSLAVES[drive_addr]->et_slavetype = ECAT_MOTIONSLAVE then
if EC_SLAVES_INFO[drive_addr]->vendor_id = GENERIC_DS402_DRIVE_VENDOR then ' replace with your product's vendor ID
call EC_REMAP_MINIMUM_PDOS(drive_addr)
end if
end if
next
Check the EtherCAT Topology for Wiring Errors
EtherCAT topology is sensitive to the direction of the wiring. Each EtherCAT slave has an INPUT connector and an OUTPUT connector.
The cable that "starts" from the EtherCAT master's OUTPUT must be connected to the INPUT of the first EtherCAT slave. A second cable will "exit" from the OUTPUT of the first slave and get connected to the INPUT of the second slave, etc...
'Miswiring' on most occasions means that somewhere in the topology the EtherCAT cable wiring got confused between the INPUT and the OUTPUT connectors.
This situation results UNDEFINED behavior, even up to making the wrong motor move, which is a safety issue.
IMPORTANT | |
If a miswiring is detected, an error will be thrown and EC_SETUP.PRG will stop running |
retVal = CHECK_TOPOLOGY
Create the EtherCAT Master.
call EC_CREATE_MASTER
Set Motion Cycle Time: 4000, 2000, 1000, 500 or 250 [us]
call EC_SET_BUS_CYCLETIME(4000) ' for a cycle time of 500/250[us], add to FWCONFIG: hpetfreq = 2000
From here on EC_SETUP.PRG uses the gathered information to configure the slaves. A 'For Loop' goes over the slaves and tries to match
them to already known products (such as the CDHD). When found, product specific functions are invoked to create data structures in the master that elaborate the PDO mapping of the slaves, be it a motion drive or an IO module. This is where you can add your own code to configure your own EtherCAT slave. Just add another case to match your Vendor ID.
You may use the already prepared GENERIC_DS402_DRIVE_VENDOR case.
Replace the define GENERIC_DS402_DRIVE_VENDOR with your device's vendor ID, and GENERIC_DS402_DRIVE_PRODUCT_ID with the device's product code:
Case GENERIC_DS402_DRIVE_VENDOR ' replace with your vendor id
if EC_SLAVES_INFO[drive_addr]->product_code = GENERIC_DS402_DRIVE_PRODUCT_ID then ' replace with your product id
call EC_INSTALL_GENERIC_DRIVE(drive_addr, Counts_Per_Revolution) ' Counts Per motor Revolution
num_Of_Motion_Drives = num_Of_Motion_Drives + 1
end if
If a Servotronix (STX) CDHD servo motion drive is found, the function EC_INSTALL_STX_CDHD is invoked. This function sets certain parameters in the drive, creates the PDO map of the CDHD, and queries the drive's PNUM and PDEN to allow calculation of the Position Factor.
For a generic drive, a minimum PDO mapping and default values are used.
The user can add his own code to EC_USER_PREOP_CONFIG to perform any specific configuration that must take place while the slaves are in PREOP mode.
After the slave configuration is done the master is started:
' Create PDOs mapping, set bus cycle time, sync clocks between the master and the slaves,
' raise slaves to OP-Mode and sets master's opmode to operational
call EC_STARTMASTER ' Syncs clocks between the master and the slaves, and sets master's opmode to operational
The master attempts to raise all the slaves to OP Mode. If it fails, the procedure is stopped and an error is issued. If it is successful, EtherCAT communication is now online and EC_SETUP.PRG starts the second stage of configuration.
OP Mode
Again, a For Loop goes over all the slaves. When a motion drive is encountered, EC_SETUP.PRG attaches its drive address to an axis and
attempts to clear its faults.
Again, the user can add his own code to EC_USER_SAFEOP_CONFIG and EC_USER_OP_CONFIG to perform any specific configuration that must take place while the slaves are in "SAFEOP" or "OP" mode.
' SAFEOP state configuration - Add code to EC_USER_SAFEOP_CONFIG(byval drive_addr as long)
retVal = EC_USER_SAFEOP_CONFIG(drive_addr)
' OP state configuration - Add code to EC_USER_OP_CONFIG(byval drive_addr as long)
retVal = EC_USER_OP_CONFIG(drive_addr)
' Assign ECAT bus ID and slave address to an axis
systemAxis(Axis_Attached_To_Drive).busnumber = ECAT_BUSID
systemAxis(Axis_Attached_To_Drive).dadd = drive_addr
' Attempt to clear faults in the drives
Try
call EC_CLEAR_FAULTS(drive_addr)
Catch Else
' if clear faults failed due to PLL Sync Error, wait a little longer and retry
if EC_SDO_READ(drive_addr, 0x603f, 0) = 0x7386 then
printu "PLL Error in drive #. Sleeping 5 seconds and retrying to clear fault";drive_addr
sleep 5000
call EC_CLEAR_FAULTS(drive_addr)
end if
End Try
All the motion drives are set to Synchronous Position Mode:
' Set drives to sync position mode
if EC_IS_PDO(Axes[Axis_Attached_To_Drive].dadd, 0x6060, 0) then
call EC_PDO_WRITE(Axes[Axis_Attached_To_Drive].dadd, Modes_Of_Operation_6060h, 0, 8)
else
call EC_SDO_WRITE(Axes[Axis_Attached_To_Drive].dadd, Modes_Of_Operation_6060h, 0, 8, 8)
end if
See Also
- EC_ETHERCAT_INIT
- EC_REMAP_MINIMUM_PDOS
- EC_CREATE_MASTER
- EC_SET_BUS_CYCLETIME
- EC_GET_BUS_CYCLETIME
- EC_STARTMASTER
- EC_CLEAR_FAULTS
- EC_SDO_READ
- EC_SDO_WRITE
- EC_PDO_READ
- EC_PDO_WRITE
- EC_IS_PDO
- EC_USER_PREOP_CONFIG
- EC_USER_SAFEOP_CONFIG
- EC_USER_OP_CONFIG
This category currently contains no pages or media.