Skip to content

Commit 5f6aa36

Browse files
mjycchris-smith
authored andcommitted
ActionServer updates
* Add action.start to make rosnodejs' ActionServer compatible with ActionClient in python & C++ * Publishes action status at statusFrequency
1 parent 5c54a50 commit 5f6aa36

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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');
104106
ac.sendGoal({ goal: {edges: 3, radius: 1}});
105107
```
106108
## Run the turtlesim example

src/actions/ActionServer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)