Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purge 'side' parameter #1083

Merged
merged 33 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c660f29
changed docstring
PetervDooren Feb 16, 2021
4c553aa
seperated gripper from arm naming conventions
PetervDooren Feb 16, 2021
06aa3ff
change loading from parameter server
PetervDooren Feb 16, 2021
b6749c9
change hardware status (currently unused)
PetervDooren Feb 16, 2021
1cb1bb3
object_repr + marker topic
PetervDooren Feb 16, 2021
abe09a2
Merge branch 'master' into fix/side_param
PetervDooren Feb 16, 2021
54292da
changed action server
PetervDooren Feb 16, 2021
527faff
represent arm with name, not side
PetervDooren Feb 19, 2021
c6a51b8
made gripper frame configurable
PetervDooren Feb 19, 2021
4798967
rename side to name
PetervDooren Feb 19, 2021
e476b20
fix imports
PetervDooren Feb 19, 2021
1073872
removed side argument from arm
PetervDooren Feb 19, 2021
188911b
changed handover detector interface
PetervDooren Feb 19, 2021
d9c5268
update mockbot
PetervDooren Feb 19, 2021
73d9b22
clean up grasp_sensor
PetervDooren Feb 23, 2021
59a4aef
added test for the construction of hero
PetervDooren Mar 6, 2021
387e064
hacked torso arm_gathering
PetervDooren Mar 6, 2021
64047af
added test_depend
PetervDooren Mar 11, 2021
3d41cc9
renamed atrribute arm_name to name
PetervDooren Mar 20, 2021
25ab978
Merge branch 'master' into fix/side_param
PetervDooren Mar 20, 2021
d018927
moved init node to main
PetervDooren Mar 20, 2021
9990790
changed rviz config
PetervDooren Mar 23, 2021
3864a96
Merge branch 'master' into fix/side_param
MatthijsBurgh Mar 30, 2021
ae671e9
dont prefix sensor_topic
PetervDooren Apr 6, 2021
bab5470
Merge branch 'master' into fix/side_param
PetervDooren Apr 6, 2021
407b74b
remove hero_test from robot_skills
PetervDooren Apr 6, 2021
59332f7
remove test depend
PetervDooren Apr 6, 2021
bf05f7a
make gripper action_client parameterised
PetervDooren Apr 6, 2021
b09df1e
move arm_names out of torso.py
PetervDooren Apr 11, 2021
e78b0a2
Merge remote-tracking branch 'origin/master' into fix/side_param
MatthijsBurgh Apr 14, 2021
9df8d98
empty commit
PetervDooren Apr 21, 2021
6903751
Revert "empty commit"
PetervDooren Apr 21, 2021
c1230ff
dont use a mutable default argument
PetervDooren Apr 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions amigo_skills/src/amigo_skills/amigo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ def __init__(self, wait_services=False):
self.add_body_part('torso', torso.Torso(self.robot_name, self.tf_listener, self.get_joint_states))

# construct left arm
left_arm = arms.Arm(self.robot_name, self.tf_listener, self.get_joint_states, "left")
left_arm.add_part('gripper', gripper.ParrallelGripper(self.robot_name, self.tf_listener, 'left'))
left_arm = arms.Arm(self.robot_name, self.tf_listener, self.get_joint_states, "arm_left")
left_arm.add_part('gripper', gripper.ParrallelGripper(self.robot_name, self.tf_listener, 'gripper_left'))
left_arm.add_part('handover_detector',
handover_detector.HandoverDetector(self.robot_name, self.tf_listener, 'left'))
handover_detector.HandoverDetector(self.robot_name, self.tf_listener, 'handoverdetector_left'))
self.add_arm_part('leftArm', left_arm)

# construct right arm
right_arm = arms.Arm(self.robot_name, self.tf_listener, self.get_joint_states, "right")
right_arm.add_part('gripper', gripper.ParrallelGripper(self.robot_name, self.tf_listener, 'right'))
right_arm = arms.Arm(self.robot_name, self.tf_listener, self.get_joint_states, "arm_right")
right_arm.add_part('gripper', gripper.ParrallelGripper(self.robot_name, self.tf_listener, 'gripper_right'))
right_arm.add_part('handover_detector',
handover_detector.HandoverDetector(self.robot_name, self.tf_listener, 'right'))
handover_detector.HandoverDetector(self.robot_name, self.tf_listener, 'handoverdetector_right'))
self.add_arm_part('rightArm', right_arm)

self.add_body_part('head', head.Head(self.robot_name, self.tf_listener))
Expand Down
15 changes: 4 additions & 11 deletions hero_skills/src/hero_skills/hero.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ def __init__(self, wait_services=False):
self.add_body_part('torso', torso.Torso(self.robot_name, self.tf_listener, self.get_joint_states))

# add hero's arm
hero_arm = arms.Arm(self.robot_name, self.tf_listener, self.get_joint_states, "left")
hero_arm.add_part('force_sensor', force_sensor.ForceSensor(
self.robot_name, self.tf_listener, self.robot_name + "/wrist_wrench/raw"
))
hero_arm.add_part('gripper', gripper.ParrallelGripper(self.robot_name, self.tf_listener, 'left'))
hero_arm.add_part('handover_detector', handover_detector.HandoverDetector(
self.robot_name, self.tf_listener, 'left'
))
hero_arm = arms.Arm(self.robot_name, self.tf_listener, self.get_joint_states, "arm_center")
hero_arm.add_part('force_sensor', force_sensor.ForceSensor(self.robot_name, self.tf_listener, "/" + self.robot_name + "/wrist_wrench/raw"))
hero_arm.add_part('gripper', gripper.ParrallelGripper(self.robot_name, self.tf_listener, 'gripper'))
hero_arm.add_part('handover_detector', handover_detector.HandoverDetector(self.robot_name, self.tf_listener, 'handover_detector'))

self.add_arm_part('leftArm', hero_arm)

Expand Down Expand Up @@ -61,9 +57,6 @@ def __init__(self, wait_services=False):
# Reasoning/world modeling
self.add_body_part('ed', world_model_ed.ED(self.robot_name, self.tf_listener))

# Rename joint names
self.parts['leftArm'].joint_names = self.parts['leftArm'].load_param('skills/arm/joint_names')

# These don't work for HSR because (then) Toyota's diagnostics aggregator makes the robot go into error somehow
for part in self.parts.values():
part.unsubscribe_hardware_status()
Expand Down
49 changes: 23 additions & 26 deletions robot_skills/src/robot_skills/arm/arms.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,67 +262,64 @@ def _test_die(self, cond, feature, hint=''):
"""
if not cond:
msg = "get_arm for '{}' arm did not request '{}' access. Hint: {}"
raise AssertionError(msg.format(self._arm.side, feature, hint))
raise AssertionError(msg.format(self._arm.name, feature, hint))

def __repr__(self):
return "PublicArm(arm={arm})".format(arm=self._arm)


class Arm(RobotPart):
"""
A single arm can be either left or right, extends Arms:
Use left or right to get arm while running from the python console

Examples:
>>> left.send_goal(0.265, 1, 0.816, 0, 0, 0, 60) # doctest: +SKIP
or Equivalently:
>>> left.send_goal(px=0.265, py=1, pz=0.816, yaw=0, pitch=0, roll=0, time_out=60, pre_grasp=False, frame_id='/amigo/base_link') # doctest: +SKIP
A kinematic chain ending in an end_effector. Can be controlled using either joint goals or a goal to reach with
the end_effector described in carthesian coordinates.
"""
def __init__(self, robot_name, tf_listener, get_joint_states, side):
def __init__(self, robot_name, tf_listener, get_joint_states, name):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this interface truly generic we should make it so that not all parameters, actions, tf_frames are linked via the arm name. Then we should allow these things as parameters to the interface. But that might be something for another day...

"""
constructor

:param robot_name: robot_name
:param tf_listener: tf_server.TFClient()
:param get_joint_states: get_joint_states function for getting the last joint states
:param side: left or right
:param name: string used to identify the arm
"""
super(Arm, self).__init__(robot_name=robot_name, tf_listener=tf_listener)
self.side = side
self.name = name

self._operational = True # In simulation, there will be no hardware cb

# Get stuff from the parameter server
offset = self.load_param('skills/arm/' + self.side + '/grasp_offset/')
offset = self.load_param('skills/gripper/grasp_offset/')
self.offset = kdl.Frame(kdl.Rotation.RPY(offset["roll"], offset["pitch"], offset["yaw"]),
kdl.Vector(offset["x"], offset["y"], offset["z"]))
MatthijsBurgh marked this conversation as resolved.
Show resolved Hide resolved

self.marker_to_grippoint_offset = self.load_param('skills/arm/' + self.side + '/marker_to_grippoint')
self.marker_to_grippoint_offset = self.load_param('skills/gripper/marker_to_grippoint')

# Grasp offsets
go = self.load_param('skills/arm/' + self.side + '/base_offset')
go = self.load_param('skills/' + self.name + '/base_offset')
self._base_offset = kdl.Vector(go["x"], go["y"], go["z"])

self.joint_names = self.load_param('skills/arm/joint_names')
self.joint_names = [name + "_" + self.side for name in self.joint_names]
self.joint_names = self.load_param('skills/' + self.name + '/joint_names')
self.torso_joint_names = self.load_param('skills/torso/joint_names')

self.default_configurations = self.load_param('skills/arm/default_configurations')
self.default_trajectories = self.load_param('skills/arm/default_trajectories')
self.default_configurations = self.load_param('skills/' + self.name + '/default_configurations')
self.default_trajectories = self.load_param('skills/' + self.name + '/default_trajectories')

self.grasp_frame = self.load_param('skills/gripper/grasp_frame') #TODO remove gripper specific parameters

# listen to the hardware status to determine if the arm is available
self.subscribe_hardware_status(self.side + '_arm')
self.subscribe_hardware_status(self.name)

# Init grasp precompute actionlib
self._ac_grasp_precompute = self.create_simple_action_client(
"/" + robot_name + "/" + self.side + "_arm/grasp_precompute", GraspPrecomputeAction)
"/" + robot_name + "/" + self.name + "/grasp_precompute", GraspPrecomputeAction)

# Init joint trajectory action server
self._ac_joint_traj = self.create_simple_action_client(
"/" + robot_name + "/body/joint_trajectory_action", FollowJointTrajectoryAction)

# Init marker publisher
self._marker_publisher = rospy.Publisher(
"/" + robot_name + "/" + self.side + "_arm/grasp_target",
"/" + robot_name + "/" + self.name + "/grasp_target",
visualization_msgs.msg.Marker, queue_size=10)

self.get_joint_states = get_joint_states
Expand Down Expand Up @@ -397,10 +394,10 @@ def close(self):
:return: no return
"""
try:
rospy.loginfo("{0} arm cancelling all goals on all arm-related ACs on close".format(self.side))
rospy.loginfo("{0} arm cancelling all goals on all arm-related ACs on close".format(self.name))
except AttributeError:
print("{0} arm cancelling all goals on all arm-related ACs on close. rospy is already deleted.".
format(self.side))
format(self.name))

self._ac_grasp_precompute.cancel_all_goals()
self._ac_joint_traj.cancel_all_goals()
Expand Down Expand Up @@ -494,7 +491,7 @@ def send_goal(self, frameStamped, timeout=30, pre_grasp=False, first_joint_pos_o
if result == GoalStatus.SUCCEEDED:

result_pose = self.tf_listener.lookupTransform(self.robot_name + "/base_link",
self.robot_name + "/grippoint_{}".format(self.side),
self.robot_name + "/" + self.grasp_frame,
rospy.Time(0))
dx = grasp_precompute_goal.goal.x - result_pose[0][0]
dy = grasp_precompute_goal.goal.y - result_pose[0][1]
Expand Down Expand Up @@ -603,7 +600,7 @@ def _send_joint_trajectory(self, joints_references, max_joint_vel=0.7, timeout=r
points=ps)
goal = FollowJointTrajectoryGoal(trajectory=joint_trajectory, goal_time_tolerance=timeout)

rospy.logdebug("Send {0} arm to jointcoords \n{1}".format(self.side, ps))
rospy.logdebug("Send {0} arm to jointcoords \n{1}".format(self.name, ps))

import time; time.sleep(0.001) # This is necessary: the rtt_actionlib in the hardware seems
# to only have a queue size of 1 and runs at 1000 hz. This
Expand Down Expand Up @@ -690,4 +687,4 @@ def _publish_marker(self, goal, color, ns=""):
self._marker_publisher.publish(marker)

def __repr__(self):
return "Arm(side='{side}')".format(side=self.side)
return "Arm(name='{}')".format(self.name)
12 changes: 7 additions & 5 deletions robot_skills/src/robot_skills/arm/grasp_sensor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import rospy

from std_msgs.msg import Float32MultiArray

from robot_skills.robot_part import RobotPart


Expand Down Expand Up @@ -85,20 +89,18 @@ class GraspSensor(RobotPart):
"""
Sensor to detect whether or not the robot is holding an object.
"""

def __init__(self, robot_name, tf_listener, side):
def __init__(self, robot_name, tf_listener, sensor_topic):
"""
constructor

:param robot_name: robot_name
:param tf_listener: tf_server.TFClient()
:param side: left or right arm of the robot.
:param sensor_topic: name of the topic where measurements are published
"""
super(GraspSensor, self).__init__(robot_name=robot_name, tf_listener=tf_listener)
# Init grasp sensor subscriber
self._grasp_sensor_state = GripperMeasurement(0.0)
rospy.Subscriber("/" + robot_name + "/" + side + "_arm/proximity_sensor",
std_msgs.msg.Float32MultiArray, self._grasp_sensor_callback)
rospy.Subscriber(sensor_topic, Float32MultiArray, self._grasp_sensor_callback)

@property
def object_in_gripper_measurement(self):
Expand Down
6 changes: 3 additions & 3 deletions robot_skills/src/robot_skills/arm/gripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ def __init__(self, robot_name, tf_listener, gripper_name):
"""
super(ParrallelGripper, self).__init__(robot_name=robot_name, tf_listener=tf_listener)
self.gripper_name = gripper_name
offset = self.load_param('skills/arm/' + self.gripper_name + '/grasp_offset/')
offset = self.load_param('skills/' + self.gripper_name + '/grasp_offset/')
PetervDooren marked this conversation as resolved.
Show resolved Hide resolved
self.offset = kdl.Frame(kdl.Rotation.RPY(offset["roll"], offset["pitch"], offset["yaw"]),
kdl.Vector(offset["x"], offset["y"], offset["z"]))

# Init gripper actionlib
self._ac_gripper = self.create_simple_action_client(
"/" + robot_name + "/" + self.gripper_name + "_arm/gripper/action", GripperCommandAction)
ac_name = self.load_param('skills/' + self.gripper_name + '/ac_gripper')
self._ac_gripper = self.create_simple_action_client(ac_name, GripperCommandAction)

def send_goal(self, state, timeout=5.0, max_torque=0.1): #Todo: should send goal be universal for all grippers?
"""
Expand Down
30 changes: 14 additions & 16 deletions robot_skills/src/robot_skills/arm/handover_detector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function

import rospy
from std_msgs.msg import Bool

from robot_skills.robot_part import RobotPart

Expand All @@ -9,16 +10,16 @@ class HandoverDetector(RobotPart):
"""
Sensor functionality to detect when a handover is taking place
"""
def __init__(self, robot_name, tf_listener, side):
def __init__(self, robot_name, tf_listener, name):
"""
constructor

:param robot_name: robot_name
:param tf_listener: tf_server.TFClient()
:param side: string used to identify the sensor
:param name: string used to identify the sensor
"""
super(HandoverDetector, self).__init__(robot_name=robot_name, tf_listener=tf_listener)
self.side = side
self.name = name

def handover_to_human(self, timeout=10):
"""
Expand All @@ -28,20 +29,18 @@ def handover_to_human(self, timeout=10):
:param timeout: timeout in seconds
:return: True or False
"""
pub = rospy.Publisher('/' + self.robot_name + '/handoverdetector_' + self.side + '/toggle_robot2human',
std_msgs.msg.Bool, queue_size=1, latch=True)
pub.publish(std_msgs.msg.Bool(True))
pub = rospy.Publisher('/' + self.robot_name + '/' + self.name + '/toggle_robot2human', Bool, queue_size=1,
latch=True)
pub.publish(Bool(True))

try:
rospy.wait_for_message('/' + self.robot_name + '/handoverdetector_' + self.side + '/result', std_msgs.msg.Bool,
timeout)
# print('/'+self.robot_name+'/handoverdetector_'+self.side+'/result')
rospy.wait_for_message('/' + self.robot_name + '/' + self.name + '/result', Bool, timeout)
# print('/'+self.robot_name+'/'+self.name+'/result')
return True
except rospy.ROSException as e:
rospy.logerr(e)
return False


def handover_to_robot(self, timeout=10):
"""
Handover an item from a human to the robot.
Expand All @@ -50,14 +49,13 @@ def handover_to_robot(self, timeout=10):
:param timeout: timeout in seconds
:return: True or False
"""
pub = rospy.Publisher('/' + self.robot_name + '/handoverdetector_' + self.side + '/toggle_human2robot',
std_msgs.msg.Bool, queue_size=1, latch=True)
pub.publish(std_msgs.msg.Bool(True))
pub = rospy.Publisher('/' + self.robot_name + '/' + self.name + '/toggle_human2robot', Bool, queue_size=1,
latch=True)
pub.publish(Bool(True))

try:
rospy.wait_for_message('/' + self.robot_name + '/handoverdetector_' + self.side + '/result', std_msgs.msg.Bool,
timeout)
# print('/'+self.robot_name+'/handoverdetector_'+self.side+'/result')
rospy.wait_for_message('/' + self.robot_name + '/' + self.name + '/result', Bool, timeout)
# print('/'+self.robot_name+'/'+self.name+'/result')
return True
except rospy.ROSException as e:
rospy.logerr(e)
Expand Down
8 changes: 4 additions & 4 deletions robot_skills/src/robot_skills/mockbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def __init__(self, robot_name, tf_listener, *args, **kwargs):


class Arm(MockedRobotPart):
def __init__(self, robot_name, tf_listener, get_joint_states, side):
def __init__(self, robot_name, tf_listener, get_joint_states, name):
super(Arm, self).__init__(robot_name, tf_listener)

self.side = side
self.arm_name = name
self.get_joint_states = get_joint_states

self._operational = True
Expand Down Expand Up @@ -417,8 +417,8 @@ def __init__(self, *args, **kwargs):
self.add_body_part('base', Base(self.robot_name, self.tf_listener))
self.add_body_part('torso', Torso(self.robot_name, self.tf_listener, self.get_joint_states))

self.add_arm_part('leftArm', Arm(self.robot_name, self.tf_listener, self.get_joint_states, "left"))
self.add_arm_part('rightArm', Arm(self.robot_name, self.tf_listener, self.get_joint_states, "right"))
self.add_arm_part('leftArm', Arm(self.robot_name, self.tf_listener, self.get_joint_states, "arm_left"))
self.add_arm_part('rightArm', Arm(self.robot_name, self.tf_listener, self.get_joint_states, "arm_right"))

self.add_body_part('head', Head(self.robot_name, self.tf_listener))

Expand Down
6 changes: 5 additions & 1 deletion robot_skills/src/robot_skills/torso.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ def __init__(self, robot_name, tf_listener, get_joint_states):
super(Torso, self).__init__(robot_name=robot_name, tf_listener=tf_listener)

self.joint_names = self.load_param('skills/torso/joint_names')
self._arm_joint_names = self.load_param('skills/arm/joint_names')
self.default_configurations = self.load_param('skills/torso/default_configurations')
self.default_tolerance = self.load_param('/skills/torso/default_tolerance')
self.lower_limit = self.default_configurations['lower_limit']
self.upper_limit = self.default_configurations['upper_limit']

try: # TODO make sure this is no longer needed
PetervDooren marked this conversation as resolved.
Show resolved Hide resolved
self._arm_joint_names = self.load_param('skills/arm_center/joint_names')
except KeyError:
self._arm_joint_names = []

# Init action client
self.ac_move_torso = self.create_simple_action_client('/' + self.robot_name + '/body/joint_trajectory_action',
control_msgs.msg.FollowJointTrajectoryAction)
Expand Down
7 changes: 2 additions & 5 deletions robot_skills/test/rostest/test_compose_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ def testfunction2(self):


class TestComposeRobot(unittest.TestCase):

@classmethod
def setUpClass(cls):
rospy.init_node('test_composable_robot_interface2')

def test_compose_robot(self):
robot = Robot("testbot")
part = RobotPart("testbot", robot.tf_listener)
Expand All @@ -68,6 +63,8 @@ def test_compose_functionality(self):

self.assertFalse(hasattr(robot.special_part, 'testfunction2'))


if __name__ == '__main__':
import rostest
rospy.init_node('test_composable_robot_interface')
rostest.rosrun('robot_skills', 'test_composable_robot_interface', TestComposeRobot)