Skip to content

Commit

Permalink
Add getPublishers functionality (#1)
Browse files Browse the repository at this point in the history
* Add getPublishers function

* Re-build
  • Loading branch information
hello-amal authored Jul 18, 2024
1 parent e52e204 commit 54173dd
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 49 deletions.
96 changes: 66 additions & 30 deletions build/roslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -3340,15 +3340,15 @@ Param.prototype.get = function(callback) {
var paramClient = new Service({
ros : this.ros,
name : '/rosapi/get_param',
serviceType : 'rosapi/GetParam'
serviceType : 'rosapi_msgs/srv/GetParam'
});

var request = new ServiceRequest({
name : this.name
});

paramClient.callService(request, function(result) {
var value = JSON.stringify(result.value);
var value = JSON.parse(result.value);
callback(value);
});
};
Expand All @@ -3363,7 +3363,7 @@ Param.prototype.set = function(value, callback) {
var paramClient = new Service({
ros : this.ros,
name : '/rosapi/set_param',
serviceType : 'rosapi/SetParam'
serviceType : 'rosapi_msgs/srv/SetParam'
});

var request = new ServiceRequest({
Expand All @@ -3383,7 +3383,7 @@ Param.prototype.delete = function(callback) {
var paramClient = new Service({
ros : this.ros,
name : '/rosapi/delete_param',
serviceType : 'rosapi/DeleteParam'
serviceType : 'rosapi_msgs/srv/DeleteParam'
});

var request = new ServiceRequest({
Expand Down Expand Up @@ -3585,7 +3585,7 @@ Ros.prototype.getActionServers = function(callback, failedCallback) {
var getActionServers = new Service({
ros : this,
name : '/rosapi/action_servers',
serviceType : 'rosapi/GetActionServers'
serviceType : 'rosapi_msgs/srv/GetActionServers'
});

var request = new ServiceRequest({});
Expand Down Expand Up @@ -3619,7 +3619,7 @@ Ros.prototype.getTopics = function(callback, failedCallback) {
var topicsClient = new Service({
ros : this,
name : '/rosapi/topics',
serviceType : 'rosapi/Topics'
serviceType : 'rosapi_msgs/srv/Topics'
});

var request = new ServiceRequest();
Expand Down Expand Up @@ -3652,7 +3652,7 @@ Ros.prototype.getTopicsForType = function(topicType, callback, failedCallback) {
var topicsForTypeClient = new Service({
ros : this,
name : '/rosapi/topics_for_type',
serviceType : 'rosapi/TopicsForType'
serviceType : 'rosapi_msgs/srv/TopicsForType'
});

var request = new ServiceRequest({
Expand All @@ -3674,6 +3674,41 @@ Ros.prototype.getTopicsForType = function(topicType, callback, failedCallback) {
}
};

/**
* Retrieve a list of active publishers for a topic in ROS.
*
* @param {string} topic - The topic to find publishers for.
* @param {function} callback - Function with the following params:
* @param {string[]} callback.publishers - Array of publisher names.
* @param {function} [failedCallback] - The callback function when the service call failed with params:
* @param {string} failedCallback.error - The error message reported by ROS.
*/
Ros.prototype.getPublishers = function(topic, callback, failedCallback) {
var publishersClient = new Service({
ros : this,
name : '/rosapi/publishers',
serviceType : 'rosapi_msgs/srv/Publishers'
});

var request = new ServiceRequest({
topic: topic
});
if (typeof failedCallback === 'function'){
publishersClient.callService(request,
function(result) {
callback(result.publishers);
},
function(message){
failedCallback(message);
}
);
} else {
publishersClient.callService(request, function(result) {
callback(result.publishers);
});
}
}

/**
* Retrieve a list of active service names in ROS.
*
Expand All @@ -3686,7 +3721,7 @@ Ros.prototype.getServices = function(callback, failedCallback) {
var servicesClient = new Service({
ros : this,
name : '/rosapi/services',
serviceType : 'rosapi/Services'
serviceType : 'rosapi_msgs/srv/Services'
});

var request = new ServiceRequest();
Expand Down Expand Up @@ -3719,7 +3754,7 @@ Ros.prototype.getServicesForType = function(serviceType, callback, failedCallbac
var servicesForTypeClient = new Service({
ros : this,
name : '/rosapi/services_for_type',
serviceType : 'rosapi/ServicesForType'
serviceType : 'rosapi_msgs/srv/ServicesForType'
});

var request = new ServiceRequest({
Expand Down Expand Up @@ -3755,7 +3790,7 @@ Ros.prototype.getActionGoalDetails = function(type, callback, failedCallback) {
var actionTypeClient = new Service({
ros : this,
name : '/rosapi/action_goal_details',
serviceType : 'rosapi/ActionGoalDetails'
serviceType : 'rosapi_msgs/srv/ActionGoalDetails'
});
var request = new ServiceRequest({
type: type
Expand Down Expand Up @@ -3791,7 +3826,7 @@ Ros.prototype.getActionGoalDetails = function(type, callback, failedCallback) {
var actionTypeClient = new Service({
ros : this,
name : '/rosapi/action_feedback_details',
serviceType : 'rosapi/ActionFeedbackDetails'
serviceType : 'rosapi_msgs/srv/ActionFeedbackDetails'
});
var request = new ServiceRequest({
type: type
Expand Down Expand Up @@ -3827,7 +3862,7 @@ Ros.prototype.getActionGoalDetails = function(type, callback, failedCallback) {
var actionTypeClient = new Service({
ros : this,
name : '/rosapi/action_result_details',
serviceType : 'rosapi/ActionResultDetails'
serviceType : 'rosapi_msgs/srv/ActionResultDetails'
});
var request = new ServiceRequest({
type: type
Expand Down Expand Up @@ -3863,7 +3898,7 @@ Ros.prototype.getServiceRequestDetails = function(type, callback, failedCallback
var serviceTypeClient = new Service({
ros : this,
name : '/rosapi/service_request_details',
serviceType : 'rosapi/ServiceRequestDetails'
serviceType : 'rosapi_msgs/srv/ServiceRequestDetails'
});
var request = new ServiceRequest({
type: type
Expand Down Expand Up @@ -3899,7 +3934,7 @@ Ros.prototype.getServiceResponseDetails = function(type, callback, failedCallbac
var serviceTypeClient = new Service({
ros : this,
name : '/rosapi/service_response_details',
serviceType : 'rosapi/ServiceResponseDetails'
serviceType : 'rosapi_msgs/srv/ServiceResponseDetails'
});
var request = new ServiceRequest({
type: type
Expand Down Expand Up @@ -3933,7 +3968,7 @@ Ros.prototype.getNodes = function(callback, failedCallback) {
var nodesClient = new Service({
ros : this,
name : '/rosapi/nodes',
serviceType : 'rosapi/Nodes'
serviceType : 'rosapi_msgs/srv/Nodes'
});

var request = new ServiceRequest();
Expand Down Expand Up @@ -3985,7 +4020,7 @@ Ros.prototype.getNodeDetails = function(node, callback, failedCallback) {
var nodesClient = new Service({
ros : this,
name : '/rosapi/node_details',
serviceType : 'rosapi/NodeDetails'
serviceType : 'rosapi_msgs/srv/NodeDetails'
});

var request = new ServiceRequest({
Expand Down Expand Up @@ -4019,7 +4054,7 @@ Ros.prototype.getParams = function(callback, failedCallback) {
var paramsClient = new Service({
ros : this,
name : '/rosapi/get_param_names',
serviceType : 'rosapi/GetParamNames'
serviceType : 'rosapi_msgs/srv/GetParamNames'
});
var request = new ServiceRequest();
if (typeof failedCallback === 'function'){
Expand Down Expand Up @@ -4051,7 +4086,7 @@ Ros.prototype.getParams = function(callback, failedCallback) {
var actionTypeClient = new Service({
ros : this,
name : '/rosapi/action_type',
serviceType : 'rosapi/ActionType'
serviceType : 'rosapi_msgs/srv/ActionType'
});
var request = new ServiceRequest({
action: action
Expand Down Expand Up @@ -4086,7 +4121,7 @@ Ros.prototype.getTopicType = function(topic, callback, failedCallback) {
var topicTypeClient = new Service({
ros : this,
name : '/rosapi/topic_type',
serviceType : 'rosapi/TopicType'
serviceType : 'rosapi_msgs/srv/TopicType'
});
var request = new ServiceRequest({
topic: topic
Expand Down Expand Up @@ -4121,7 +4156,7 @@ Ros.prototype.getServiceType = function(service, callback, failedCallback) {
var serviceTypeClient = new Service({
ros : this,
name : '/rosapi/service_type',
serviceType : 'rosapi/ServiceType'
serviceType : 'rosapi_msgs/srv/ServiceType'
});
var request = new ServiceRequest({
service: service
Expand Down Expand Up @@ -4156,7 +4191,7 @@ Ros.prototype.getMessageDetails = function(message, callback, failedCallback) {
var messageDetailClient = new Service({
ros : this,
name : '/rosapi/message_details',
serviceType : 'rosapi/MessageDetails'
serviceType : 'rosapi_msgs/srv/MessageDetails'
});
var request = new ServiceRequest({
type: message
Expand Down Expand Up @@ -4244,7 +4279,7 @@ Ros.prototype.getTopicsAndRawTypes = function(callback, failedCallback) {
var topicsAndRawTypesClient = new Service({
ros : this,
name : '/rosapi/topics_and_raw_types',
serviceType : 'rosapi/TopicsAndRawTypes'
serviceType : 'rosapi_msgs/srv/TopicsAndRawTypes'
});

var request = new ServiceRequest();
Expand Down Expand Up @@ -5251,6 +5286,7 @@ mixin(Ros, ['Actions'], actionhandle);
*/

var ActionClient = require('../actionlib/ActionClient');
var ActionHandle = require('../ros2action/Actions.js')
var Goal = require('../actionlib/Goal');

var Service = require('../core/Service.js');
Expand Down Expand Up @@ -5301,19 +5337,19 @@ function TFClient(options) {
this._isDisposed = false;

// Create an Action Client
this.actionClient = new ActionClient({
this.actionClient = new ActionHandle({
ros : options.ros,
serverName : this.serverName,
actionName : 'tf2_web_republisher/TFSubscriptionAction',
omitStatus : true,
omitResult : true
name : this.serverName,
actionType : 'tf2_web_republisher/action/TFSubscription',
// omitStatus : true,
// omitResult : true
});

// Create a Service Client
this.serviceClient = new Service({
ros: options.ros,
name: this.repubServiceName,
serviceType: 'tf2_web_republisher/RepublishTFs'
serviceType: 'tf2_web_republisher/srv/RepublishTFs'
});
}

Expand Down Expand Up @@ -5406,7 +5442,7 @@ TFClient.prototype.processResponse = function(response) {
this.currentTopic = new Topic({
ros: this.ros,
name: response.topic_name,
messageType: 'tf2_web_republisher/TFArray'
messageType: 'tf2_web_republisher/msg/TFArray'
});
this._subscribeCB = this.processTFArray.bind(this);
this.currentTopic.subscribe(this._subscribeCB);
Expand Down Expand Up @@ -5478,7 +5514,7 @@ TFClient.prototype.dispose = function() {

module.exports = TFClient;

},{"../actionlib/ActionClient":10,"../actionlib/Goal":12,"../core/Service.js":18,"../core/ServiceRequest.js":19,"../core/Topic.js":22,"../math/Transform":26}],36:[function(require,module,exports){
},{"../actionlib/ActionClient":10,"../actionlib/Goal":12,"../core/Service.js":18,"../core/ServiceRequest.js":19,"../core/Topic.js":22,"../math/Transform":26,"../ros2action/Actions.js":33}],36:[function(require,module,exports){
var Ros = require('../core/Ros');
var mixin = require('../mixin');

Expand Down
2 changes: 1 addition & 1 deletion build/roslib.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 54173dd

Please sign in to comment.