D4 – ROSjava – Publisher – Subscriber

This first demo shows network with two ROS nodes: Publisher and Subscriber. This demo demonstrates connecting two ROS nodes in Nengo and shielding their communication from the rest of the ROS network.

Normally, the publisher periodically generates vector of 7 random float values and publishes on a given topic. The Subscriber subscribes to the same topic and starts receiving the messages.

Starting the Script

In order to run this demo, start the following in the Nengo GUI:


run nr-demo/basic/pubsub.py

This script does the following:

  • For each ROS node creates own Neural Module
  • Given Neural Modules are set to “independent”, this means that the Nengoros generates unique ROS namespace for them. Running Publisher and Subscriber ROS nodes in own namespaces ensures that ROS messages are not sent over the ROS network between them.
  • Adds output/input for publisher/subscriber node
  • Connect these two in the Nengo simulator

pubsubA

ROS Network

From the ROS Graph visualization we can see that each ROS node is pushed into the namespace shared only with its modem, so the communication is not passed directly over the ROS network.

pubsub

Launching the Simulation

Notice that ROS nodes are started after adding them into the Nengo GUI, so the Publisher already generates and publishes messages. Subscriber is already subscribed, but ROS messages are not received, because is in a different namespace than the Publisher.

After starting the interactive simulation, it can be seen from console that communication between nodes started and the Subscriber receives messages.

pubsubB

Note that this demo uses asynchronous communication: it can be seen that Nengo updates values on (Subscribers) encoder faster than the Publisher publishes new messages, so the Subscriber receives the same message several times, until the a one is received from the Publisher.

Advertisements