13
13
from prpy .planning .base import UnsupportedPlanningError
14
14
from herbbase import HerbBase
15
15
from herbpantilt import HERBPantilt
16
- from ros_control_client_py import ControllerManagerClient
16
+ from ros_control_client_py import ControllerManagerClient , JointStateClient
17
17
18
18
logger = logging .getLogger ('herbpy' )
19
19
@@ -48,15 +48,16 @@ def __init__(self, left_arm_sim, right_arm_sim, right_ft_sim,
48
48
head_sim )
49
49
if not self .full_controller_sim :
50
50
# any non-simulation requires ros and the ros_control stack
51
- print 'CLINT: something not sim'
52
51
import rospy
53
52
if not rospy .core .is_initialized ():
54
53
rospy .init_node ('herbpy' )
55
54
55
+ # update openrave state from /joint_states
56
+ self ._jointstate_client = JointStateClient (
57
+ self , topic_name = '/joint_states' )
58
+
56
59
self .controller_manager = ControllerManagerClient ()
57
60
self .controllers_always_on .append ('joint_state_controller' )
58
- else :
59
- print 'CLINT: all sim'
60
61
61
62
62
63
# Convenience attributes for accessing self components.
@@ -163,7 +164,7 @@ def __init__(self, left_arm_sim, right_arm_sim, right_ft_sim,
163
164
raise ValueError ('Failed loading named hand configurations from "{:s}".' .format (
164
165
hand_configs_path ))
165
166
else :
166
- logger .warn ('Unrecognized hand class. Not loading named configurations.' )
167
+ logger .warning ('Unrecognized hand class. Not loading named configurations.' )
167
168
168
169
# Initialize a default planning pipeline.
169
170
from prpy .planning import (
@@ -353,8 +354,7 @@ def _ExecuteTrajectory(self, traj, defer=False, timeout=None, period=0.01,
353
354
354
355
# Verify that the trajectory has non-zero duration.
355
356
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'
358
358
' function that produced this trajectory to return a'
359
359
' single-waypoint trajectory.' , FutureWarning )
360
360
@@ -363,48 +363,56 @@ def _ExecuteTrajectory(self, traj, defer=False, timeout=None, period=0.01,
363
363
active_controllers = []
364
364
if self .head in traj_manipulators :
365
365
# 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.' )
368
370
371
+ # logic to determine which controllers are needed
369
372
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' )
379
377
else :
380
378
if self .right_arm in traj_manipulators :
381
379
if not self .right_arm .IsSimulated ():
382
380
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 ))
389
381
else :
390
382
active_controllers .append (self .right_arm .sim_controller )
391
383
392
384
if self .left_arm in traj_manipulators :
393
385
if not self .left_arm .IsSimulated ():
394
386
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 ))
401
387
else :
402
388
active_controllers .append (self .left_arm .sim_controller )
403
389
404
390
# load and activate controllers
405
391
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 ()))
408
416
409
417
if needs_base :
410
418
if (hasattr (self , 'base' ) and hasattr (self .base , 'controller' ) and
@@ -471,25 +479,26 @@ def SetStiffness(self, stiffness, manip=None):
471
479
if isinstance (stiffness , numbers .Number ) and not (0 <= stiffness <= 1 ):
472
480
raise Exception ('Stiffness must be boolean or decimal in the range [0, 1];'
473
481
'got {}.' .format (stiffness ))
482
+
474
483
# TODO head after Schunk integration
484
+ if manip is self .head :
485
+ raise NotImplementedError ('Head immobilized under ros_control, SetStiffness not available.' )
486
+
475
487
new_manip_controllers = []
476
488
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' )
483
493
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 ):
485
495
new_manip_controllers .append (
486
496
'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 ):
488
498
new_manip_controllers .append (
489
499
'right_gravity_compensation_controller' )
490
500
491
- self .controller_manager .request (self .controllers_always_on +
492
- new_manip_controllers ).switch ()
501
+ self .controller_manager .request (new_manip_controllers ).switch ()
493
502
494
503
def Say (self , words , block = True ):
495
504
"""Speak 'words' using talker action service or espeak locally in simulation"""
0 commit comments