7.26-rosbridge-suit 解读

ROS程序与非ROS程序沟通

TOC

参考

rosbridge_suit
rosbridge v2.0 Protocol Specification
WebSocket 特点与应用
LabVIEW TCP Write JSON
LabVIEW websocket client
client
rosbridge 原理及应用

学习记录

rosbridge_suit

  • 这个工具包提供JSON API供非ROS程序使用,有很多前端可以使用,包括WebSocket Server。
  • 任何环境,只要能够发送JSON协议数据且符合rosbridge传输协议
  • 注意,JSON协议和TCP,HTTP不在一个层次上,JSON是一种数据规约,规定发送的数据应该具有何种格式,可以说,JSON处在OSI七层标准协议的表示层。

WebSocket Json API是啥

  • websocket是一种在单个TCP连接上进行全双工通讯的协议。将套接字引入网络。
  • 通俗的讲,就是通过浏览器运行程序,在B/S架构下与本地运行的软件进行通讯,完成套接字的相关功能。

rosbridge2.0协议规约

  • rosbridge消息的传输层是JSON对象,仅仅需要的字段是'op'字段,表示消息的操作(operation),而整个协议就是'op'codes的集合,再加上每一个操作的语义。

传输层

  • 一个消息就是一个JSON对象,类似于下面的键值对:
{“op”: "Example" }
  • 请注意,依然能够提供任意的字符串键值对,如
{"op": “Example”
    "id": "fred"
}

但是请注意,"id"键可能并没有任何释义,但是在服务端可以被设计为一个特定的含义。

协议规约主要分类

  • 消息压缩和转换
    • fragment - 分段消息的一个部分
    • png - 图片分段消息的一个部分
  • 状态消息
    • set_status_level - 设置状态消息报告等级的一个请求消息
    • status - 一个状态消息
  • 确认消息
    • auth - 确认或者授权客户端的连接
  • ROS消息

ROS消息详细介绍

  • 注册(Advertise)

3.4.1 Advertise ( advertise )

If you wish to advertise that you are or will be publishing a topic, then use the advertise command.

{ "op": "advertise",  (optional) "id": <string>,  "topic": <string>,  "type": <string> } 
  • topic – the string name of the topic to advertise
  • type – the string type to advertise for the topic
  • If the topic does not already exist, and the type specified is a valid type, then the topic will be established with this type.
  • If the topic already exists with a different type, an error status message is sent and this message is dropped
  • If the topic already exists with the same type, the sender of this message is registered as another publisher.
  • If the topic doesnt already exist but the type cannot be resolved, then an error status message is sent and this message is dropped.

3.4.2 Unadvertise ( unadvertise ) This stops advertising that you are publishing a topic.

{ "op": "unadvertise",  (optional) "id": <string>,  "topic": <string> } 
  • topic – the string name of the topic being unadvertised
  • If the topic does not exist, a warning status message is sent and this message is dropped
  • If the topic exists and there are still clients left advertising it, rosbridge will continue to advertise it until all of them have unadvertised
  • If the topic exists but rosbridge is not advertising it, a warning status message is sent and this message is dropped

3.4.3 Publish ( publish )

The publish message is used to send data on a topic.

 { "op": "publish",  (optional) "id": <string>,  "topic": <string>,  "msg": <json> }

The publish command publishes a message on a topic.

  • topic - the string name of the topic to publish to
  • msg - the message to publish on the topic
  • If the topic does not exist, then an error status message is sent and this message is dropped
  • If the msg does not conform to the type of the topic, then an error status message is sent and this message is dropped
  • If the msg is a subset of the type of the topic, then a warning status message is sent and the unspecified fields are filled in with defaults Special case: if the type being published has a 'header' field, then the client can optionally omit the header from the msg. If this happens, rosbridge will automatically populate the header with a frame id of "" and the timestamp as the current time. Alternatively, just the timestamp field can be omitted, and then the current time will be automatically inserted.

3.4.4 Subscribe

 { "op": "subscribe",  (optional) "id": <string>,  "topic": <string>,  (optional) "type": <string>,  (optional) "throttle_rate": <int>,  (optional) "queue_length": <int>,  (optional) "fragment_size": <int>,  (optional) "compression": <string> }

This command subscribes the client to the specified topic. It is recommended that if the client has multiple components subscribing to the same topic, that each component makes its own subscription request providing an ID. That way, each can individually unsubscribe and rosbridge can select the correct rate at which to send messages.

  • type – the (expected) type of the topic to subscribe to. If left off, type will be inferred, and if the topic doesn't exist then the command to subscribe will fail
  • topic – the name of the topic to subscribe to
  • throttle_rate – the minimum amount of time (in ms) that must elapse between messages being sent. Defaults to 0
  • queue_length – the size of the queue to buffer messages. Messages are buffered as a result of the throttle_rate. Defaults to 1.
  • id – if specified, then this specific subscription can be unsubscribed by referencing the ID.
  • fragment_size – the maximum size that a message can take before it is to be fragmented.
  • compression – an optional string to specify the compression scheme to be used on messages. Valid values are "none" and "png" If queue_length is specified, then messages are placed into the queue before being sent. Messages are sent from the head of the queue. If the queue gets full, the oldest message is removed and replaced by the newest message. If a client has multiple subscriptions to the same topic, then messages are sent at the lowest throttle_rate, with the lowest fragmentation size, and highest queue_length. It is recommended that the client provides IDs for its subscriptions, to enable rosbridge to effectively choose the appropriate fragmentation size and publishing rate.

3.4.5 Unsubscribe

 { "op": "unsubscribe",  (optional) "id": <string>,  "topic": <string> } 
  • topic – the name of the topic to unsubscribe from
  • id – an id of the subscription to unsubscribe If an id is provided, then only the corresponding subscription is unsubscribed. If no ID is provided, then all subscriptions are unsubscribed.

3.4.6 Call Service

{ "op": "call_service",  (optional) "id": <string>,  "service": <string>,  (optional) "args": <list<json>>,  (optional) "fragment_size": <int>,  (optional) "compression": <string> } 

Calls a ROS service

  • service – the name of the service to call
  • args – if the service has no args, then args does not have to be provided, though an empty list is equally acceptable. Args should be a list of json objects representing the arguments to the service
  • id – an optional id to distinguish this service call
  • fragment_size – the maximum size that the response message can take before it is fragmented
  • compression – an optional string to specify the compression scheme to be used on messages. Valid values are "none" and "png"

3.4.7 Advertise Service

{ "op": "advertise_service",  "type": <string>,  "service": <string> } 

Advertises an external ROS service server. Requests come to the client via Call Service.

  • service – the name of the service to advertise
  • type – the advertised service message type

3.4.8 Unadvertise Service

 { "op": "unadvertise_service",  "service": <string> } 

Stops advertising an external ROS service server

  • service – the name of the service to unadvertise

3.4.9 Service Response

{ "op": "service_response",  (optional) "id": <string>,  "service": <string>,  (optional) "values": <list<json>>,  "result": <boolean> } 

A response to a ROS service call

  • service – the name of the service that was called
  • values – the return values. If the service had no return values, then this field can be omitted (and will be by the rosbridge server)
  • id – if an ID was provided to the service request, then the service response will contain the ID
  • result - return value of service callback. true means success, false failure.

rosbridge server implementation

  • 给出服务端的实现细节是为了方便修改协议

LabVIEW JSON TCP

  • LabVIEW2014拥有“簇平化至JSON字符串”以及“从JSON恢复”vi函数,可以完成上述需求,我虽然也找到一些JSON插件,但是貌似没有使用的必要,都是比较老的库,新版本的LV已经包含了这一功能

rosbridge-suit使用

安装

sudo apt-get install ros-indigo-rosbridge-suit

运行tcp服务端

rosrun rosbridge_server rosbridge_tcp
rqt_graph

猜你喜欢

转载自www.cnblogs.com/lizhensheng/p/11117602.html