EtherCAT Drive Config Script
This script should be placed first within a program.
# EtherCAT Single Axis Config Script
# This script provides the MotionPlus configuration for the EtherCAT drive, servo motor, gearing and encoder.
# NOTE: You must first create the following global variable in the installation tab under "General"
# CAL_AX1_ROTARY p[0,0,0,0,0,0]
# This will be used to store the calibrated poses calculated here
PI = acos(-1)
AXIS_TYPE1 = 0 # 0:rotary, 1:linear
VELOCITY_LIMIT1 = 0.7*2 # rad/s
ACCELERATION_LIMIT1 = 0.1*100 # rad/s^2
ENCODER_RESOLUTION1 = <ENCODER>
FEED_CONSTANT1 = 2 * PI # make sure +Z points out of motor
GEAR_RATIO1 = <GEAR>
ZERO_OFFSET1 = 0
def run_axis_config():
# stop EtherCAT master first, otherwise, reset_world_model may throw an error
ethercat_clear_error()
ethercat_stop(True)
reset_world_model()
# after calibration, change this to use CAL_AX1_ROTARY
axis1_position = p[0,0,0,0,0,0]
#axis1_position = CAL_AX1_ROTARY
axis_group_add("positioner", p[0,0,0,0,0,0], "base")
axis_group_add_axis("positioner", "axis1", "", axis1_position, AXIS_TYPE1, VELOCITY_LIMIT1, ACCELERATION_LIMIT1)
ethercat_config_axis("axis1", 1, ENCODER_RESOLUTION1, GEAR_RATIO1, FEED_CONSTANT1, ZERO_OFFSET1)
ethercat_set_parameter("dc_enable", True)
ethercat_start(10)
if (ethercat_is_axis_in_fault_state("axis1")):
textmsg("FAULT in: ", "axis1")
if(ethercat_reset_axis_fault("axis1")):
textmsg("Axis 1 FAULT cleared")
else:
return False
end
end
ethercat_enable_axis("axis1")
return True
end
run_config() #run the axis configuration
Basic Move Rotary Script
# Basic Move - Slow turn of the servo
if not run_axis_config():
popup("configuration failed to run", title="Basic Move", warning=False, error=True, blocking=True)
halt
end
popup("Ready for Basic Move?", title="Servo Test1", blocking=True)
popup("Moving axis to ZERO", title="Servo Test1", blocking=True)
axis_group_movej("positioner", [0], 0.1, 0.1)
popup("Moving axis to +90, -90, ZERO", title="Servo Test1", blocking=True)
axis_group_movej("positioner", [d2r(90)], 0.4, 0.4)
sleep(0.5)
axis_group_movej("positioner", [d2r(-90)], 0.4, 0.4)
sleep(0.5)
axis_group_movej("positioner", [d2r(0)], 0.4, 0.4)
sleep(0.5)