can't subscribe the message via rosbridge (websocket)
Hello,
I want to display the turtlesim_node's topic("/turtle1/cmd_vel") by using rosbridge.
to this end, I implement the following 3 codes.
[websocket.py]
#!/usr/bin/env python
import rospy, os
import SimpleHTTPServer
def kill():
os.system("kill -KILL " + str(os.getpid()))
os.chdir(os.path.dirname(__file__) + "/../contents")
rospy.init_node("webserver")
rospy.on_shutdown(kill)
SimpleHTTPServer.test()
[index.html]
<!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:9000'
});
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.');
});
// Subscribing to a Topic
// ----------------------
var listener = new ROSLIB.Topic({
ros : ros,
name :'/turtle1/cmd_vel',
messageType :'geometry_msgs/Twist'
});
listener.subscribe(function(message) {
console.log('Received message on ' + listener.name + ': ' + message.data);
value1=message.data;
});
</script>
</head>
<body>
<h1>Simple roslib Example</h1>
<p>Check your Web Console for output.</p>
</body>
</html>
[webtopic_turtle.launch]
<launch>
<node pkg="webtopic_turtle" name="webserver" type="webserver.py" args="8000" />
<include file="$(find rosbridge_server)/launch/rosbridge_websocket.launch">
<arg name="port" value="9000"/>
</include>
</launch>
After that , I executed catkin_make and "chmod +x webserver.py" in proper directory.
Finally, I executed the following command.
(1)roscore (2)roslanch webtopic_turtle webtopic_turtle.launch (3)open http://localhost:8000/ then the message is appeared in terminal that is executed webtopic_turtle.
[INFO] [WallTime: 1506767932.089070] Rosbridge WebSocket server started on port 9000 127.0.0.1 - - [30/Sep/2017 19:38:55] "GET / HTTP/1.1" 200 - [INFO] [WallTime: 1506767935.992950] Client connected. 1 clients total. [INFO] [WallTime: 1506767936.406980] [Client 0] Subscribed to /turtle1/cmd_vel
(4) rosrun turtlesim tutlesim_node (5)rosrun turtlesim turtleteleop_key
But, it is not display the message'Received message on …' in terminal that is executed webtopic_turtle. what is the problem ? I confirm the rqt_garph and it showed the diagram that is properly subscribed the message"/turtle1/cmd_vel" in rosbrideg_websocket.
Please let me know if you can find how to resolve the problem.