Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"devDependencies": {
"@testing-library/react": "^14.2.1",
"@types/node": "^20.11.19",
"@types/ws": "^8.5.10",
"eslint": "^8.56.0",
"globals": "^14.0.0",
"jsdoc": "^4.0.2",
Expand Down
30 changes: 14 additions & 16 deletions src/actionlib/ActionClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import { EventEmitter } from 'eventemitter3';
*
*/
export default class ActionClient extends EventEmitter {
goals = {};
/** flag to check if a status has been received */
receivedStatus = false
/**
* @param {Object} options
* @param {Ros} options.ros - The ROSLIB.Ros connection handle.
Expand All @@ -31,18 +34,13 @@ export default class ActionClient extends EventEmitter {
*/
constructor(options) {
super();
var that = this;
this.ros = options.ros;
this.serverName = options.serverName;
this.actionName = options.actionName;
this.timeout = options.timeout;
this.omitFeedback = options.omitFeedback;
this.omitStatus = options.omitStatus;
this.omitResult = options.omitResult;
this.goals = {};

// flag to check if a status has been received
var receivedStatus = false;

// create the topics associated with actionlib
this.feedbackListener = new Topic({
Expand Down Expand Up @@ -81,10 +79,10 @@ export default class ActionClient extends EventEmitter {

// subscribe to the status topic
if (!this.omitStatus) {
this.statusListener.subscribe(function (statusMessage) {
receivedStatus = true;
statusMessage.status_list.forEach(function (status) {
var goal = that.goals[status.goal_id.id];
this.statusListener.subscribe((statusMessage) => {
this.receivedStatus = true;
statusMessage.status_list.forEach((status) => {
var goal = this.goals[status.goal_id.id];
if (goal) {
goal.emit('status', status);
}
Expand All @@ -94,8 +92,8 @@ export default class ActionClient extends EventEmitter {

// subscribe the the feedback topic
if (!this.omitFeedback) {
this.feedbackListener.subscribe(function (feedbackMessage) {
var goal = that.goals[feedbackMessage.status.goal_id.id];
this.feedbackListener.subscribe((feedbackMessage) => {
var goal = this.goals[feedbackMessage.status.goal_id.id];
if (goal) {
goal.emit('status', feedbackMessage.status);
goal.emit('feedback', feedbackMessage.feedback);
Expand All @@ -105,8 +103,8 @@ export default class ActionClient extends EventEmitter {

// subscribe to the result topic
if (!this.omitResult) {
this.resultListener.subscribe(function (resultMessage) {
var goal = that.goals[resultMessage.status.goal_id.id];
this.resultListener.subscribe((resultMessage) => {
var goal = this.goals[resultMessage.status.goal_id.id];

if (goal) {
goal.emit('status', resultMessage.status);
Expand All @@ -117,9 +115,9 @@ export default class ActionClient extends EventEmitter {

// If timeout specified, emit a 'timeout' event if the action server does not respond
if (this.timeout) {
setTimeout(function () {
if (!receivedStatus) {
that.emit('timeout');
setTimeout(() => {
if (!this.receivedStatus) {
this.emit('timeout');
}
}, this.timeout);
}
Expand Down
23 changes: 11 additions & 12 deletions src/actionlib/ActionListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default class ActionListener extends EventEmitter {
*/
constructor(options) {
super();
var that = this;
this.ros = options.ros;
this.serverName = options.serverName;
this.actionName = options.actionName;
Expand Down Expand Up @@ -57,25 +56,25 @@ export default class ActionListener extends EventEmitter {
messageType: this.actionName + 'Result'
});

goalListener.subscribe(function (goalMessage) {
that.emit('goal', goalMessage);
goalListener.subscribe((goalMessage) => {
this.emit('goal', goalMessage);
});

statusListener.subscribe(function (statusMessage) {
statusMessage.status_list.forEach(function (status) {
that.emit('status', status);
statusListener.subscribe((statusMessage) => {
statusMessage.status_list.forEach((status) => {
this.emit('status', status);
});
});

feedbackListener.subscribe(function (feedbackMessage) {
that.emit('status', feedbackMessage.status);
that.emit('feedback', feedbackMessage.feedback);
feedbackListener.subscribe((feedbackMessage) => {
this.emit('status', feedbackMessage.status);
this.emit('feedback', feedbackMessage.feedback);
});

// subscribe to the result topic
resultListener.subscribe(function (resultMessage) {
that.emit('status', resultMessage.status);
that.emit('result', resultMessage.result);
resultListener.subscribe((resultMessage) => {
this.emit('status', resultMessage.status);
this.emit('result', resultMessage.result);
});
}
}
42 changes: 18 additions & 24 deletions src/actionlib/Goal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,21 @@ import ActionClient from './ActionClient.js';
* * 'timeout' - If a timeout occurred while sending a goal.
*/
export default class Goal extends EventEmitter {
isFinished = false;
status = undefined;
result = undefined;
feedback = undefined;
// Create a random ID
goalID = 'goal_' + Math.random() + '_' + new Date().getTime();
/**
* @param {Object} options
* @param {ActionClient} options.actionClient - The ROSLIB.ActionClient to use with this goal.
* @param {Object} options.goalMessage - The JSON object containing the goal for the action server.
*/
constructor(options) {
super();
var that = this;
this.actionClient = options.actionClient;
this.goalMessage = options.goalMessage;
this.isFinished = false;
this.status = undefined;
this.result = undefined;
this.feedback = undefined;

// Used to create random IDs
var date = new Date();

// Create a random ID
this.goalID = 'goal_' + Math.random() + '_' + date.getTime();
// Fill in the goal message
this.goalMessage = {
goal_id: {
Expand All @@ -43,20 +38,20 @@ export default class Goal extends EventEmitter {
},
id: this.goalID
},
goal: this.goalMessage
goal: options.goalMessage
};

this.on('status', function (status) {
that.status = status;
this.on('status', (status) => {
this.status = status;
});

this.on('result', function (result) {
that.isFinished = true;
that.result = result;
this.on('result', (result) => {
this.isFinished = true;
this.result = result;
});

this.on('feedback', function (feedback) {
that.feedback = feedback;
this.on('feedback', (feedback) => {
this.feedback = feedback;
});

// Add the goal
Expand All @@ -68,12 +63,11 @@ export default class Goal extends EventEmitter {
* @param {number} [timeout] - A timeout length for the goal's result.
*/
send(timeout) {
var that = this;
that.actionClient.goalTopic.publish(that.goalMessage);
this.actionClient.goalTopic.publish(this.goalMessage);
if (timeout) {
setTimeout(function () {
if (!that.isFinished) {
that.emit('timeout');
setTimeout(() => {
if (!this.isFinished) {
this.emit('timeout');
}
}, timeout);
}
Expand Down
Loading