Single Linear Axis Calibration
Configuration
Use this script to configur your axis and ethercat settings.
Please note the the variables in uppercase are values that you should modify to match your axis setup.
#revised 16 Jan 4:25pm ET
# EtherCAT Single Linear Axis Config Script
# NOTE: You must first create the following global variable in the installation tab under "General"
# CAL_AX_LINEAR p[0,0,0,0,0,0]
# This will be used to store the calibrated poses calculated here
PI = acos(-1)
AXIS_TYPE = 1 # 0:rotary, 1:linear
# These values should be according to your linear axis setup, servo drive and motor
VELOCITY_LIMIT = 0.200 # m/s
ACCELERATION_LIMIT = 1.0 # m/s^2
ENCODER_RESOLUTION = 1000000
FEED_CONSTANT = -1 # Pulley diameter * PI
GEAR_RATIO = 1 # Output gear
ZERO_OFFSET = 0 # Offset from homed zero position
RAIL_MIN = 0.0
RAIL_MAX = 1.0
def run_axis_config(is_mounted=True):
# stop EtherCAT master first, otherwise, reset_world_model may throw an error
ethercat_clear_error()
ethercat_stop(True)
reset_world_model()
axis_position = CAL_AX_LINEAR #saved in global installation variable
axis_group_add("rail", p[0,0,0,0,0,0], "world")
axis_group_add_axis("rail", "axis1", "", p[0,0,0,0,0,0], AXIS_TYPE, VELOCITY_LIMIT, ACCELERATION_LIMIT, [RAIL_MIN, RAIL_MAX])
ethercat_config_axis("axis1", 1, ENCODER_RESOLUTION, GEAR_RATIO, FEED_CONSTANT, ZERO_OFFSET)
ethercat_start(10)
sleep(1) #wait for the ethercat to start
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
# If the robot is mounted to the linear axis, move the base of the robot to the slide,
# then update the axis position and attach the robot base to the axis
if (is_mounted):
move_frame("base", CAL_AX_LINEAR, "world")
axis_group_update_axis(name="axis1", pose=p[CAL_AX_LINEAR[0], CAL_AX_LINEAR[1], CAL_AX_LINEAR[2],0,0,0])
attach_frame("base", "axis1")
end
ethercat_enable_axis("axis1")
return True
end
Interactive Calibration with the Teach Pendant
This script will step you through sampling the points around the axis to compute the position and orientation of the axis center.
# Single Rotary Axis Calibration
def move_axis(group_name, axis1_position):
msg1 = group_name
msg1 = str_cat(msg1, " will now move to [")
msg1 = str_cat(msg1, to_str(axis1_position))
msg1 = str_cat(msg1, "] meters")
popup(msg1, "Axis is about to move!", warning=True, error=False, blocking=True)
axis_group_movej(group_name, [axis1_position], 1, 1)
end
popup_title = "Linear Axis Calibration"
# pass in point name as a parameter to the message
def teachCalPointAxis(position1, ref_frame, sample_point_name):
move_axis("rail", position1)
sleep(0.5)
freedrive_mode()
msg = str_cat("Freedrive to the ", sample_point_name)
msg = str_cat(msg, " point, then press Continue")
popup(msg, title=popup_title, blocking=True)
p = get_pose("tcp", ref_frame)
msg = str_cat("Freedrive up and away from the ", sample_point_name)
msg = str_cat(msg, " point, then presss Continue")
popup(msg, "Axis Calibration", blocking=True)
end_freedrive_mode()
return p
end
#-----------------------------------------------------------
# Provide a function to configure your base ethercat setup
#-----------------------------------------------------------
MOUNTED = True
if not run_axis_config(MOUNTED):
popup("configuration failed to run", title=popup_title, warning=False, error=True, blocking=True)
halt
end
# Teach the pose of axis1 relative to the robot base.
# The robot base should not move
popup("Ready to Calibrate Axis1?", title=popup_title, warning=False, error=False, blocking=True)
# Home to block with very slow speed. Which direction?
popup("Step 1: Home the Linear axis. Ready?", title=popup_title, warning=False, error=False, blocking=True)
# homing
# you should choose appropriate homing method and velocities for your system
homing_method = -2 # home to block
homing_offset = 0 # [encoder counts]
homing_velocities = [100, 100] # [encoder counts / sec]
homing_acceleration = [50, 50] # [encoder counts / sec^2]
ethercat_home_axis("axis1", homing_method, homing_offset, homing_velocities, homing_acceleration)
AXIS_LENGTH = 1.0 #length in meters
pz1 = teachCalPointAxis( AXIS_LENGTH*0.2, "base", "origin")
origin_offset = get_pose("axis1")[2]
# Teach the X axis direction (single point)
popup("Teach X direction point", title=popup_title, warning=False, error=False, blocking=True)
px1 = teachCalPointAxis(AXIS_LENGTH*0.2, "base", "X direction")
# Teach two more points along the linear axis
pz2 = teachCalPointAxis( AXIS_LENGTH*0.4, "base", "origin")
pz3 = teachCalPointAxis( AXIS_LENGTH*0.6, "base", "origin")
CAL_AX_LINEAR = calibrate_linear_axis(pz1, [pz2, pz3], px1, MOUNTED)[0]
# Subtract any potential origin offset:
CAL_AX_LINEAR[2] = CAL_AX_LINEAR[2] - origin_offset
popup("Completed. Calibration has been saved.", title=popup_title, warning=False, error=False, blocking=True)