Skip to content

Commit 893774b

Browse files
authored
Update README.md
1 parent e415e03 commit 893774b

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,63 @@
11
# rosnodejs [![Build Status](https://travis-ci.org/RethinkRobotics-opensource/rosnodejs.svg)](https://travis-ci.org/RethinkRobotics-opensource/rosnodejs)
22

3+
## Start a node
4+
```
5+
const rosnodejs = require('rosnodejs');
6+
rosnodejs.initNode('/my_node')
7+
.then(() => {
8+
// do stuff
9+
});
10+
```
11+
12+
## Publish/Subscribe
13+
```
14+
const nh = rosnodejs.nh;
15+
const sub = nh.subscribe('/chatter', 'std_msgs/String', (msg) => {
16+
console.log('Got msg on chatter: %j', msg);
17+
});
18+
19+
const pub = nh.advertise('/chatter', 'std_msgs/String');
20+
pub.publish({ data: "hi" });
21+
```
22+
23+
## Services
24+
```
25+
const service = nh.advertiseService('/add_two_ints', 'beginner_tutorials/AddTwoInts', (req, resp) => {
26+
res.sum = req.a + req.b;
27+
return true;
28+
});
29+
30+
const client = nh.serviceClient('/add_two_ints', 'beginner_tutorials/AddTwoInts');
31+
client.call({a: 1, b: 2});
32+
```
33+
34+
## Params
35+
```
36+
nh.setParam('val', 2);
37+
nh.getParam('val')
38+
.then((val) => {
39+
// do stuff
40+
});
41+
```
42+
## Messages
43+
```
44+
const sensorMsgs = rosnodejs.require('sensor_msgs');
45+
46+
const image = new sensorMsgs.msg.Image();
47+
const temperature = new sensorMsgs.msg.Temperature({ temperature: 32 });
48+
49+
const SetCameraInfo = sensorMsgs.srv.SetCameraInfo;
50+
const setRequest = new SetCameraInfo.Request();
51+
52+
// messages can be used when advertising/subscribing
53+
const StringMsg = rosnodejs.require('std_msgs').msg.String;
54+
const sub = nh.subscribe('/chatter', StringMsg, (msg) => { ... });
55+
const pub = nh.advertise('/chatter', StringMsg);
56+
57+
const AddTwoInts = rosnodejs.require('beginner_tutorials').srv.AddTwoInts;
58+
const service = nh.advertiseService('/add_two_ints', AddTwoInts, (req, resp) => { ... });
59+
const client = nh.serviceClient('/add_two_ints', AddTwoInts);
60+
```
361

462
## Run the turtlesim example
563

@@ -22,3 +80,14 @@ or, if you are running an older version of node:
2280
npm run compile
2381
node dist/examples/turtle.js
2482
```
83+
84+
## Catkin-Like
85+
Checkout [`rosnodejs_examples`](https://github.com/RethinkRobotics-opensource/rosnodejs_examples) for a more catkin-inspired take on using `rosnodejs`.
86+
87+
## Inspired By
88+
`rosnodejs` was inspired by other work that you can learn more about here
89+
- [roscpp & rospy](https://github.com/ros/ros_comm)
90+
- [Robots as web services](http://ieeexplore.ieee.org/document/5980464/?tp=&arnumber=5980464&url=http:%2F%2Fieeexplore.ieee.org%2Fxpls%2Fabs_all.jsp%3Farnumber%3D5980464)
91+
- [ROSBridge](https://github.com/RobotWebTools/rosbridge_suite)
92+
- [roslibjs](https://github.com/RobotWebTools/roslibjs)
93+

0 commit comments

Comments
 (0)