当前位置:   article > 正文

ros_bridge 使用_swarm_ros_bridge如何使用

swarm_ros_bridge如何使用

ros_bridge 使用教程

安装

二进制安装

sudo apt-get install ros-<rosdistro>-rosbridge-suite
  • 1

源码安装

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

修改rosbridge_websocket.launch文件

<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

websocket接收

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>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76

其中eventemitter2.js可以在<github下载>,roslib.min.js可以在此<下载>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/491202
推荐阅读
相关标签
  

闽ICP备14008679号