1717
1818'use strict' ;
1919
20- const rosnodejs = require ( '../index.js' ) ;
2120const timeUtils = require ( '../utils/time_utils.js' ) ;
2221let EventEmitter = require ( 'events' ) ;
2322
@@ -29,28 +28,29 @@ class ActionClient extends EventEmitter {
2928
3029 this . _actionServer = options . actionServer ;
3130
32- const nh = rosnodejs . nh ;
31+ this . _rosnodejs = options . rosnodejs ;
32+ const nh = this . _rosnodejs . getNodeHandle ( ) ;
3333
3434 // FIXME: support user options for these parameters
35- this . _goalPub = nh . advertise ( this . _actionServer + '/goal' ,
35+ this . _goalPub = nh . advertise ( this . _actionServer + '/goal' ,
3636 this . _actionType + 'Goal' ,
3737 { queueSize : 1 , latching : true } ) ;
3838
39- this . _cancelPub = nh . advertise ( this . _actionServer + '/cancel' ,
39+ this . _cancelPub = nh . advertise ( this . _actionServer + '/cancel' ,
4040 'actionlib_msgs/GoalID' ,
4141 { queueSize : 1 , latching : true } ) ;
4242
43- this . _statusSub = nh . subscribe ( this . _actionServer + '/status' ,
43+ this . _statusSub = nh . subscribe ( this . _actionServer + '/status' ,
4444 'actionlib_msgs/GoalStatusArray' ,
4545 ( msg ) => { this . _handleStatus ( msg ) ; } ,
4646 { queueSize : 1 } ) ;
4747
48- this . _feedbackSub = nh . subscribe ( this . _actionServer + '/feedback' ,
48+ this . _feedbackSub = nh . subscribe ( this . _actionServer + '/feedback' ,
4949 this . _actionType + 'Feedback' ,
5050 ( msg ) => { this . _handleFeedback ( msg ) ; } ,
5151 { queueSize : 1 } ) ;
5252
53- this . _statusSub = nh . subscribe ( this . _actionServer + '/result' ,
53+ this . _statusSub = nh . subscribe ( this . _actionServer + '/result' ,
5454 this . _actionType + 'Result' ,
5555 ( msg ) => { this . _handleResult ( msg ) ; } ,
5656 { queueSize : 1 } ) ;
@@ -97,6 +97,19 @@ class ActionClient extends EventEmitter {
9797 this . _goals [ goalId ] = goal ;
9898
9999 this . _goalPub . publish ( goal ) ;
100+ return goal ;
101+ }
102+
103+ /** Cancel the given goal. If none is given, send an empty goal message,
104+ i.e. cancel all goals. See
105+ http://wiki.ros.org/actionlib/DetailedDescription#The_Messages
106+ */
107+ cancel ( goal ) {
108+ if ( ! goal ) {
109+ let GoalID = this . _rosnodejs . require ( 'actionlib_msgs' ) . msg . GoalID ;
110+ goal = new GoalID ( ) ;
111+ }
112+ this . _cancelPub . publish ( goal ) ;
100113 }
101114
102115 _generateGoalId ( ) {
0 commit comments