Skip to content

Instantly share code, notes, and snippets.

@cfpperche2
Last active April 12, 2016 01:04
Show Gist options
  • Save cfpperche2/a9aeb73462e25e9327608f5a80bd4157 to your computer and use it in GitHub Desktop.
Save cfpperche2/a9aeb73462e25e9327608f5a80bd4157 to your computer and use it in GitHub Desktop.
roslibjs example
d
_conf: Object
_events: Object
event: "connection"
groovyCompatibility: false
idCounter: 5
isConnected: true
socket: WebSocket
__proto__: d
Connected to websocket server.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="http://cdn.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
<script type="text/javascript" src="http://cdn.robotwebtools.org/roslibjs/current/roslib.min.js"></script>
<script type="text/javascript" type="text/javascript">
// Connecting to ROS
// -----------------
var ros = new ROSLIB.Ros({
url : 'ws://localhost:9090',
groovyCompatibility: false,
});
console.dir(ros);
ros.on('connection', function() {
console.log('Connected to websocket server.');
});
ros.on('error', function(error) {
console.log('Error connecting to websocket server: ', error);
});
ros.on('close', function() {
console.log('Connection to websocket server closed.');
});
var listener = new ROSLIB.Topic({
ros : ros,
name : '/listener',
messageType : 'std_msgs/String'
});
listener.subscribe(function(message) {
console.log('Received message on ' + listener.name + ': ' + message.data);
listener.unsubscribe();
});
ros.getNodes(function(nodes) {
console.log(nodes);
});
ros.getTopics(function(topics) {
console.log(topics);
});
ros.getServices(function(services) {
console.log(services);
});
ros.getParams(function(params) {
console.log(params);
});
</script>
</head>
<body>
<h1>Simple roslib Example</h1>
<p>Check your Web Console for output.</p>
</body>
</html>
roslaunch rosbridge_server rosbridge_websocket.launch
# outpout
... logging to /home/vilma/.ros/log/fbe52fe6-0048-11e6-825b-240a64b68157/roslaunch-vilma-1951.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://vilma:45653/
SUMMARY
========
PARAMETERS
* /rosbridge_websocket/address:
* /rosbridge_websocket/authenticate: False
* /rosbridge_websocket/delay_between_messages: 0
* /rosbridge_websocket/fragment_timeout: 600
* /rosbridge_websocket/max_message_size: None
* /rosbridge_websocket/port: 9090
* /rosbridge_websocket/retry_startup_delay: 5
* /rosdistro: indigo
* /rosversion: 1.11.16
NODES
/
rosapi (rosapi/rosapi_node)
rosbridge_websocket (rosbridge_server/rosbridge_websocket)
auto-starting new master
process[master]: started with pid [1963]
ROS_MASTER_URI=http://localhost:11311
setting /run_id to fbe52fe6-0048-11e6-825b-240a64b68157
process[rosout-1]: started with pid [1976]
started core service [/rosout]
process[rosbridge_websocket-2]: started with pid [1979]
process[rosapi-3]: started with pid [1997]
registered capabilities (classes):
- rosbridge_library.capabilities.call_service.CallService
- rosbridge_library.capabilities.advertise.Advertise
- rosbridge_library.capabilities.publish.Publish
- rosbridge_library.capabilities.subscribe.Subscribe
- <class 'rosbridge_library.capabilities.defragmentation.Defragment'>
- rosbridge_library.capabilities.advertise_service.AdvertiseService
- rosbridge_library.capabilities.service_response.ServiceResponse
- rosbridge_library.capabilities.unadvertise_service.UnadvertiseService
[INFO] [WallTime: 1460422415.496561] Rosbridge WebSocket server started on port 9090
#when index.html is open in browser
[INFO] [WallTime: 1460422717.531417] Client connected. 1 clients total.
[INFO] [WallTime: 1460422717.720001] [Client 0] Subscribed to /listener
# from another terminal, I try to publish a topic to /listener, but browser console does not shows anything
rostopic pub /listener std_msgs/String "Hello, World"
publishing and latching message. Press ctrl-C to terminate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment