Skip to content

Commit

Permalink
Add fail callback and missing docstrings to params (#357)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Vollrath <matt@endpoint.com>
Co-authored-by: Matthijs van der Burgh <MatthijsBurgh@outlook.com>
Co-authored-by: Jihoon Lee <jihoonlee.in@gmail.com>
Co-authored-by: Ezra Brooks <ezra@brooks.cx>
  • Loading branch information
5 people authored Nov 28, 2023
1 parent bcf5145 commit 5efa9c3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/core/Param.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ function Param(options) {
*
* @param {function} callback - Function with the following params:
* @param {Object} callback.value - The value of the param from ROS.
* @param {function} [failedCallback] - Function when the service call failed with the following params:
* @param {string} failedCallback.error - The error message reported by ROS.
*/
Param.prototype.get = function(callback) {
Param.prototype.get = function(callback, failedCallback) {
var paramClient = new Service({
ros : this.ros,
name : '/rosapi/get_param',
Expand All @@ -40,16 +42,18 @@ Param.prototype.get = function(callback) {
paramClient.callService(request, function(result) {
var value = JSON.parse(result.value);
callback(value);
});
}, failedCallback);
};

/**
* Set the value of the param in ROS.
*
* @param {Object} value - The value to set param to.
* @param {function} callback - The callback function.
* @param {function} [callback] - The callback function.
* @param {function} [failedCallback] - The callback function when the service call failed.
* @param {string} failedCallback.error - The error message reported by ROS.
*/
Param.prototype.set = function(value, callback) {
Param.prototype.set = function(value, callback, failedCallback) {
var paramClient = new Service({
ros : this.ros,
name : '/rosapi/set_param',
Expand All @@ -61,15 +65,17 @@ Param.prototype.set = function(value, callback) {
value : JSON.stringify(value)
});

paramClient.callService(request, callback);
paramClient.callService(request, callback, failedCallback);
};

/**
* Delete this parameter on the ROS server.
*
* @param {function} callback - The callback function.
* @param {function} [callback] - The callback function when the service call succeeded.
* @param {function} [failedCallback] - The callback function when the service call failed.
* @param {string} failedCallback.error - The error message reported by ROS.
*/
Param.prototype.delete = function(callback) {
Param.prototype.delete = function(callback, failedCallback) {
var paramClient = new Service({
ros : this.ros,
name : '/rosapi/delete_param',
Expand All @@ -80,7 +86,7 @@ Param.prototype.delete = function(callback) {
name : this.name
});

paramClient.callService(request, callback);
paramClient.callService(request, callback, failedCallback);
};

module.exports = Param;

0 comments on commit 5efa9c3

Please sign in to comment.