Skip to content

Commit 73fb54c

Browse files
committed
update openrave from joint state; fixes for running on herb
1 parent 950cecf commit 73fb54c

File tree

2 files changed

+53
-42
lines changed

2 files changed

+53
-42
lines changed

setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
d = generate_distutils_setup(
66
packages=[
77
'herbpy',
8+
'herbpy.action',
9+
'herbpy.tsr',
810
],
911
package_dir={'': 'src'},
1012
)

src/herbpy/herbrobot.py

+51-42
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from prpy.planning.base import UnsupportedPlanningError
1414
from herbbase import HerbBase
1515
from herbpantilt import HERBPantilt
16-
from ros_control_client_py import ControllerManagerClient
16+
from ros_control_client_py import ControllerManagerClient, JointStateClient
1717

1818
logger = logging.getLogger('herbpy')
1919

@@ -48,15 +48,16 @@ def __init__(self, left_arm_sim, right_arm_sim, right_ft_sim,
4848
head_sim)
4949
if not self.full_controller_sim:
5050
# any non-simulation requires ros and the ros_control stack
51-
print 'CLINT: something not sim'
5251
import rospy
5352
if not rospy.core.is_initialized():
5453
rospy.init_node('herbpy')
5554

55+
# update openrave state from /joint_states
56+
self._jointstate_client = JointStateClient(
57+
self, topic_name='/joint_states')
58+
5659
self.controller_manager = ControllerManagerClient()
5760
self.controllers_always_on.append('joint_state_controller')
58-
else:
59-
print 'CLINT: all sim'
6061

6162

6263
# Convenience attributes for accessing self components.
@@ -163,7 +164,7 @@ def __init__(self, left_arm_sim, right_arm_sim, right_ft_sim,
163164
raise ValueError('Failed loading named hand configurations from "{:s}".'.format(
164165
hand_configs_path))
165166
else:
166-
logger.warn('Unrecognized hand class. Not loading named configurations.')
167+
logger.warning('Unrecognized hand class. Not loading named configurations.')
167168

168169
# Initialize a default planning pipeline.
169170
from prpy.planning import (
@@ -353,8 +354,7 @@ def _ExecuteTrajectory(self, traj, defer=False, timeout=None, period=0.01,
353354

354355
# Verify that the trajectory has non-zero duration.
355356
if traj.GetDuration() <= 0.0:
356-
import warnings
357-
warnings.warn('Executing zero-length trajectory. Please update the'
357+
logger.warning('Executing zero-length trajectory. Please update the'
358358
' function that produced this trajectory to return a'
359359
' single-waypoint trajectory.', FutureWarning)
360360

@@ -363,48 +363,56 @@ def _ExecuteTrajectory(self, traj, defer=False, timeout=None, period=0.01,
363363
active_controllers = []
364364
if self.head in traj_manipulators:
365365
# TODO head after Schunk integration
366-
import warnings
367-
warnings.warn('The head is currently disabled under ros_control.')
366+
if len(traj_manipulators) == 1:
367+
raise NotImplementedError('The head is currently disabled under ros_control.')
368+
else:
369+
logger.warning('The head is currently disabled under ros_control.')
368370

371+
# logic to determine which controllers are needed
369372
if (self.right_arm in traj_manipulators and
370-
self.left_arm in traj_manipulators):
371-
controllers_manip.append('dual_arm_trajectory_controller')
372-
joints = []
373-
joints.extend(self.right_arm.GetJointNames())
374-
joints.extend(self.left_arm.GetJointNames())
375-
active_controllers.append(
376-
RewdOrTrajectoryController(self, '',
377-
'dual_arm_trajectory_controller',
378-
joints))
373+
not self.right_arm.IsSimulated() and
374+
self.left_arm in traj_manipulators and
375+
not self.left_arm.IsSimulated()):
376+
controllers_manip.append('bimanual_trajectory_controller')
379377
else:
380378
if self.right_arm in traj_manipulators:
381379
if not self.right_arm.IsSimulated():
382380
controllers_manip.append('right_trajectory_controller')
383-
joints = []
384-
joints.extend(self.right_arm.GetJointNames())
385-
active_controllers.append(
386-
RewdOrTrajectoryController(self, '',
387-
'right_trajectory_controller',
388-
joints))
389381
else:
390382
active_controllers.append(self.right_arm.sim_controller)
391383

392384
if self.left_arm in traj_manipulators:
393385
if not self.left_arm.IsSimulated():
394386
controllers_manip.append('left_trajectory_controller')
395-
joints = []
396-
joints.extend(self.left_arm.GetJointNames())
397-
active_controllers.append(
398-
RewdOrTrajectoryController(self, '',
399-
'left_trajectory_controller',
400-
joints))
401387
else:
402388
active_controllers.append(self.left_arm.sim_controller)
403389

404390
# load and activate controllers
405391
if not self.full_controller_sim:
406-
self.controller_manager.request(self.controllers_always_on +
407-
controllers_manip).switch()
392+
self.controller_manager.request(controllers_manip).switch()
393+
394+
# repeat logic and actually construct controller clients
395+
# now that we've activated them on the robot
396+
if 'bimanual_trajectory_controller' in controllers_manip:
397+
joints = []
398+
joints.extend(self.right_arm.GetJointNames())
399+
joints.extend(self.left_arm.GetJointNames())
400+
active_controllers.append(
401+
RewdOrTrajectoryController(self, '',
402+
'bimanual_trajectory_controller',
403+
joints))
404+
else:
405+
if 'right_trajectory_controller' in controllers_manip:
406+
active_controllers.append(
407+
RewdOrTrajectoryController(self, '',
408+
'right_trajectory_controller',
409+
self.right_arm.GetJointNames()))
410+
411+
if 'left_trajectory_controller' in controllers_manip:
412+
active_controllers.append(
413+
RewdOrTrajectoryController(self, '',
414+
'left_trajectory_controller',
415+
self.left_arm.GetJointNames()))
408416

409417
if needs_base:
410418
if (hasattr(self, 'base') and hasattr(self.base, 'controller') and
@@ -471,25 +479,26 @@ def SetStiffness(self, stiffness, manip=None):
471479
if isinstance(stiffness, numbers.Number) and not (0 <= stiffness <= 1):
472480
raise Exception('Stiffness must be boolean or decimal in the range [0, 1];'
473481
'got {}.'.format(stiffness))
482+
474483
# TODO head after Schunk integration
484+
if manip is self.head:
485+
raise NotImplementedError('Head immobilized under ros_control, SetStiffness not available.')
486+
475487
new_manip_controllers = []
476488
if stiffness:
477-
if not self.left_arm_sim and (manip is None or manip is self.left_arm):
478-
new_manip_controllers.append(
479-
'left_position_controller')
480-
if not self.right_arm_sim and (manip is None or manip is self.right_arm):
481-
new_manip_controllers.append(
482-
'right_position_controller')
489+
if not self.left_arm.IsSimulated() and (manip is None or manip is self.left_arm):
490+
new_manip_controllers.append('left_joint_group_position_controller')
491+
if not self.right_arm.IsSimulated() and (manip is None or manip is self.right_arm):
492+
new_manip_controllers.append('right_joint_group_position_controller')
483493
else:
484-
if not self.left_arm_sim and (manip is None or manip is self.left_arm):
494+
if not self.left_arm.IsSimulated() and (manip is None or manip is self.left_arm):
485495
new_manip_controllers.append(
486496
'left_gravity_compensation_controller')
487-
if not self.right_arm_sim and (manip is None or manip is self.right_arm):
497+
if not self.right_arm.IsSimulated() and (manip is None or manip is self.right_arm):
488498
new_manip_controllers.append(
489499
'right_gravity_compensation_controller')
490500

491-
self.controller_manager.request(self.controllers_always_on +
492-
new_manip_controllers).switch()
501+
self.controller_manager.request(new_manip_controllers).switch()
493502

494503
def Say(self, words, block=True):
495504
"""Speak 'words' using talker action service or espeak locally in simulation"""

0 commit comments

Comments
 (0)