Difference between revisions of "Category:EtherCAT:EC SETUP"

From SoftMC-Wiki
Jump to: navigation, search
Line 156: Line 156:
 
* [[EtherCAT:EC CREATE MASTER|EC_CREATE_MASTER]]
 
* [[EtherCAT:EC CREATE MASTER|EC_CREATE_MASTER]]
 
* [[EtherCAT:EC SET BUS CYCLETIME|EC_SET_BUS_CYCLETIME]]
 
* [[EtherCAT:EC SET BUS CYCLETIME|EC_SET_BUS_CYCLETIME]]
* [[EtherCAT:EC GET BUS CYCLETIME|EC_SET_BUS_CYCLETIME]]
+
* [[EtherCAT:EC GET BUS CYCLETIME|EC_GET_BUS_CYCLETIME]]
 
* [[EtherCAT:EC STARTMASTER|EC_STARTMASTER]]
 
* [[EtherCAT:EC STARTMASTER|EC_STARTMASTER]]
 
* [[EtherCAT:EC CLEAR FAULTS|EC_CLEAR_FAULTS]]
 
* [[EtherCAT:EC CLEAR FAULTS|EC_CLEAR_FAULTS]]

Revision as of 12:20, 28 February 2016

Category:EtherCAT:EC SETUP How to Set up EtherCAT.

The front page is EtherCAT

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-Info.svgNOTE
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.svgIMPORTANT
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.svgIMPORTANT
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


This category currently contains no pages or media.