赞
踩
sudo apt-get install ros-<rosdistro>-rosbridge-suite
cd catkin_ws/src
git clone -b ros1 https://github.com/RobotWebTools/rosbridge_suite.git
cd catkin_ws
rosdep update
rosdep install --from-paths src --ignore-src -r
catkin build#或catkin_make
<launch> <arg name="port" default="9091" /> <arg name="address" default="127.0.0.1" /><!--修改IP和端口地址--> <arg name="ssl" default="false" /> <arg name="certfile" default=""/> <arg name="keyfile" default="" /> <arg name="retry_startup_delay" default="5" /> <arg name="fragment_timeout" default="600" /> <arg name="delay_between_messages" default="0" /> <arg name="max_message_size" default="None" /> <arg name="unregister_timeout" default="10" /> <arg name="websocket_external_port" default="None" /> <arg name="use_compression" default="false" /> <arg name="authenticate" default="false" /> <arg name="websocket_ping_interval" default="0" /> <arg name="websocket_ping_timeout" default="30" /> <arg name="websocket_null_origin" default="true" /> <arg name="topics_glob" default="[*]" /> <arg name="services_glob" default="[*]" /> <arg name="params_glob" default="[*]" /> <arg name="bson_only_mode" default="false" /> <!-- Output: screen, log --> <arg name="output" default="screen" /> <!-- Valid options for binary_encoder are "default", "b64" and "bson". --> <arg unless="$(arg bson_only_mode)" name="binary_encoder" default="default"/> <group if="$(arg ssl)"> <node name="rosbridge_websocket" pkg="rosbridge_server" type="rosbridge_websocket" output="$(arg output)"> <param name="certfile" value="$(arg certfile)" /> <param name="keyfile" value="$(arg keyfile)" /> <param name="authenticate" value="$(arg authenticate)" /> <param name="port" value="$(arg port)"/> <param name="address" value="$(arg address)"/> <param name="retry_startup_delay" value="$(arg retry_startup_delay)"/> <param name="fragment_timeout" value="$(arg fragment_timeout)"/> <param name="delay_between_messages" value="$(arg delay_between_messages)"/> <param name="max_message_size" value="$(arg max_message_size)"/> <param name="unregister_timeout" value="$(arg unregister_timeout)"/> <param name="use_compression" value="$(arg use_compression)"/> <param name="websocket_ping_interval" value="$(arg websocket_ping_interval)" /> <param name="websocket_ping_timeout" value="$(arg websocket_ping_timeout)" /> <param name="websocket_external_port" value="$(arg websocket_external_port)" /> <param name="websocket_null_origin" value="$(arg websocket_null_origin)" /> <param name="topics_glob" value="$(arg topics_glob)"/> <param name="services_glob" value="$(arg services_glob)"/> <param name="params_glob" value="$(arg params_glob)"/> </node> </group> <group unless="$(arg ssl)"> <node name="rosbridge_websocket" pkg="rosbridge_server" type="rosbridge_websocket" output="$(arg output)"> <param name="authenticate" value="$(arg authenticate)" /> <param name="port" value="$(arg port)"/> <param name="address" value="$(arg address)"/> <param name="retry_startup_delay" value="$(arg retry_startup_delay)"/> <param name="fragment_timeout" value="$(arg fragment_timeout)"/> <param name="delay_between_messages" value="$(arg delay_between_messages)"/> <param name="max_message_size" value="$(arg max_message_size)"/> <param name="unregister_timeout" value="$(arg unregister_timeout)"/> <param name="use_compression" value="$(arg use_compression)"/> <param name="websocket_ping_interval" value="$(arg websocket_ping_interval)" /> <param name="websocket_ping_timeout" value="$(arg websocket_ping_timeout)" /> <param name="websocket_external_port" value="$(arg websocket_external_port)" /> <param name="topics_glob" value="$(arg topics_glob)"/> <param name="services_glob" value="$(arg services_glob)"/> <param name="params_glob" value="$(arg params_glob)"/> <param name="bson_only_mode" value="$(arg bson_only_mode)"/> </node> </group> <node name="rosapi" pkg="rosapi" type="rosapi_node" output="$(arg output)"> <param name="topics_glob" value="$(arg topics_glob)"/> <param name="services_glob" value="$(arg services_glob)"/> <param name="params_glob" value="$(arg params_glob)"/> </node> </launch>
html页面示例如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script type="text/javascript" src="./html_ros/EventEmitter2/lib/eventemitter2.js"></script> <script type="text/javascript" src="./html_ros/roslib.min.js_1.1.0/cdnjs/roslib.min.js"></script> <script type="text/javascript" type="text/javascript"> // Connecting to ROS var ros = new ROSLIB.Ros({ url : 'ws://localhost:9091' }); //判断是否连接成功并输出相应的提示消息到web控制台 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.'); }); // Publishing a Topic var cmdVel = new ROSLIB.Topic({ ros : ros, name : '/cmd_vel', messageType : 'geometry_msgs/Twist' });//创建一个topic,它的名字是'/cmd_vel',,消息类型是'geometry_msgs/Twist' var twist = new ROSLIB.Message({ linear : { x : 0.1, y : 0.2, z : 0.3 }, angular : { x : -0.1, y : -0.2, z : -0.3 } });//创建一个message function func()//在点击”Publish”按钮后发布消息,并对消息进行更改 { cmdVel.publish(twist);//发布twist消息 twist.linear.x = twist.linear.x + 0.1; twist.linear.y = twist.linear.y + 0.1; twist.linear.z = twist.linear.z + 0.1; twist.angular.x = twist.angular.x + 0.1; twist.angular.y = twist.angular.y + 0.1; twist.angular.z = twist.angular.z + 0.1; } // Subscribing to a Topic var listener = new ROSLIB.Topic({ ros : ros, name : '/test', messageType : 'sensor_msgs/PointCloud2' });//创建一个topic,它的名字是'/chatter',,消息类型是'std_msgs/String' function subscribe()//在点击”Subscribe”按钮后订阅'/chatter'的消息,并将其显示到网页中 { listener.subscribe(function(message) { document.getElementById("output").innerHTML = ('Received message on ' + listener.name + ': ' + message.data); }); } function unsubscribe()//在点击”Unsubscribe”按钮后取消订阅'/chatter'的消息 { listener.unsubscribe(); } </script> </head> <body> <h1>Simple roslib Example</h1> <p>Check your Web Console for output.</p> <p id = "output"></p> <button onclick = "func()">Publish</button> <button onclick = "subscribe()">Subscribe</button> <button onclick = "unsubscribe()">Unsubscribe</button><br /> </body>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。