Configuring, Enabling, and Driving EtherCAT Axes

Brief: An axis group with a single axis is created and mapped to an EtherCAT slave. The robot then enables the EtherCAT slave, rotates it by 1 radian and brings it back to home position before shutting down EtherCAT network.

URScript API functions used in this example:

  • axis_group_add

  • axis_group_add_axis

  • axis_group_movej

  • reset_world_model

  • ethercat_config_axis

  • ethercat_start

  • ethercat_stop

  • ethercat_reset_axis_fault

  • ethercat_enable_axis

  • ethercat_disable_axis

Warning

This example drives EtherCAT hardware. It requires the EtherCAT URCap to be configured and slaves to be connected to the controller. See EtherCAT URCap Manual** **for information on installing and configuring the EtherCAT URCap.

Driving EtherCAT axes using EtherCAT URCap

# Constants used in config. Replace <XXX> tokens with correct values for your servo
PI = acos(-1) 
AXIS_TYPE = 0                # 0:rotary, 1:linear
VELOCITY_LIMIT = 2           # rad/s 
ACCELERATION_LIMIT = 10      # rad/s^2 
ENCODER_RESOLUTION = <ENCODER>>
FEED_CONSTANT = 2 * PI       # sign can be changed to change motor positive direction
GEAR_RATIO = <GEAR> 
ZERO_OFFSET = 0

# EtherCAT: Stop Master and Reset Config 
ethercat_stop(True) 

# Reset World Model 
reset_world_model() 

# Add an axis group 'groupA' to the world model at world origin 
axis_group_add("groupA", p[0, 0, 0, 0, 0, 0], "world") 

# Add an axis 'axis1' at origin to the 'groupA' axis group at the group's origin 
axis_group_add_axis("groupA", "axis1", "", p[0, 0, 0, 0, 0, 0], AXIS_TYPE, 0.5, 5) 

# EtherCAT: Map Axis 'axis1' to an EtherCAT slave and configure slave parameters. 
ethercat_config_axis("axis1", 1, ENCODER_RESOLUTION, GEAR_RATIO, FEED_CONSTANT, 0) 

# EtherCAT: Start Master 
if not ethercat_start():
  halt
end

# Reset fault in case 'axis1' slave has a fault 
ethercat_reset_axis_fault("axis1", 2) 

# Enable 'axis1' slave
ethercat_enable_axis("axis1", 3, 1) 

# Move external axis using 'axis_group_movej' 
axis_group_movej("groupA", [0], 1, 1) 
axis_group_movej("groupA", [-1], 1, 1) 

# Disable 'axis1' slave. This is recommended before stopping master as some slaves may go into fault 
# on stopping master if not disabled before stopping master. 
ethercat_disable_axis("axis1", 3) 

# EtherCAT: Stop Master 
ethercat_stop()

This is an example of basic EtherCAT master configuration and control. Let’s go through the example in greater detail:

# EtherCAT: Stop Master and Reset Config 
ethercat_stop(True) 

This line stops the EtherCAT Master (if already running). The parameter reset is set to True to also reset/clear the axis configuration since a fresh configuration is done later in the program.

# Reset World Model 
reset_world_model() 

# Add an axis group 'groupA' to the world model at world origin 
axis_group_add("groupA", p[0, 0, 0, 0, 0, 0], "world") 

# Add an axis 'axis1' at origin to the 'groupA' axis group at the group's origin 
axis_group_add_axis("groupA", "axis1", "", p[0, 0, 0, 0, 0, 0], AXIS_TYPE, 0.5, 5) 

These lines clear the world model and adds an axis group named “groupA” with an axis named “axis1” to the world model.

# EtherCAT: Map Axis 'axis1' to an EtherCAT slave and configure slave parameters. 
ethercat_config_axis("axis1", 1, ENCODER_RESOLUTION, GEAR_RATIO, FEED_CONSTANT, 0) 

This line maps the added axis “axis1” to slave with station address 1 on the EtherCAT network. It also configures other parameters (counts per revolution, gear ratio, feed constant and zero offset count) for the axis gearbox.

# EtherCAT: Start Master 
if not ethercat_start():
  halt
end

These lines start the EtherCAT Master and halt the program in case EtherCAT Master isn’t able to transition to Operational state.

# Reset fault in case 'axis1' slave has a fault 
ethercat_reset_axis_fault("axis1", 2) 

The state information of the axis is available after EtherCAT Master is running. This line sends a reset fault command to the axis in case it is currently in a Fault state. This command triggers a transition from the Fault state to the Switch on disabled state for the axis.

# Enable 'axis1' slave
ethercat_enable_axis("axis1", 3, 1) 

This statement enables the axis, brings the axis from Switch on disabled state to Operation Enabled state. The enabling process goes through multiple states, so, a timeout parameter (second parameter with value 3) is provided to specify the maximum waiting time for the axis to transition to the Operation Enabled state. Since the drive starts its motion control loop in Operation Enabled state, it’s possible for the drive to transition to Fault state right after transitioning to Operation Enabled state in case of an error. The enable function also verifies the state once more after a stabilization period specified by the last parameter (with value 1 second).

# Move external axis using 'axis_group_movej' 
axis_group_movej("groupA", [0], 1, 1) 
axis_group_movej("groupA", [-1], 1, 1) 

These lines move the axis first to the target position of 0 radians and then to 1 radian.

# Disable 'axis1' slave. This is recommended before stopping master as some slaves may go into fault 
# on stopping master if not disabled before stopping master. 
ethercat_disable_axis("axis1", 3)

# EtherCAT: Stop Master 
ethercat_stop()

Finally, the axis is disabled and the ethercat master stops.