forked from ZhengLiu-cart/IK_qp
add collision detection
This commit is contained in:
+3
-3
@@ -43,11 +43,11 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
# ----------- rm75 qp based kine ------------
|
# ----------- rm75 qp based kine ------------
|
||||||
robot_kine_qp = kine_qp(urdf_path='./urdf_rm75/RM75-SCI.urdf', mesh_dir='./urdf_rm75')
|
robot_kine_qp = kine_qp(urdf_path='./urdf_rm75/RM75-SCI.urdf', mesh_dir='./urdf_rm75', tcps=["scissor_tcp", "camera_tcp"])
|
||||||
robot_kine_qp.add_tool_frames(tools_in_ee)
|
robot_kine_qp.add_tool_frames(tools_in_ee)
|
||||||
robot_kine_qp.cfg_j_limit(min_j=lb, max_j=ub, rad_flag=True)
|
robot_kine_qp.cfg_j_limit(min_j=lb, max_j=ub, rad_flag=True)
|
||||||
|
|
||||||
fp = robot_kine_qp.forward_kinematics(np.zeros(7))
|
fp = robot_kine_qp.forward_kinematics(np.zeros(7),tool='scissor_tcp')
|
||||||
print(f'forward kine res = {fp}')
|
print(f'forward kine res = {fp}')
|
||||||
|
|
||||||
# ---------- rm75 official algorithm -----------
|
# ---------- rm75 official algorithm -----------
|
||||||
@@ -103,7 +103,7 @@ def main():
|
|||||||
fk_qp_p2 = robot_kine_qp.forward_kinematics(q, tool=tool_name)
|
fk_qp_p2 = robot_kine_qp.forward_kinematics(q, tool=tool_name)
|
||||||
d_p_ik = cal_pose_deviation(pose1=t_p, pose2=fk_qp_p2)
|
d_p_ik = cal_pose_deviation(pose1=t_p, pose2=fk_qp_p2)
|
||||||
print(f'---- success, in the qp ik, fk_qp_p2 = {fk_qp_p2}, d_p_ik = {d_p_ik}')
|
print(f'---- success, in the qp ik, fk_qp_p2 = {fk_qp_p2}, d_p_ik = {d_p_ik}')
|
||||||
# robot_kine_qp.collision_detect(q,stop_at_first_collision=True, verbose=True)
|
robot_kine_qp.collision_detect(q,stop_at_first_collision=True, verbose=True)
|
||||||
if d_p_ik < 0.01:
|
if d_p_ik < 0.01:
|
||||||
result[0][1] += 1
|
result[0][1] += 1
|
||||||
|
|
||||||
|
|||||||
+36
-24
@@ -13,7 +13,7 @@ import threading
|
|||||||
|
|
||||||
|
|
||||||
class KinematicsSolver():
|
class KinematicsSolver():
|
||||||
def __init__(self,urdf_path="urdf_rm75/RM75-B.urdf", mesh_dir="urdf_rm75"):
|
def __init__(self, urdf_path="urdf_rm75/RM75-B.urdf", mesh_dir="urdf_rm75", tcps=None):
|
||||||
"""
|
"""
|
||||||
for realman 75b
|
for realman 75b
|
||||||
Initialize robotic arm kinematics using Pinocchio (ROS2 version).
|
Initialize robotic arm kinematics using Pinocchio (ROS2 version).
|
||||||
@@ -30,10 +30,7 @@ class KinematicsSolver():
|
|||||||
|
|
||||||
self.cfg_j_limit()
|
self.cfg_j_limit()
|
||||||
|
|
||||||
q_range = (
|
q_range = ( self.model.upperPositionLimit[:7] - self.model.lowerPositionLimit[:7] )
|
||||||
self.model.upperPositionLimit[:7] -
|
|
||||||
self.model.lowerPositionLimit[:7]
|
|
||||||
)
|
|
||||||
|
|
||||||
self.w_q_limit = np.diag(1.0 / (q_range ** 2))
|
self.w_q_limit = np.diag(1.0 / (q_range ** 2))
|
||||||
|
|
||||||
@@ -71,8 +68,19 @@ class KinematicsSolver():
|
|||||||
0.3, 0.3, 0.2
|
0.3, 0.3, 0.2
|
||||||
])
|
])
|
||||||
|
|
||||||
self.scissor_frame_id = self.model.getFrameId("scissor_tcp")
|
|
||||||
self.camera_frame_id = self.model.getFrameId("camera_tcp")
|
if tcps is None:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.tcps = tcps
|
||||||
|
self.tcp_ids = []
|
||||||
|
try:
|
||||||
|
for tcp in self.tcps:
|
||||||
|
tcp_id = self.model.getFrameId(tcp)
|
||||||
|
self.tcp_ids.append(tcp_id)
|
||||||
|
except:
|
||||||
|
print(f'tcp_id of {tcp} not found')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -107,14 +115,13 @@ class KinematicsSolver():
|
|||||||
min_j = [-3.14159, -2.2689, -3.14159, -2.3562, -3.14159, -2.234, -6.14159]
|
min_j = [-3.14159, -2.2689, -3.14159, -2.3562, -3.14159, -2.234, -6.14159]
|
||||||
if max_j is None:
|
if max_j is None:
|
||||||
max_j = [3.14159, 2.2689, 3.14159, 2.3562, 3.14159, 2.234, 6.14159]
|
max_j = [3.14159, 2.2689, 3.14159, 2.3562, 3.14159, 2.234, 6.14159]
|
||||||
if rad_flag:
|
|
||||||
|
k = 1.0 if rad_flag is True else 1.0 / 180 * pi
|
||||||
|
|
||||||
for i in range(7):
|
for i in range(7):
|
||||||
self.model.lowerPositionLimit[i] = min_j[i]
|
self.model.lowerPositionLimit[i] = min_j[i] * k
|
||||||
self.model.upperPositionLimit[i] = max_j[i]
|
self.model.upperPositionLimit[i] = max_j[i] * k
|
||||||
else:
|
|
||||||
for i in range(7):
|
|
||||||
self.model.lowerPositionLimit[i] = min_j[i] / 180 * pi
|
|
||||||
self.model.upperPositionLimit[i] = max_j[i] / 180 * pi
|
|
||||||
|
|
||||||
def forward_kinematics(self, joint_angles, tool="omnipic"):
|
def forward_kinematics(self, joint_angles, tool="omnipic"):
|
||||||
"""
|
"""
|
||||||
@@ -142,8 +149,14 @@ class KinematicsSolver():
|
|||||||
pin.updateFramePlacements(self.model, self.data)
|
pin.updateFramePlacements(self.model, self.data)
|
||||||
|
|
||||||
# Get frame transform
|
# Get frame transform
|
||||||
# frame_id = self.tool_frames[tool]
|
if tool in self.tcps:
|
||||||
frame_id = self.scissor_frame_id
|
frame_id = self.tcp_ids[self.tcps.index(tool)]
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
frame_id = self.tool_frames[tool]
|
||||||
|
except:
|
||||||
|
print(f'{tool} definition not found')
|
||||||
|
|
||||||
frame_transform = self.data.oMf[frame_id]
|
frame_transform = self.data.oMf[frame_id]
|
||||||
|
|
||||||
# Extract results
|
# Extract results
|
||||||
@@ -154,16 +167,8 @@ class KinematicsSolver():
|
|||||||
rpy = pin.rpy.matrixToRpy(rotation)
|
rpy = pin.rpy.matrixToRpy(rotation)
|
||||||
|
|
||||||
# Compute quaternion
|
# Compute quaternion
|
||||||
# quat = pin.Quaternion(rotation)
|
|
||||||
pose = np.concatenate([position, rpy], axis=0)
|
pose = np.concatenate([position, rpy], axis=0)
|
||||||
return pose
|
return pose
|
||||||
# return {
|
|
||||||
# 'position': position,
|
|
||||||
# # 'rotation': rotation,
|
|
||||||
# 'rpy': rpy,
|
|
||||||
# 'quaternion': [quat.x, quat.y, quat.z, quat.w],
|
|
||||||
# # 'transform': frame_transform
|
|
||||||
# }
|
|
||||||
|
|
||||||
def inverse_kinematics(self, target_position, target_rpy=None,
|
def inverse_kinematics(self, target_position, target_rpy=None,
|
||||||
target_quat=None, initial_guess=None,
|
target_quat=None, initial_guess=None,
|
||||||
@@ -224,7 +229,14 @@ class KinematicsSolver():
|
|||||||
iter_count = 0
|
iter_count = 0
|
||||||
prev_error = float('inf')
|
prev_error = float('inf')
|
||||||
|
|
||||||
|
# ee_frame_id = self.tool_frames[tool]
|
||||||
|
if tool in self.tcps:
|
||||||
|
ee_frame_id = self.tcp_ids[self.tcps.index(tool)]
|
||||||
|
else:
|
||||||
|
try:
|
||||||
ee_frame_id = self.tool_frames[tool]
|
ee_frame_id = self.tool_frames[tool]
|
||||||
|
except:
|
||||||
|
print(f'{tool} definition not found')
|
||||||
|
|
||||||
J = pin.computeFrameJacobian(
|
J = pin.computeFrameJacobian(
|
||||||
self.model,
|
self.model,
|
||||||
|
|||||||
Reference in New Issue
Block a user