
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
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.
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
ROS 2 Node.js library provides the following features:
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);
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:
rosbridge_server
package:$ cd ros2_ws/src
$ git clone https://github.com/lorenzinigiovanni/rosbridge_suite.git
$ cd ros2_ws
$ colcon build
$ source install/local_setup.bash
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:
$ npm init
ros2nodejs
package:$ npm install ros2nodejs
This library is developed by:
FAQs
ROS 2 Library for Node.js
The npm package ros2nodejs receives a total of 0 weekly downloads. As such, ros2nodejs popularity was classified as not popular.
We found that ros2nodejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.