@@ -30,43 +30,27 @@ class Body {
3030 parameter . get ( parameter_ => {
3131 // Joint names
3232 this . jointNames = { } ;
33- // Arm joint names. N.B.: the suffices 'left' and 'right'
34- // must be added
35- this . jointNames . arm = [ ] ;
36- this . jointNames . leftArm = [ ] ;
37- this . jointNames . rightArm = [ ] ;
38- for ( const jointName in parameter_ . arm . joint_names . values ( ) ) { // eslint-disable-line guard-for-in
39- this . jointNames . arm . push ( `${ jointName } ` ) ;
40- this . jointNames . leftArm . push ( `${ jointName } _left` ) ;
41- this . jointNames . rightArm . push ( `${ jointName } _right` ) ;
42- }
43-
44- // Torso joint name
45- this . jointNames . torso = parameter_ . torso . joint_names ;
46-
47- // Default joint configuration. N.B., the configurations for the left
48- // and right arm are equal
4933 this . defaultConfigurations = { } ;
50- this . defaultConfigurations . torso = parameter_ . torso . default_configurations ;
51- this . defaultConfigurations . arm = parameter_ . arm . default_configurations ;
52- this . defaultConfigurations . leftArm = parameter_ . arm . default_configurations ;
53- this . defaultConfigurations . rightArm = parameter_ . arm . default_configurations ;
54- } ) ;
55-
56- // Define the gripper action
57- this . leftGripperAction = new ActionClient ( {
58- ros ,
59- serverName : 'left_arm/gripper/action' ,
60- actionName : 'tue_manipulation_msgs/GripperCommandAction' ,
61- timeout : 0 ,
62- } ) ;
63-
64- // Define the gripper action
65- this . rightGripperAction = new ActionClient ( {
66- ros ,
67- serverName : 'right_arm/gripper/action' ,
68- actionName : 'tue_manipulation_msgs/GripperCommandAction' ,
69- timeout : 0 ,
34+ this . grippers = { } ;
35+
36+ for ( const [ partName , part ] of Object . entries ( parameter_ ) ) {
37+ if ( Object . prototype . hasOwnProperty . call ( part , 'joint_names' ) ) {
38+ this . jointNames [ partName ] = part . joint_names ;
39+ }
40+
41+ if ( Object . prototype . hasOwnProperty . call ( part , 'default_configurations' ) ) {
42+ this . defaultConfigurations [ partName ] = part . default_configurations ;
43+ }
44+
45+ if ( Object . prototype . hasOwnProperty . call ( part , 'ac_gripper' ) ) {
46+ this . grippers [ partName ] = new ActionClient ( {
47+ ros ,
48+ serverName : part . ac_gripper ,
49+ actionName : 'tue_manipulation_msgs/GripperCommandAction' ,
50+ timeout : 0 ,
51+ } ) ;
52+ }
53+ }
7054 } ) ;
7155 } // End of constructor
7256
@@ -100,22 +84,18 @@ class Body {
10084
10185 /**
10286 * Sends a gripper goal
103- * @param {object } cmd: object containing 'side' ('left' or 'right') and 'direction' ('open' or 'close')
87+ * @param {object } cmd: object containing 'side' and 'direction' ('open' or 'close')
10488 */
10589 sendGripperGoal ( cmd ) {
10690 console . log ( 'Robot body: gripper goal:' , cmd ) ;
10791
108- let actionClient ;
109- // Get the side
110- if ( cmd . side === 'left' ) {
111- actionClient = this . leftGripperAction ;
112- } else if ( cmd . side === 'right' ) {
113- actionClient = this . rightGripperAction ;
114- } else {
92+ if ( ! Object . prototype . hasOwnProperty . call ( this . grippers , cmd . side ) ) {
11593 console . error ( 'Gripper command side must be either left or right. Right now, it is' , cmd . side ) ;
11694 return ;
11795 }
11896
97+ const actionClient = this . grippers [ cmd . side ] ;
98+
11999 // Get the direction: open or close. This is mapped to the enum defined in the action description
120100 // int8 OPEN=-1
121101 // int8 CLOSE=1
0 commit comments