New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ros2nodejs

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ros2nodejs

ROS 2 Library for Node.js

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ROS 2 Library for Node.js

Node library for ROS 2. This is an experimental library and is not yet ready for production use.

This library is similar to roslibjs but with full support for ROS 2.

Installation

This is a Node.js module available through the npm registry. Before installing, download and install Node.js.

Installation is done using the npm install command:

$ npm install ros2nodejs

Features

ROS 2 Node.js library provides the following features:

Quick Start

Connect to rosbridge server:

import { Ros } from 'ros2nodejs';

const ros = new Ros('ws://localhost:9090');
ros.open();

Subscribe to a topic:

const topic = new Topic(ros, '/turtle1/pose', 'turtlesim/Pose');
topic.subscribe((message) => {
  console.log('Received message on ' + topic.name + ': ' + message);
});

Publish to a topic:

const topic = new Topic(ros, '/chatter', 'std_msgs/String');
topic.publish({message: 'Hello World!'});

Call a service:

const service = new Service(ros, '/spawn', 'turtlesim/Spawn');
service.callService({
    x: 2,
    y: 2,
    theta: 0.2,
    name: '',
}, (response: any) => {
    console.log(response);
}, (error: any) => {
    console.log(error);
});

Service server:

const service = new Service(ros, '/my_spawn', 'turtlesim/Spawn');
service.advertise((request: any, response: any) => {
    console.log('Received request on ' + service.name + ': ' + request);
    response.name = 'MyBot';
    return true;
});

Action client:

const action = new Action(ros, '/turtle1/rotate_absolute', 'turtlesim/RotateAbsolute');

Send goal

action.sendGoal({
    theta: 1.57,
}, (result: any) => {
    console.log('Result:', result);
}, (error: any) => {
    console.log('Error:', error);
}, (feedback: any) => {
    console.log('Feedback:', feedback);
});

Cancel goal

action.cancelGoal((result: any) => {
    console.log('Cancel result:', result);
});

Destroy action client

action.destroyClient();

Get parameter:

const param = new Param(ros, '/turtlesim:background_r');
param.get((value: any) => {
    console.log('Background red:', value);
});

Set parameter:

const param = new Param(ros, '/turtlesim:background_r');
param.set(255);

Examples

The examples available in the github repository are to be used with the ROS turtlesim package and the a modified rosbridge_server package.

In a machine with ROS 2 installed, run the following commands:

$ ros2 run turtlesim turtlesim_node

In another command prompt, run the following commands:

  • Install the modified rosbridge_server package:
$ cd ros2_ws/src
$ git clone https://github.com/lorenzinigiovanni/rosbridge_suite.git
  • build the package:
$ cd ros2_ws
$ colcon build
  • source the setup file:
$ source install/local_setup.bash
  • run the rosbridge_server:
$ ros2 launch rosbridge_server rosbridge_websocket_launch.xml

In the same machine or in another machine in the same network, run the following commands:

  • Install node.js and create a new project:
$ npm init
  • Install the ros2nodejs package:
$ npm install ros2nodejs
  • In a new file, copy the code from the example you want to try and run it.

People

This library is developed by:

License

MIT

Keywords

FAQs

Package last updated on 24 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc