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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM