baalexander/rosnodejs — Issue #21: (API impromvent proposal) The code I would have like to write to move my turtle in turtlesim
Author: temsa
Created: 2012-02-28 09:01:28+00:00
State: open

The original code is in #20

```javascript
var ros = require('rosnodejs'),
Velocity = ros.message('turtlesim/Velocity'); // if no callback is passed as a second argument, then run it in synchronous mode

// first argument can be an object like current api, but if a string, it will just be the name
ros.createNode('turtlenode' , function(err) {
//'this' is a reference to the created node
if(err)
return console.error(err);

//Velocity is still an object which is able to auto-instantiate if not an instance of the Velocity object yet.
// we may want to add an optional callback below as a third argument, to know when it has been sent, but generally we just won't care at all, we could even listen for the event we just created instead

this.emit('turtle1/command_velocity', Velocity({ linear: 1.0, angular: 1.0 }));
})
.on('error', console.error)

// not in the code above, but would be powerful too
//creates the topic /turtlenode/hello and registers a callback for it
.on('turtlenode/hello', function(name) {console.log('hello, ', name)})
```