koonpeng / rclnodejs

Node.js version of ROS 2.0 client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rclnodejs - ROS2 Client Library for JavaScript npmCoverage StatusnpmGitHub licensenodedependencies Statusnpm type definitionscode style: prettier

Branch Linux Build macOS Build Windows Build
develop Build Status macOS Build Status Build status
master Build Status macOS Build Status Build status

rclnodejs is a Node.js client library for the Robot Operating System (ROS 2). It provides a JavaScript API and TypeScript declarations for ROS 2 programming.

Here's an example for how to create a ROS 2 node that publishes a string message in a few lines of JavaScript.

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

Documentation

Installation

Prerequisites

Before installing rclnodejs please ensure the following softare is installed and configured on your systemd:

Installing rclnodejs

Install the rclnodejs version that is compatible with your version of ROS 2 (see table below).

For the most current version of rclnodejs run:

npm i rclnodejs

To install a specific version of rclnodejs use:

npm i rclnodejs@x.y.z
RCLNODEJS Version Compatible ROS 2 Release
0.18.0 (current) (API) Foxy Fitzroy / Eloquent Elusor
0.10.3 Dashing Diademata - Patch 4
  • Note: to install rclnodejs from GitHub: add "rclnodejs":"RobotWebTools/rclnodejs#<branch>" to your package.json depdendency section.

API Documentation

API documentation is generated by jsdoc and can be viewed in the docs/ folder or on-line. To create a local copy of the documentation run npm run docs.

Using TypeScript

rclnodejs API can be used in TypeScript projects. You can find the TypeScript declaration files (*.d.ts) in the types/ folder.

Your project tsconfig.json file should include the following compiler options:

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es6"
    // your additional options here
  }
}

Here's a short rclnodejs TypeScript example:

import * as rclnodejs from 'rclnodejs';
rclnodejs.init().then(() => {
  const node = new rclnodejs.Node('publisher_example_node');
  const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
  publisher.publish(`Hello ROS 2 from rclnodejs`);
  node.spin();
});

The benefits of using TypeScript become evident when working with more complex use-cases. The ROS 2 messages in your environment are defined in the types/interfaces.d.ts module. This module is updated as part of the generate-ros-messages process. Here's a trivial example of working with a String msg.

const msg: rclnodejs.std_msgs.msg.String = {
  data: 'hello ROS2 from rclnodejs',
};

Contributing

Please make sure to read the Contributing Guide before making a pull request.

Thank you to all the people who already contributed to rclnodejs!

License

This project abides by the Apache License 2.0.

About

Node.js version of ROS 2.0 client

License:Apache License 2.0


Languages

Language:JavaScript 71.2%Language:C++ 20.2%Language:Python 6.8%Language:TypeScript 1.2%Language:CMake 0.3%Language:Shell 0.2%Language:Dockerfile 0.2%