Rosbridge Client 程序测试

标签 : roslibjs html

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();
  });```

```terminal
rostopic pub [topic] [msg_type] [args]
rostopic pub /listener std_msgs/String "Hello, World" ```
```terminal
roslaunch rosbridge_server rosbridge_websocket.launch```
往/listener这个topic发送消息后rqt显示的是对应下图中第二个方框。
launch文件启动的节点和topic对应一/三方框。
![rqt_graph_RosGraph.png](http://upload-images.jianshu.io/upload_images/3869738-e0f365927ea3a575.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
往**/listener**发布**hello,world**消息后,浏览器控制台输出如下图:
![listener.png](http://upload-images.jianshu.io/upload_images/3869738-afcd31fe273187bf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
笔记:
打开浏览器后,javascript得到运行。往/listener发布消息后,/listener调用订阅函数,控制台输出数据。
********
#####__测试二:__
终端启动模拟小乌龟:
```terminal
rosrun turtlesim turtlesim_node```
在web浏览器往话题上发布运动消息:
```roslibjs
var cmdVel = new ROSLIB.Topic({
    ros : ros,
    name : '/turtle1/cmd_vel',
    messageType : 'geometry_msgs/Twist'
  });

  var twist = new ROSLIB.Message({
    linear : {
      x : 2.0,
      y : 0.0,
      z : 0.0
    },
    angular : {
      x : 0.0,
      y : 0.0,
      z : 0.0
    }
  });```

![rqt_turtle.png](http://upload-images.jianshu.io/upload_images/3869738-a9960f2d9e59e323.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 137,418评论 19赞 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 181,039评论 25赞 708
  • Kafka入门经典教程-Kafka-about云开发 http://www.aboutyun.com/threa...
    葡萄喃喃呓语阅读 11,041评论 4赞 54
  • 从三月份找实习到现在,面了一些公司,挂了不少,但最终还是拿到小米、百度、阿里、京东、新浪、CVTE、乐视家的研发岗...
    时芥蓝阅读 43,094评论 11赞 349
  • 什么是曼陀罗
    云开无照阅读 331评论 0赞 0

友情链接更多精彩内容