Skip to content

Commit

Permalink
Gets rid of boiler plate node() and topics().
Browse files Browse the repository at this point in the history
Can now initialize a topic directly. See example/how_to.js for an example.
  • Loading branch information
baalexander committed Apr 20, 2012
1 parent ddd18cb commit 6839c1d
Show file tree
Hide file tree
Showing 6 changed files with 445 additions and 517 deletions.
74 changes: 40 additions & 34 deletions example/how_to.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ describe('How to use rosnodejs', function() {
ros.types([
'std_msgs/String'
], function(String) {
var node = ros.node('talker');
node.topics([
{ topic: 'publish_example', messageType: String }
], function(publishExample) {
// Uses the ROS command line tool rostopic to echo messages published
// over the 'publish_example' topic.
var subscribeCommand = 'rostopic'
+ ' echo'
+ ' /publish_example';
var child = exec(subscribeCommand, function(error, stdout, stderr) {
should.not.exist(error);
});

var message = new String({ data: 'howdy' });
publishExample.publish(message);
setTimeout(done, 1500);
// Uses the ROS command line tool rostopic to echo messages published
// over the 'publish_example' topic.
var subscribecommand = 'rostopic'
+ ' echo'
+ ' /publish_example';
var child = exec(subscribecommand, function(error, stdout, stderr) {
should.not.exist(error);
});

// Creates the topic 'publish_example'
var publishExample = new ros.topic({
node : 'talker'
, topic : 'publish_example'
, messageType : String
});

// Sends a std_msgs/String message over the 'publish_example' topic.
var message = new String({ data: 'howdy' });
publishExample.publish(message);
setTimeout(done, 1500);
});
});

Expand All @@ -36,24 +39,27 @@ describe('How to use rosnodejs', function() {
ros.types([
'std_msgs/String'
], function(String) {
var node = ros.node('listener');
node.topics([
{ topic: 'subscribe_example', messageType: String }
], function(subscribeExample) {
subscribeExample.subscribe(function(message) {
message.data.should.equal('howdy');
done();
});

// Uses rostopic to publish a message on the subscribed to topic.
var publishCommand = 'rostopic'
+ ' pub'
+ ' /subscribe_example'
+ ' std_msgs/String'
+ ' howdy';
var child = exec(publishCommand, function(error, stdout, stderr) {
should.not.exist(error);
});
// Creates the topic 'subscribe_example'
var subscribeExample = new ros.topic({
node : 'listener'
, topic : 'subscribe_example'
, messageType : String
});

// Subscribes to the 'subscribe_example' topic
subscribeExample.subscribe(function(message) {
message.data.should.equal('howdy');
done();
});

// Uses rostopic to publish a message on the subscribed to topic.
var publishCommand = 'rostopic'
+ ' pub'
+ ' /subscribe_example'
+ ' std_msgs/String'
+ ' howdy';
var child = exec(publishCommand, function(error, stdout, stderr) {
should.not.exist(error);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ master.registerPublisher = function(publisher, callback) {
, callerUri = publisher.callerUri
, callerId = getGraphResourceName(publisher.callerId)
, topicName = getGraphResourceName(publisher.topic)
, messageType = publisher.messageType.messageType
, messageType = publisher.messageType
, params = [callerId, topicName, messageType, callerUri]
, client = xmlrpc.createClient(masterUri)
;
Expand All @@ -25,7 +25,7 @@ master.registerSubscriber = function(subscriber, callback) {
, callerUri = subscriber.callerUri
, callerId = getGraphResourceName(subscriber.callerId)
, topicName = getGraphResourceName(subscriber.topic)
, messageType = subscriber.messageType.messageType
, messageType = subscriber.messageType
, params = [callerId, topicName, messageType, callerUri]
, client = xmlrpc.createClient(masterUri)
;
Expand Down
170 changes: 0 additions & 170 deletions lib/node.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/ros.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var node = require('./node')
var topic = require('./topic')
, messages = require('./messages')
;

var ros = exports;
ros.node = node;
ros.topic = topic;

ros.types = function(types, callback) {
var that = this;
Expand Down
Loading

0 comments on commit 6839c1d

Please sign in to comment.