Class: Topic

Topic(options)

new Topic(options)

Publish and/or subscribe to a topic in ROS.

Emits the following events:

  • 'warning' - If there are any warning during the Topic creation.
  • 'message' - The message data from rosbridge.
Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
ros Ros

The ROSLIB.Ros connection handle.

name string

The topic name, like '/cmd_vel'.

messageType string

The message type, like 'std_msgs/String'.

compression string <optional>
none

The type of compression to use, like 'png', 'cbor', or 'cbor-raw'.

throttle_rate number <optional>
0

The rate (in ms in between messages) at which to throttle the topics.

queue_size number <optional>
100

The queue created at bridge side for re-publishing webtopics.

latch boolean <optional>
false

Latch the topic when publishing.

queue_length number <optional>
0

The queue length at bridge side used when subscribing.

reconnect_on_close boolean <optional>
true

The flag to enable resubscription and readvertisement on close event.

Source:

Methods

Register as a publisher for the topic.

Source:

publish(message)

Publish the message.

Parameters:
Name Type Description
message Message

A ROSLIB.Message object.

Source:

subscribe(callback)

Every time a message is published for the given topic, the callback will be called with the message object.

Parameters:
Name Type Description
callback function

Function with the following params:

Properties
Name Type Description
message Object

The published message.

Source:

toStream(options)

Publish a connected ROS topic to a duplex stream. This stream can be piped to, which will publish to the topic.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
subscribe boolean <optional>
true

The flag to indicate whether to subscribe to the topic and start emitting data or not.

publish boolean <optional>
true

The flag to indicate whether to register the stream as a publisher to the topic or not.

transform boolean <optional>

A function to change the data to be published or filter it if false is returned.

Source:

unadvertise()

Unregister as a publisher for the topic.

Source:

unsubscribe(callbackopt)

Unregister as a subscriber for the topic. Unsubscribing will stop and remove all subscribe callbacks. To remove a callback, you must explicitly pass the callback function in.

Parameters:
Name Type Attributes Description
callback function <optional>

The callback to unregister, if provided and other listeners are registered the topic won't unsubscribe, just stop emitting to the passed listener.

Source: