Skip to content

Commit 687d159

Browse files
committed
Add support for passive joints on IK
1 parent 1859487 commit 687d159

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Unreleased
1717
**Changed**
1818

1919
* Updated to COMPAS 0.10
20+
* Add support for passive joints on IK
2021

2122
**Removed**
2223

src/compas_fab/backends/ros/planner_backend_moveit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def inverse_kinematics_async(self, callback, errback, frame, base_link, group,
141141
attempts=attempts)
142142

143143
def convert_to_positions(response):
144-
callback(response.solution.joint_state.position)
144+
callback((response.solution.joint_state.position, response.solution.joint_state.name))
145145

146146
self.GET_POSITION_IK(self, (ik_request, ), convert_to_positions, errback)
147147

src/compas_fab/robots/robot.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,12 @@ def get_position_by_joint_name(self, configuration, joint_name, group=None):
514514
"Please pass a configuration with %d values or specify group" % len(names))
515515
return configuration.values[names.index(joint_name)]
516516

517-
def _scale_joint_values(self, values, scale_factor, group=None):
517+
def _scale_joint_values(self, values, names, scale_factor, group=None):
518518
"""Scales the scaleable joint values with scale_factor.
519519
"""
520-
joints = self.get_configurable_joints(group)
521-
if len(joints) != len(values):
522-
raise ValueError("Expected %d values for group %s, but received only %d." % (
523-
len(joints), group, len(values)))
524-
525520
values_scaled = []
526-
for v, j in zip(values, joints):
521+
for v, name in zip(values, names):
522+
j = self.get_joint_by_name(name)
527523
if j.is_scalable():
528524
v *= scale_factor
529525
values_scaled.append(v)
@@ -540,7 +536,7 @@ def _get_scaled_joint_positions_from_start_configuration(self, start_configurati
540536
joint_positions = start_configuration.values
541537
# scale the prismatic joints
542538
joint_positions = self._scale_joint_values(
543-
joint_positions, 1. / self.scale_factor)
539+
joint_positions, joint_names, 1. / self.scale_factor)
544540
return joint_positions
545541

546542
# ==========================================================================
@@ -906,14 +902,22 @@ def inverse_kinematics(self, frame_WCF, start_configuration=None,
906902
frame_RCF = self.to_local_coords(frame_WCF, group)
907903
frame_RCF.point /= self.scale_factor # must be in meters
908904

909-
joint_positions = self.client.inverse_kinematics(frame_RCF, base_link,
910-
group, joint_names, joint_positions,
911-
avoid_collisions, constraints, attempts,
912-
attached_collision_meshes)
913-
joint_positions = self._scale_joint_values(joint_positions, self.scale_factor)
914-
# full configuration # TODO group config?
915-
configuration = Configuration(joint_positions, self.get_configurable_joint_types())
905+
# The returned joint names might be more than the requested ones if there are passive joints present
906+
joint_positions, joint_names = self.client.inverse_kinematics(frame_RCF, base_link,
907+
group, joint_names, joint_positions,
908+
avoid_collisions, constraints, attempts,
909+
attached_collision_meshes)
910+
joint_types = [self.get_joint_by_name(n).type for n in joint_names]
911+
912+
joint_positions = self._scale_joint_values(joint_positions, joint_names, self.scale_factor)
913+
914+
# build configuration including passive joints
915+
configuration = Configuration(joint_positions, joint_types)
916916

917+
# return only group configuration
918+
# NOTE: it might actually make more sense to return
919+
# the configuration instance without extracting the group's config
920+
# because we lose the passive joint info
917921
return self.get_group_configuration(group, configuration)
918922

919923
def forward_kinematics(self, configuration, group=None, backend=None, link_name=None):

0 commit comments

Comments
 (0)