Publishing/Subscribing msg type Topics
Main Sheet Configuration
- Required Modules
- RosNodeGenerator
- LOOP0 (This appears after you create iterator sheet.)
RosNodeGenerator
- Module Description
This module generates a ROS node with a specific node name defined by NODE_NAME property.
Since ROS allows single node generation for single process, DO NOT put this node more than two in the same HARK network file.
- Module Location
Node list > HARK:ROS:Master > RosNodeGenerator
- Property settings
Name | Type | Value | Explanation |
---|---|---|---|
NODE_NAME | string | HARK_MASTER_NODE | ROS node name for this network file. |
HARK_MASTER_NODE is just an example. You can give any preferred ROS node name.
- Terminal settings
Set “VALUE” for this output.
LOOP0
Set “OUTPUT1” and “OUTPUT1_2” for this outputs after iterator sheet configuration.
Iterator Sheet Configuration
- Required Modules
- Sleep
- RosHarkIntPublisher
- RosHarkIntSubscriber
Sleep
- Module Description
This module outputs true with a certain sleep time.
- Module Location
Node list > Flow > Sleep
- Property settings
Name | Type | Value | Explanation |
---|---|---|---|
SECONDS | float | 2 | Interval sleep time to output TRUE. |
- Terminal settings
Set “CONDITION” for this output. Then, this whole network file runs with a sampling time of the sleep time.
RosHarkIntPublisher
- Module Description
This module publishes a HarkInt type (contains just an integer) topic.
The value of the integer is determined as “count + PARAM”.
- Module Location
Node list > HARK:ROS:Sample > RosHarkIntPublisher
- Property settings
Name | Type | Value | Explanation |
---|---|---|---|
TOPIC_NAME | string | HarkInt1 | Published ROS Topic Name |
BUFFER_NUM | int | 100 | Number of buffers for published messages. |
PARAM | int | 0 | Output integer setting |
- Terminal settings
Set “OUTPUT1” for this output.
RosHarkIntSubscriber
- Module Description
This module subscribes a HarkInt type (contains just an integer) ROS topic.
It displays and outputs the integer.
- Module Location
Node list > HARK:ROS:Sample > RosHarkIntSubscriber
- Property settings
Name | Type | Value | Explanation |
---|---|---|---|
TOPIC_NAME | string | HarkInt1 | Subscribed ROS Topic Name |
BUFFER_NUM | int | 100 | Number of buffers for subscribed messages. |
ROS_DURATION | float | 0.001 | Minimum interval of ROS topic subscription. |
ROS_DURATION is only valid if the ROS_DURATION is longer than HARK interval.
Set ROS_DURATION small value so that HARK can work with desired interval.
- Terminal settings
Set “OUTPUT1_2” for this output.
Examining the network file
Save the network file before closing [e.g.) RosHarkInt_Publisher_and_Subscriber.n ]
Open a new terminal and type
roscore
Go back to the previous terminal and run the HARK network file
./RosHarkInt_Publisher_and_Subscriber.n
You’ll see something like following.
node_RosHarkIntPublisher_1 constructor end... node_RosHarkIntSubscriber_1 constructor end... ROS node : HarkRosMasterNode generated... node_RosHarkIntPublisher_1 initialized... node_RosHarkIntSubscriber_1 initialized... ROS initialized... <Int 0 > node_RosHarkIntPublisher_1 Published : [0] node_RosHarkIntSubscriber_1 Subscribed : [0] [ INFO] [1289788809.709227278]: Received [0] [thread=0x8ecd528] node_RosHarkIntPublisher_1 Published : [1] node_RosHarkIntSubscriber_1 Subscribed : [0] [ INFO] [1289788809.874858947]: Received [1] [thread=0x8ecd528] node_RosHarkIntPublisher_1 Published : [2] node_RosHarkIntSubscriber_1 Subscribed : [1] [ INFO] [1289788810.048147291]: Received [2] [thread=0x8ecd528]
If you see some ROS related errors in the standard output, type
. ~/ros/setup.sh
on your terminal to refresh ROS related environmental variable settings.
Now, let us check how the ROS system sees the HARK network by rqt_graph.
rosrun rqt_graph rqt_graph
You can see that the HARK network file successfully creates the HARK_MASTER_NODE node.
Also, the HarkInt1 topic is published/subscribed by the node.