02-19-2023, 06:05点
我一直试图找出a way to set a minimum distance from my tool to a part as it moves through a program. As the parts that are used are complex and varying diffrent sizes of objects are used I want to automate this process.
I assumed that RoboDK would have some sort of constraint built in for this but it seems not, so I have decided to try creating a py script. my code it below
I seem to be having problems with the third last line of my code that startsdirectionas I get an error as such:
direction = (tool_pose_global.Pos() - object_pose.Pos()) / distance
TypeError: unsupported operand type(s) for -: 'list' and 'list'
my simulation is trying to scan an object on a turntable with a camera from a set distance from the surface of the complex object as it moves from a front facing orientation with respect to the object to an almost top downviewwith respect to the object as seen in the attached picture.
I am not very good with programming ingeneraland this is my first attempt in RoboDK. I am not sure if my code will even work if this error is fixed so I was wondering if anyone could help, or if there might be an easier way to do this.
I assumed that RoboDK would have some sort of constraint built in for this but it seems not, so I have decided to try creating a py script. my code it below
Code:
from robolink import *
from robodk import *
# Connect to RoboDK
RDK = Robolink()
# Get the robot and tool and object
robot = RDK.Item('KUKA KR 6 R900-2')
tool = RDK.Item('Kinect')
object = RDK.Item('Piston deform')
# Set the minimum distance constraint
min_distance = 5000 # Set the desired minimum distance in millimeters
while True:
# Get the pose of the robot, tool, and object
robot_pose = robot.Pose()
tool_pose = tool.PoseTool()
object_pose = object.Pose()
# Calculate the position of the tool in the global reference frame
tool_pose_global = robot_pose*tool_pose
#计算元素的距离een the tool and object
dist = distance(tool_pose_global.Pos(), object_pose.Pos())
# If the distance is less than the minimum distance, move the robot away from the object
if dist < min_distance:
displacement = min_distance - dist
direction = (tool_pose_global.Pos() - object_pose.Pos()) / distance
new_pos = robot_pose * transl(displacement * direction)
robot.MoveJ(new_pos)
I seem to be having problems with the third last line of my code that startsdirectionas I get an error as such:
direction = (tool_pose_global.Pos() - object_pose.Pos()) / distance
TypeError: unsupported operand type(s) for -: 'list' and 'list'
my simulation is trying to scan an object on a turntable with a camera from a set distance from the surface of the complex object as it moves from a front facing orientation with respect to the object to an almost top downviewwith respect to the object as seen in the attached picture.
I am not very good with programming ingeneraland this is my first attempt in RoboDK. I am not sure if my code will even work if this error is fixed so I was wondering if anyone could help, or if there might be an easier way to do this.