Skip to content

Commit

Permalink
Enable autodetection params determine the pack position for different…
Browse files Browse the repository at this point in the history
… hands (#817)

* Adding params

* Adding params

* Adding params

* Adding params

* Adding params

* Adding params

* Adding params

* Adding params

* Adding params

* Adding params

* Changing load params

* Updating positions to fit hand lite

* Fixing comments from review

* Fixing lint

* Fixing test

* Fixing all f strings

* Fixing all f strings
  • Loading branch information
Beatriz Leon authored Mar 15, 2023
1 parent 4b69bd6 commit 780639b
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 147 deletions.
190 changes: 118 additions & 72 deletions sr_moveit_hand_config/config/shadowhand.srdf.xacro

Large diffs are not rendered by default.

57 changes: 29 additions & 28 deletions sr_moveit_hand_config/config/shadowhands_prefix.srdf.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<xacro:arg name="lf" default="1"/>
<xacro:arg name="th" default="1"/>
<xacro:arg name="is_lite" default="0"/>
<xacro:arg name="is_biotac" default="0"/>
<xacro:arg name="tip_sensors" default="pst"/>
<xacro:arg name="hand_version" default="E3M5"/>
<xacro:arg name="robot_name" default="shadowhand_motor"/>
<xacro:arg name="hand_name" default="right_hand"/>

Expand Down Expand Up @@ -153,20 +154,20 @@

<group_state name="pack" group="$(arg hand_name)">
<xacro:if value="$(arg th)">
<xacro:thumb_state_pack prefix="$(arg prefix)" is_biotac="$(arg is_biotac)" />
<xacro:thumb_state_pack prefix="$(arg prefix)" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg ff)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg mf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg rf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:unless value="$(arg is_lite)">
<xacro:if value="$(arg lf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<joint name="$(arg prefix)WRJ1" value="0" />
<joint name="$(arg prefix)WRJ2" value="0" />
Expand All @@ -178,17 +179,17 @@
<xacro:thumb_state_open prefix="$(arg prefix)" />
</xacro:if>
<xacro:if value="$(arg ff)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg mf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg rf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:unless value="$(arg is_lite)">
<xacro:if value="$(arg lf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<joint name="$(arg prefix)WRJ1" value="0" />
<joint name="$(arg prefix)WRJ2" value="0" />
Expand Down Expand Up @@ -225,29 +226,29 @@
</xacro:if>
<xacro:if value="$(arg ff)">
<group_state name="first_finger_pack" group="$(arg prefix)first_finger">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</group_state>
</xacro:if>
<xacro:if value="$(arg mf)">
<group_state name="middle_finger_pack" group="$(arg prefix)middle_finger">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</group_state>
</xacro:if>
<xacro:if value="$(arg rf)">
<group_state name="ring_finger_pack" group="$(arg prefix)ring_finger">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</group_state>
</xacro:if>
<xacro:unless value="$(arg is_lite)">
<xacro:if value="$(arg lf)">
<group_state name="little_finger_pack" group="$(arg prefix)little_finger">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</group_state>
</xacro:if>
</xacro:unless>
<xacro:if value="$(arg th)">
<group_state name="thumb_pack" group="$(arg prefix)thumb">
<xacro:thumb_state_pack prefix="$(arg prefix)" is_biotac="$(arg is_biotac)" />
<xacro:thumb_state_pack prefix="$(arg prefix)" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</group_state>
</xacro:if>

Expand All @@ -273,20 +274,20 @@
</group_state>
<group_state name="fingers_pack" group="$(arg prefix)fingers">
<xacro:if value="$(arg th)">
<xacro:thumb_state_pack prefix="$(arg prefix)" is_biotac="$(arg is_biotac)" />
<xacro:thumb_state_pack prefix="$(arg prefix)" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)" />
</xacro:if>
<xacro:if value="$(arg ff)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg mf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg rf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:unless value="$(arg is_lite)">
<xacro:if value="$(arg lf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
</xacro:unless>
</group_state>
Expand All @@ -295,36 +296,36 @@
<xacro:thumb_state_open prefix="$(arg prefix)" />
</xacro:if>
<xacro:if value="$(arg ff)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="FF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg mf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg rf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:unless value="$(arg is_lite)">
<xacro:if value="$(arg lf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
</xacro:unless>
</group_state>
<group_state name="first_finger_point" group="$(arg prefix)fingers">
<xacro:if value="$(arg th)">
<xacro:thumb_state_pack prefix="$(arg prefix)" is_biotac="$(arg is_biotac)" />
<xacro:thumb_state_pack prefix="$(arg prefix)" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg ff)">
<xacro:finger_state_open prefix="$(arg prefix)" joint_prefix="FF" lf="0" />
</xacro:if>
<xacro:if value="$(arg mf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="MF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:if value="$(arg rf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="RF" lf="0" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
<xacro:unless value="$(arg is_lite)">
<xacro:if value="$(arg lf)">
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" is_biotac="$(arg is_biotac)"/>
<xacro:finger_state_pack prefix="$(arg prefix)" joint_prefix="LF" lf="1" tip_sensors="$(arg tip_sensors)" hand_version="$(arg hand_version)"/>
</xacro:if>
</xacro:unless>
</group_state>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# Software License Agreement (BSD License)
#
# Copyright (c) 2015, CITEC, Bielefeld University
# Copyright (c) 2015, 2023 CITEC, Bielefeld University
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,20 +29,19 @@
# POSSIBILITY OF SUCH DAMAGE.

# Author: Guillaume Walck <[email protected]>
# Author: Shadow Software Team <[email protected]>

"""
generate the srdf according to the urdf
syntax generate_hand_srdf [output filename]
"""

import sys
import os
from xml.dom.minidom import parse
import xacro
import rospy
import rospkg
from rosgraph.names import load_mappings

from urdf_parser_py.urdf import URDF


Expand All @@ -55,34 +54,23 @@ def __init__(self, urdf_str=None, load=True, save=True):

# load the urdf from the parameter server
urdf_str = rospy.get_param('robot_description')

robot = URDF.from_xml_string(urdf_str)

extracted_prefix = False
prefix = ""
first_finger = middle_finger = ring_finger = little_finger = thumb = False
is_lite = True
is_biotac = False
hand_name = "right_hand"

# Check if hand has the old biotac sensors
for key in robot.link_map:
link = robot.link_map[key]
if link.visual:
if hasattr(link.visual.geometry, 'filename'):
filename = os.path.basename(link.visual.geometry.filename)
if filename == "biotac_decimated.dae":
is_biotac = True
break
tip_sensors = "pst"
side = "right"

for key in robot.joint_map:
# any joint is supposed to have the same prefix and a joint name with 4 chars
if not extracted_prefix:
prefix = key.split("_")[0] + "_"
rospy.loginfo("Found prefix:" + prefix)
rospy.loginfo(f"Found prefix: {prefix}")
extracted_prefix = True
if prefix == "lh_":
hand_name = "left_hand"
side = "left"

if not first_finger and key.endswith("FFJ4"):
first_finger = True
Expand All @@ -96,32 +84,52 @@ def __init__(self, urdf_str=None, load=True, save=True):
thumb = True
if is_lite and key.endswith("WRJ2"):
is_lite = False

rospy.logdebug(f"Found fingers (ff mf rf lf th) {str(first_finger)} {str(middle_finger)} " +
f"{str(ring_finger)} {str(little_finger)} {str(thumb)}")
rospy.logdebug(f"is_lite: {str(is_lite)}")
rospy.logdebug(f"is_biotac: {str(is_biotac)}")
rospy.logdebug(f"Hand name: {str(hand_name)}")

mappings = load_mappings([f'prefix:={str(prefix)}',
hand_name = f"{side}_hand"

param = f"{side}_tip_sensors"
while not rospy.has_param(param):
rospy.sleep(0.5)
rospy.loginfo(f"waiting for {param}")
# load the tip_sensors from the parameter server after the hand has been auto-detected
tip_sensors_param = rospy.get_param(param)

# Check if hand has biotac 2p sensors
if tip_sensors_param.find('bt_2p') > -1:
tip_sensors = "bt_2p"
elif tip_sensors_param.find('bt_sp') > -1:
tip_sensors = "bt_sp"

param = f"{side}_hand_version"
while not rospy.has_param(param):
rospy.sleep(0.5)
rospy.loginfo(f"waiting for {param}")
# load the tip_sensors from the parameter server after the hand has been auto-detected
hand_version = rospy.get_param(param)

rospy.logdebug(f"Found fingers (ff mf rf lf th): {first_finger} {middle_finger} " +
f"{ring_finger} {little_finger} {thumb}")
rospy.logdebug(f"is_lite: {is_lite}")
rospy.logdebug(f"tip_sensors: {tip_sensors}")
rospy.logdebug(f"hand_version: {hand_version}")

mappings = load_mappings([f'prefix:={prefix}',
f'robot_name:={robot.name}',
f'ff:={str(int(first_finger))}',
f'mf:={str(int(middle_finger))}',
f'rf:={str(int(ring_finger))}',
f'lf:={str(int(little_finger))}',
f'th:={str(int(thumb))}',
f'is_lite:={str(int(is_lite))}',
f'is_biotac:={str(int(is_biotac))}',
f'hand_name:={str(hand_name)}'
f'ff:={first_finger}',
f'mf:={middle_finger}',
f'rf:={ring_finger}',
f'lf:={little_finger}',
f'th:={thumb}',
f'is_lite:={is_lite}',
f'tip_sensors:={tip_sensors}',
f'hand_version:={hand_version}',
f'hand_name:={hand_name}'
])

# the prefix version of the srdf_xacro must be loaded
package_path = rospkg.RosPack().get_path('sr_moveit_hand_config')
srdf_xacro_filename = f"{package_path}/config/shadowhands_prefix.srdf.xacro"
rospy.loginfo(f"File loaded {srdf_xacro_filename}")

# open and parse the xacro.srdf file
with open(srdf_xacro_filename, 'r', encoding="utf-8") as srdf_xacro_file:
with open(f"{package_path}/config/shadowhands_prefix.srdf.xacro", 'r', encoding="utf-8") as srdf_xacro_file:
self.srdf_xacro_xml = parse(srdf_xacro_file)

# expand the xacro
Expand All @@ -138,8 +146,7 @@ def __init__(self, urdf_str=None, load=True, save=True):

if load:
rospy.loginfo("Loading SRDF on parameter server")
robot_description_param = rospy.resolve_name('robot_description') + "_semantic"
rospy.set_param(robot_description_param,
rospy.set_param(rospy.resolve_name('robot_description') + "_semantic",
self.srdf_xacro_xml.toprettyxml(indent=' '))
if save:
output_path = f"{package_path}/config/generated_shadowhand.srdf"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/**
* @file test_end_effector.cpp
* @author Guillaume Walck
*/


/*********************************************************************
* Software License Agreement (BSD License)
*
* Software License Agreement (BSD License)
* Copyright (c) 2013, Willow Garage, Inc.
* All rights reserved.
*
Expand Down Expand Up @@ -36,7 +32,7 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/
*/

/* Author: Ioan Sucan */

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<launch>

<include file = "$(find sr_multi_moveit_config)/launch/demo.launch">
<param name="right_tip_sensors" value="pst" />
<param name="right_hand_version" value="E3M5" />
<include file = "$(find sr_multi_moveit_config)/launch/demo.launch">
<arg name="visualization" value="false" />
<arg name="robot_description" default="'$(find sr_multi_description)/urdf/srhand_ur.urdf.xacro'"/>
<arg name="robot_config_file" default="$(find sr_multi_moveit_config)/config/robot_configs/right_sh_ur10.yaml"/>
Expand Down
3 changes: 3 additions & 0 deletions sr_robot_launch/launch/load_robot_description.launch
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<!-- LOAD THE DESCRIPTION -->
<param if="$(eval arm and hand)" name="$(arg side)_hand_description" command="$(arg load_hand_description_command)"/>
<param if="$(arg sim)" name="robot_description" command="$(arg load_robot_description_command)"/>
<param name="$(arg side)_tip_sensors" value="$(arg tip_sensors)" />
<param name="$(arg side)_hand_version" value="$(arg hand_version)" />

<group unless="$(arg sim)">
<node if="$(arg arm)" name="construct_robot_description" pkg="sr_robot_launch" type="construct_robot_description" output="screen">
<param name="arm_type" value="$(arg robot_model)"/>
Expand Down
5 changes: 5 additions & 0 deletions sr_robot_launch/launch/load_robot_description_bimanual.launch
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
<param if="$(eval arg('hands') == 'both' or arg('hands') == 'left')" name="left_hand_description" command="$(arg load_left_hand_description_command)"/>

<param if="$(arg sim)" name="robot_description" command="$(arg load_robot_description_command)"/>
<param name="right_tip_sensors" value="$(arg right_tip_sensors)" />
<param name="right_hand_version" value="$(arg right_hand_version)" />
<param name="left_tip_sensors" value="$(arg left_tip_sensors)" />
<param name="left_hand_version" value="$(arg left_hand_version)" />

<group unless="$(arg sim)">
<node if="$(arg arms)" name="construct_robot_description" pkg="sr_robot_launch" type="construct_robot_description" output="screen">
<param name="arm_type" value="$(arg robot_model)"/>
Expand Down

0 comments on commit 780639b

Please sign in to comment.