84 lines
1.8 KiB
Python
84 lines
1.8 KiB
Python
import plotutils
|
|
from mathutils import fit_gaussian, Gaussian
|
|
|
|
cal_tool = TOOL_CALIBRATION
|
|
|
|
robot.set_tool(cal_tool)
|
|
|
|
robot.enable()
|
|
move_to_laser()
|
|
|
|
|
|
robot.set_motors_enabled(True)
|
|
robot.set_joint_motors_enabled(True)
|
|
initial_pos = robot.get_cartesian_pos()
|
|
|
|
#robot.align()
|
|
try:
|
|
robot.set_frame(FRAME_TABLE)
|
|
run("calibration/ScanX")
|
|
finally:
|
|
robot.set_default_frame()
|
|
|
|
pos1 = robot.get_cartesian_pos()
|
|
x1, l1 = closest_x, closest_y
|
|
|
|
print "Scan 1 result: ", [x1, l1]
|
|
print "Position 1: ", pos1
|
|
|
|
|
|
pj6 = robot_j6.position
|
|
if pj6>0:
|
|
robot_j6.move(pj6 - 180.0)
|
|
else:
|
|
robot_j6.move(pj6 + 180.0)
|
|
|
|
|
|
try:
|
|
robot.set_frame(FRAME_TABLE)
|
|
run("calibration/ScanX")
|
|
finally:
|
|
robot.set_default_frame()
|
|
|
|
pos2 =robot.get_cartesian_pos()
|
|
x2, l2 = closest_x, closest_y
|
|
|
|
print "Scan 2 result: ", [x2, l2]
|
|
print "Position 2: ", pos1
|
|
|
|
off_l = l2 - l1
|
|
print "Offset l: ", off_l
|
|
|
|
#For composing cannot use tcp_p, need another auxiliary point. tcp_t is also destroyed.
|
|
robot.set_pnt(robot.get_cartesian_pos(), "pTemp")
|
|
robot.set_trsf([0, -off_l, 0, 0, 0, 0])
|
|
c=robot.compose("pTemp", FRAME_TABLE, "tcp_t" )
|
|
robot.set_pnt(c, "pTemp")
|
|
robot.movel("pTemp", cal_tool, DESC_SCAN, sync=True)
|
|
|
|
|
|
pos3 = robot.get_cartesian_pos()
|
|
print "Position 3: ", pos3
|
|
|
|
|
|
#Updates the tool
|
|
t=robot.get_tool_trsf(TOOL_DEFAULT)
|
|
print "Former tool: " + str(t)
|
|
|
|
xoff = (pos3[0]-pos1[0])/2
|
|
yoff = (pos3[1]-pos1[1])/2
|
|
xrot = math.degrees(math.atan(yoff/t[2]))
|
|
yrot = math.degrees(math.atan(xoff/t[2]))
|
|
t[0]=xoff
|
|
t[1]=-yoff
|
|
print "Calibrated tool: " + str(t)
|
|
robot.set_tool_trsf(t, TOOL_DEFAULT)
|
|
|
|
robot.set_tool(TOOL_DEFAULT)
|
|
d = robot.get_distance_to_pnt("pLaser")
|
|
if d<POSITION_TOLERANCE:
|
|
print "Moving calibrated tool to laser"
|
|
#move_to_laser()
|
|
else:
|
|
print "Cannot move calibrated tool to laser: too big offset"
|