Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rosnodejs

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rosnodejs

Native ROS for nodejs

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
decreased by-12.97%
Maintainers
3
Weekly downloads
 
Created
Source

rosnodejs Build Status

Install

npm install rosnodejs

Start a node

const rosnodejs = require('rosnodejs');
rosnodejs.initNode('/my_node')
.then(() => {
  // do stuff
});

Publish/Subscribe

const nh = rosnodejs.nh;
const sub = nh.subscribe('/chatter', 'std_msgs/String', (msg) => {
  console.log('Got msg on chatter: %j', msg);
});

const pub = nh.advertise('/chatter', 'std_msgs/String');
pub.publish({ data: "hi" });

Udp transport (Experimental)

const nh = rosnodejs.nh;
const sub = nh.subscribe('/chatter', 'std_msgs/String', (msg) => {
  console.log('Got msg on chatter: %j', msg);
}, {
  transports: ["TCPROS", "UDPROS"],  // specify transports, default ["TCPROS"]
  dgramSize: 1500   // optional: datagram packet size, default: 1500 bytes
});

const pub = nh.advertise('/chatter', 'std_msgs/String');
pub.publish({ data: "hi" });

Services

const service = nh.advertiseService('/add_two_ints', 'beginner_tutorials/AddTwoInts', (req, res) => {
  res.sum = req.a + req.b;
  return true;
});

const client = nh.serviceClient('/add_two_ints', 'beginner_tutorials/AddTwoInts');
client.call({a: 1, b: 2});

Params

nh.setParam('val', 2);
nh.getParam('val')
.then((val) => {
  // do stuff
});

Generating Messages

Messages can be generated in a number of ways depending on the versions of ROS and Node.js you're using.

  • catkin - works in ROS Kinetic and later for Node.js v6+.
$ catkin_make
OR
$ catkin build
  • loadAllPackages() - One-time "build" call available through rosnodejs for versions of ROS before Kinetic and Node.js v6+. Should be called separately and in advance of processes attempting to use messages.
const rosnodejs = require('rosnodejs');
rosnodejs.loadAllPackages();
  • On the fly - all versions of ROS and Node.js 4.5+. When generating on the fly, messages can not be required until the node has initialized.
const rosnodejs = require('rosnodejs');
rosnodejs.initNode('my_node', { onTheFly: true }).then(() => {
  const stdMsgs = rosnodejs.require('std_msgs');
  ...
}
Pre-KineticKinetic & Later
Node.js >= v6loadAllPackages(), on the flycatkin, loadAllPackages(), on the fly
Node.js < v6on the flyon the fly

Using Messages

const sensorMsgs = rosnodejs.require('sensor_msgs');

const image = new sensorMsgs.msg.Image();
const temperature = new sensorMsgs.msg.Temperature({ temperature: 32 });

const SetCameraInfo = sensorMsgs.srv.SetCameraInfo;
const setRequest = new SetCameraInfo.Request();

// messages can be used when advertising/subscribing
const nh = rosnodejs.nh;
const StringMsg = rosnodejs.require('std_msgs').msg.String;
const sub = nh.subscribe('/chatter', StringMsg, (msg) => { ... });
const pub = nh.advertise('/chatter', StringMsg);

const AddTwoInts = rosnodejs.require('beginner_tutorials').srv.AddTwoInts;
const service = nh.advertiseService('/add_two_ints', AddTwoInts, (req, res) => { ... });
const client = nh.serviceClient('/add_two_ints', AddTwoInts);

Actions (Experimental)

const nh = rosnodejs.nh;
const as = new rosnodejs.ActionServer({
  nh,
  type: 'turtle_actionlib/Shape',
  actionServer: '/turtle_shape'
});

as.on('goal', function (goal) {
  goal.setAccepted();
});

as.start();

const ac = new rosnodejs.ActionClient({
  nh,
  type: 'turtle_actionlib/Shape',
  actionServer:'/turtle_shape'
});

ac.sendGoal({edges: 3, radius: 1});

Run the turtlesim example

Start:

roscore
rosrun turtlesim turtlesim_node
rosrun turtle_actionlib shape_server

Then run

node src/examples/turtle.js

or, if you are running an older version of node:

npm run compile
node dist/examples/turtle.js

Catkin-Like

Checkout rosnodejs_examples for a more catkin-inspired take on using rosnodejs.

Inspired By

rosnodejs was inspired by other work that you can learn more about here

Keywords

FAQs

Package last updated on 06 Apr 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