Skip to content

Commit c34fe82

Browse files
chfritzchris-smith
authored andcommitted
Updated getActionClient to invoke actionClientInterface the right way (#87)
Fixes #86.
1 parent 4e562ce commit c34fe82

3 files changed

Lines changed: 28 additions & 20 deletions

File tree

src/examples/turtle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ rosnodejs.initNode('/my_node', {onTheFly: true}).then((rosNode) => {
7474

7575
// wait two seconds for previous example to complete
7676
setTimeout(function() {
77-
let shapeActionGoal = rosnodejs.require('turtle_actionlib').msg.ShapeActionGoal;
78-
let ac = rosnodejs.nh.actionClient(
77+
const shapeActionGoal = rosnodejs.require('turtle_actionlib').msg.ShapeActionGoal;
78+
const ac = rosnodejs.nh.actionClient(
7979
"/turtle_shape",
8080
"turtle_actionlib/ShapeAction"
8181
);

src/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ let pingMasterTimeout = null;
4848
* Helper function to see if the master is available and able to accept
4949
* connections.
5050
* @param {number} timeout time in ms between connection attempts
51-
* @param {number} maxTimeout maximum time in ms to retry before timing out.
51+
* @param {number} maxTimeout maximum time in ms to retry before timing out.
5252
* A negative number will make it retry forever. 0 will only make one attempt
5353
* before timing out.
5454
*/
5555
function _checkMasterHelper(timeout=100, maxTimeout=-1) {
5656
let startTime = Date.now();
5757
const localHelper = (resolve,reject) => {
5858
pingMasterTimeout = setTimeout(() => {
59-
// also check that the slave api server is set up
59+
// also check that the slave api server is set up
6060
if (!rosNode.slaveApiSetupComplete()) {
6161
if (Date.now() - startTime >= maxTimeout && !(maxTimeout < 0) ) {
6262
log.error(`Unable to register with master node [${rosNode.getRosMasterUri()}]: unable to set up slave API Server. Stopping...`);
@@ -320,18 +320,18 @@ let Rosnodejs = {
320320
/**
321321
Get an action client for a given type and action server.
322322
323+
**Deprecated**: Use rosNode.nh.actionClientInterface instead.
324+
323325
Example:
324-
let ac = rosNode.getActionClient({
325-
type: "turtle_actionlib/ShapeAction",
326-
actionServer: "/turtle_shape"
327-
});
326+
let ac = rosNode.nh.getActionClient(
327+
"/turtle_shape", "turtle_actionlib/ShapeAction");
328328
let shapeActionGoal =
329329
rosnodejs.require('turtle_actionlib').msg.ShapeActionGoal;
330-
ac.sendGoal(new shapeActionGoal({
331-
goal: { edges: 3, radius: 1 } }));
330+
ac.sendGoal(new shapeActionGoal({ goal: { edges: 3, radius: 1 } }));
332331
*/
333332
getActionClient(options) {
334-
return this.nh.actionClientInterface(options);
333+
return this.nh.actionClientInterface(
334+
options.actionServer, options.type, options);
335335
}
336336
};
337337

src/lib/NodeHandle.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,15 @@ class NodeHandle {
202202
return this.actionClientInterface(...args);
203203
}
204204

205-
actionClientInterface(actionServer, type, options={}) {
205+
/**
206+
* Create an action client
207+
* @param {String} actionServer name of the action server
208+
* (e.g., "/turtle_shape")
209+
* @param {String} type action type
210+
* (e.g., "turtle_actionlib/ShapeAction")
211+
* @return {[type]} an instance of ActionClientInterface
212+
*/
213+
actionClientInterface(actionServer, type, options = {}) {
206214
if (!actionServer) {
207215
throw new Error(`Unable to create action client to unspecified server - [${actionServer}]`);
208216
}
@@ -311,11 +319,11 @@ class NodeHandle {
311319
* @property {{name: string, type: string}[]} topics Array of topics
312320
*/
313321

314-
315-
/**
322+
323+
/**
316324
* Get list of topics that can be subscribed to. This does not return
317325
* topics that have no publishers.
318-
*
326+
*
319327
* @param {string} subgraph Restrict topic names to match within the
320328
* specified subgraph. Subgraph namespace is
321329
* resolved relative to this node's namespace.
@@ -328,7 +336,7 @@ class NodeHandle {
328336

329337
/**
330338
* Retrieve list topic names and their types.
331-
*
339+
*
332340
* @return {Promise.<TopicList>}
333341
*/
334342
getTopicTypes() {
@@ -338,9 +346,9 @@ class NodeHandle {
338346

339347
/**
340348
* @typedef {Object} SystemState
341-
* @property {{...string:Array.<string>}} publishers An object with topic names as keys and
349+
* @property {{...string:Array.<string>}} publishers An object with topic names as keys and
342350
* an array of publishers as values
343-
* @property {{...string:Array.<string>}} subscribers An object with topic names as keys and
351+
* @property {{...string:Array.<string>}} subscribers An object with topic names as keys and
344352
* an array of subscribers as values
345353
* @property {{...string:Array.<string>}} services An object with service names as keys and
346354
* an array of providers as values
@@ -349,11 +357,11 @@ class NodeHandle {
349357
/**
350358
* Retrieve list representation of system state (i.e. publishers,
351359
* subscribers, and services).
352-
*
360+
*
353361
* @return {Promise.<SystemState>}
354362
*/
355363
getSystemState(){
356-
return this._node.getSystemState();
364+
return this._node.getSystemState();
357365
}
358366

359367
//------------------------------------------------------------------

0 commit comments

Comments
 (0)