Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    rosnodejspublic

    rosnodejs Build Status

    Install

    npm install rosnodejs

    Start a node

    const rosnodejs = require('rosnodejs');
    rosnodejs.initNode('/my_node')
    .then(() => {
      // do stuff
    });
    

    Publish/Subscribe

    const nh = rosnodejs.nh;
    const sub = nh.subscribe('/chatter', 'std_msgs/String', (msg) => {
      console.log('Got msg on chatter: %j', msg);
    });
    
    const pub = nh.advertise('/chatter', 'std_msgs/String');
    pub.publish({ data: "hi" });
    

    Services

    const service = nh.advertiseService('/add_two_ints', 'beginner_tutorials/AddTwoInts', (req, resp) => {
      res.sum = req.a + req.b;
      return true;
    });
    
    const client = nh.serviceClient('/add_two_ints', 'beginner_tutorials/AddTwoInts');
    client.call({a: 1, b: 2});
    

    Params

    nh.setParam('val', 2);
    nh.getParam('val')
    .then((val) => {
      // do stuff
    });
    

    Messages

    const sensorMsgs = rosnodejs.require('sensor_msgs');
    
    const image = new sensorMsgs.msg.Image();
    const temperature = new sensorMsgs.msg.Temperature({ temperature: 32 });
    
    const SetCameraInfo = sensorMsgs.srv.SetCameraInfo;
    const setRequest = new SetCameraInfo.Request();
    
    // messages can be used when advertising/subscribing
    const StringMsg = rosnodejs.require('std_msgs').msg.String;
    const sub = nh.subscribe('/chatter', StringMsg, (msg) => { ... });
    const pub = nh.advertise('/chatter', StringMsg);
    
    const AddTwoInts = rosnodejs.require('beginner_tutorials').srv.AddTwoInts;
    const service = nh.advertiseService('/add_two_ints', AddTwoInts, (req, resp) => { ... });
    const client = nh.serviceClient('/add_two_ints', AddTwoInts);
    

    Actions (Experimental)

    const nh = rosnodejs.nh;
    const as = new rosnodejs.ActionServer({
      nh,
      type: 'turtle_actionlib/ShapeAction',
      actionServer: '/turtle_shape'
    });
    
    as.on('goal, function (goal) {
      goal.setAccepted();
    });
    
    const ac = nh.actionClientInterface('/turtle_shape, 'turtle_actionlib/ShapeAction');
    ac.sendGoal({ goal: {edges: 3, radius: 1}});
    

    Run the turtlesim example

    Start:

    roscore
    rosrun turtlesim turtlesim_node
    rosrun turtle_actionlib shape_server
    

    Then run

    node src/examples/turtle.js
    

    or, if you are running an older version of node:

    npm run compile
    node dist/examples/turtle.js
    

    Catkin-Like

    Checkout rosnodejs_examples for a more catkin-inspired take on using rosnodejs.

    Inspired By

    rosnodejs was inspired by other work that you can learn more about here

    Keywords

    install

    npm i rosnodejs

    Downloadsweekly downloads

    194

    version

    2.2.0

    license

    Apache-2.0

    repository

    github.com

    last publish

    collaborators

    • avatar
    • avatar