Skip to content

Commit 5515f9a

Browse files
committed
fix: added global solution for q7=none
1 parent 4a67782 commit 5515f9a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/frankik/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,20 @@ def inverse(
110110
q0 = self.q_home
111111

112112
new_pose = pose @ self.pose_inverse(tcp_offset) if tcp_offset is not None else pose
113+
114+
def get_min(qs):
115+
if len(qs) == 0:
116+
return np.nan
117+
q_diffs = np.sum((np.array(qs) - q0) * joint_weight, axis=1) ** 2
118+
return qs[np.argmin(q_diffs)]
119+
113120
if q7 is not None:
114-
q = ik(new_pose, q0, q7, is_fr3=(self.robot_type == RobotType.FR3)) # type: ignore
121+
if not global_solution:
122+
q = ik(new_pose, q0, q7, is_fr3=(self.robot_type == RobotType.FR3)) # type: ignore
123+
else:
124+
qs = ik_full(new_pose, q0, q7, is_fr3=(self.robot_type == RobotType.FR3)) # type: ignore
125+
q = get_min(qs)
126+
115127
else:
116128
qs = ik_sample_q7(
117129
new_pose,
@@ -121,8 +133,7 @@ def inverse(
121133
sample_interval=q7_sample_interval,
122134
full_ik=global_solution,
123135
) # type: ignore
124-
q_diffs = np.sum((np.array(qs) - q0) * joint_weight, axis=1) ** 2
125-
q = qs[np.argmin(q_diffs)]
136+
q = get_min(qs)
126137

127138
if np.isnan(q).any():
128139
return None

0 commit comments

Comments
 (0)