npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ros2nodejs

v0.1.0

Published

ROS 2 Library for Node.js

Downloads

2

Readme

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