npm

Check out our latest tech talk, "JavaScript Supply Chain Security" presented by VP of Security, Adam Baldwin.Watch it here »

rclnodejs

0.10.0 • Public • Published

rclnodejs Build Status

rclnodejs is a Node.js client for Robot Operating System (ROS) v2.0. It provides extremely simple & easy API for ROS 2.0 programming, the following example shows how to create a ROS 2.0 node and then publish a string message in only 6 lines of code.

const rclnodejs = require('rclnodejs');
rclnodejs.init().then(() => {
  const node = rclnodejs.createNode('publisher_example_node');
  const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
  publisher.publish(`Hello ROS 2.0 from rclnodejs`);
  rclnodejs.spin(node);
});

Install ROS 2.0

Before install rclnodejs, make sure ROS 2.0 is installed first. Read and follow the Installation Guide to install ROS 2.0

Install rclnodejs

After ROS 2.0 is installed, run the following command

npm i --save rclnodejs

Match with ROS 2.0 Stable Releases

Please check the table to select a specific version you want.

Document

Please browse our online doucment to learn the detailed usage if you needed.

More Examples

Use complex message

  const publisher = node.createPublisher('sensor_msgs/msg/JointState', 'topic');
  publisher.publish({
    header: {
      stamp: {
        sec: 123456,
        nanosec: 789,
      },
      frame_id: 'main frame',
    },
    name: ['Tom', 'Jerry'],
    position: [1, 2],
    velocity: [2, 3],
    effort: [4, 5, 6],
  });
 

Create a subscription

const rclnodejs = require('../index.js');
 
// Create a ROS node and then print out the string message received from publishers
rclnodejs.init().then(() => {
  const node = rclnodejs.createNode('subscription_example_node');
 
  node.createSubscription('std_msgs/msg/String', 'topic', (msg) => {
    console.log(`Received message: ${typeof msg}`, msg);
  });
 
  rclnodejs.spin(node);
});

Create a service

  node.createService('example_interfaces/srv/AddTwoInts', 'add_two_ints', (request, response) => {
    console.log(`Incoming request: ${typeof request}`, request);
    let result = response.template;
    result.sum = request.a + request.b;
    console.log(`Sending response: ${typeof result}`, result, '\n--');
    response.send(result);
  });
 

Send a request in a client

  const client = node.createClient('example_interfaces/srv/AddTwoInts', 'add_two_ints');
  const request = {
    a: Math.floor(Math.random() * 100),
    b: Math.floor(Math.random() * 100),
  };
 
  console.log(`Sending: ${typeof request}`, request);
  client.sendRequest(request, (response) => {
    console.log(`Result: ${typeof response}`, response);
  });
 

License

Apache License Version 2.0

install

npm i rclnodejs

Downloadsweekly downloads

128

version

0.10.0

license

Apache-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability