Accessor: robotics/RosPublisher

robotics/RosPublisher

This accessor advertises and publishes to a ROS topic. It extends the WebSocketClient to communicate to a rosbridge websocket.

During intialize, it will advertise the topic it will publish to, along with its type. The purpose of 'advertise' here is to establish the ROS topic if isn't already established. This is slightly different from the 'advertise' function in NodeHandle which simply publicizes that the the node will be publishing messages to the topic.

  • If the topic does not already exist, and the type is valid, a topic will be established with this type.
  • If the topic already exists with a different type, no new topic will be established
  • If the topic already exists with the same type, no new topic will be established.
  • If the topic already exists but the type isn't resolved, no new topic will be established.

On input from 'toSend', this accessor publishes that input to the aforementioned topic. The input from 'toSend' must be in JSON form, and must match the message datatype that the ROS topic is expecting. For example if ROS topic is expecting std_msgs/String, then the input in 'toSend' should be as follows:

 { "data": "hello world" } 
Some ROS types contain a header which consists of a sequence, timestamp, and a frame_id. If the ROS type has a header, you can either:
  • send the message on toSend without the header, and check the parameter 'addHeader'. This sends the message with a header with only the frame_id specified, and rosbridge will add the sequence and timestamp for you.
  • send a fully formed message with all fields in the header included and don't check the parameter 'addHeader'.
This accessor doesn't do any error checking. All error messages orginate from rosbridge and will appear on the console running rosbridge. More information ccan be viewed on the rosbridge protocol specification site.

Version:
  • $$Id$$
Author:
  • Marcus Pan
Source:
Parameters:
Name Type Description
topic string The ROS topic to publish to.
ROStype string The ROS datatype of the topic.
addHeader boolean If (true), this accessor will send a header with a blank seq and timestamp field, and rosbridge will add the header for you.
frame_id string The frame_id of the header (only needed if a header is required).

Methods

(static) initialize()

Inherits initialize from WebSocketClient. Advertise the topic we are publishing to.

Source:

(static) setup()

Sets up by accessor by inheriting inputs from setup() in WebSocketClient. Adds additional parameters regarding the ROS topic to which to publish to.

Source:

(static) toSendInputHandler()

Override inputHandler on 'toSend' from WebSocketClient.

Source:

(static) wrapup()

Unadvertise the topic and inherit wrapup from WebSocketClient.

Source: