File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,11 +96,13 @@ const as = new rosnodejs.ActionServer({
9696 actionServer: '/turtle_shape'
9797});
9898
99- as.on('goal, function (goal) {
99+ as.on('goal' , function (goal) {
100100 goal.setAccepted();
101101});
102102
103- const ac = nh.actionClientInterface('/turtle_shape, 'turtle_actionlib/ShapeAction');
103+ as.start();
104+
105+ const ac = nh.actionClientInterface('/turtle_shape', 'turtle_actionlib/ShapeAction');
104106ac.sendGoal({ goal: {edges: 3, radius: 1}});
105107```
106108## Run the turtlesim example
Original file line number Diff line number Diff line change @@ -73,14 +73,24 @@ class ActionServer extends EventEmitter {
7373
7474 this . _lastCancelStamp = timeUtils . epoch ( ) ;
7575
76+ this . _statusFrequency = 5 ;
7677 this . _statusListTimeout = 5 ;
78+ this . _statusHandle = null ;
79+
80+ this . _started = false ;
7781 }
7882
7983 generateGoalId ( ) {
8084 return this . _asInterface . generateGoalId ( ) ;
8185 }
8286
87+ start ( ) {
88+ this . _started = true ;
89+ this . _statusHandle = setInterval ( this . publishStatus . bind ( this ) , 1000 / this . _statusFrequency ) ;
90+ }
91+
8392 shutdown ( ) {
93+ clearInterval ( this . _statusHandle ) ;
8494 return this . _asInterface . shutdown ( ) ;
8595 }
8696
@@ -89,6 +99,10 @@ class ActionServer extends EventEmitter {
8999 }
90100
91101 _handleGoal ( msg ) {
102+ if ( ! this . _started ) {
103+ return ;
104+ }
105+
92106 const newGoalId = msg . goal_id . id ;
93107
94108 let handle = this . _getGoalHandle ( newGoalId ) ;
@@ -123,6 +137,10 @@ class ActionServer extends EventEmitter {
123137 }
124138
125139 _handleCancel ( msg ) {
140+ if ( ! this . _started ) {
141+ return ;
142+ }
143+
126144 const cancelId = msg . id ;
127145 const cancelStamp = msg . stamp ;
128146 const cancelStampIsZero = timeUtils . isZeroTime ( cancelStamp ) ;
You can’t perform that action at this time.
0 commit comments