@@ -30,43 +30,27 @@ class Body {
30
30
parameter . get ( parameter_ => {
31
31
// Joint names
32
32
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
49
33
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
+ }
70
54
} ) ;
71
55
} // End of constructor
72
56
@@ -86,36 +70,36 @@ class Body {
86
70
trajectory : {
87
71
/* eslint camelcase:0 */
88
72
joint_names : this . jointNames [ cmd . body_part ] ,
89
- points : [ { positions : this . defaultConfigurations [ cmd . body_part ] [ cmd . configuration ] } ] ,
73
+ points : [ {
74
+ positions : this . defaultConfigurations [ cmd . body_part ] [ cmd . configuration ] ,
75
+ time_from_start : { secs : 2 } ,
76
+ } ] ,
90
77
} ,
91
78
goal_time_tolerance : {
92
79
secs : 5 ,
93
80
} ,
94
81
} ,
95
82
} ) ;
83
+ console . debug ( goal ) ;
96
84
97
85
// Send the goal with a default timeout of 10.0 seconds
98
86
goal . send ( 10 ) ;
99
87
} // End of sendGoal
100
88
101
89
/**
102
90
* Sends a gripper goal
103
- * @param {object } cmd: object containing 'side' ('left' or 'right') and 'direction' ('open' or 'close')
91
+ * @param {object } cmd: object containing 'side' and 'direction' ('open' or 'close')
104
92
*/
105
93
sendGripperGoal ( cmd ) {
106
94
console . log ( 'Robot body: gripper goal:' , cmd ) ;
107
95
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 {
115
- console . error ( 'Gripper command side must be either left or right. Right now, it is' , cmd . side ) ;
96
+ if ( ! Object . prototype . hasOwnProperty . call ( this . grippers , cmd . side ) ) {
97
+ console . error ( `Gripper command side must be one of [${ Object . keys ( this . grippers ) } ]. Right now, it is '${ cmd . side } '` ) ;
116
98
return ;
117
99
}
118
100
101
+ const actionClient = this . grippers [ cmd . side ] ;
102
+
119
103
// Get the direction: open or close. This is mapped to the enum defined in the action description
120
104
// int8 OPEN=-1
121
105
// int8 CLOSE=1
0 commit comments