Requesting/Responding srv type Topics
Main Sheet Configuration
- Required Modules
- RosNodeGenerator
- LOOP0 (This appears after you create iterator sheet.)
RosNodeGenerator
All description is available at Publishing/Subscribing msg type Topics.
LOOP0
All description is available at Publishing/Subscribing msg type Topics.
Iterator Sheet Configuration
- Required Modules
- Sleep
- RosAddHarkIntServer
- RosAddHarkIntClient
Sleep
All description is available at Publishing/Subscribing msg type Topics.
RosAddHarkIntServer
- Module Description
This module subscribes a HarkIntSrv type request ROS topic and responds to it as a server.
HarkIntSrv.srv contains two integers (a and b) in the request field and one integer (result) in the response field.
RosAddHarkIntServer takes “a” and “b” from the client ROS node and returns “result = a + b” to the client.
As a HARK module, it outputs “result”.
- Module Location
Node list > HARK:ROS:Sample > RosAddHarkIntServer
- Property settings
Name | Type | Value | Explanation |
---|---|---|---|
TOPIC_NAME | string | HarkIntSrv1 | Subscribed ROS Topic Name |
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” for this output.
RosAddHarkIntClient
- Module Description
This module publishes a HarkIntSrv type request ROS topic as a client.
This modules fills “a = count” and “b = count + PARAM” in the request field of HarkIntSrv.srv and publishes it.
When it gets return from ROS service node, it starts to output the “result” as HARK module output.
- Module Location
Node list > HARK:ROS:Sample > RosAddHarkIntClient
- Property settings
Name | Type | Value | Explanation |
---|---|---|---|
TOPIC_NAME | string | HarkIntSrv1 | Published ROS Topic Name |
PARAM | int | 10 | Request parameter setting |
- Terminal settings
Set “OUTPUT1_2” for this output.
Examining the network file
Save the network file before closing [e.g.) RosAddHarkInt_Client_and_Service.n ]
Open a new terminal and type
roscore
Go back to the previous terminal and run the HARK network file
./RosAddHarkInt_Client_and_Service.n
You’ll see something like following.
node_RosAddHarkIntClient_1 constructor end... ROS node : HARK_MASTER_NODE generated... node_RosAddHarkIntClient_1 initialized... node_RosAddHarkIntServer_1 initialized... ROS initialized... <Int 0 > node_RosAddHarkIntServer_1 Output : [0] [ INFO] [1289790940.132554321]: Request [0 + 10 = 10] [thread=0xa07fe00] node_RosAddHarkIntClient_1 Published : [10] node_RosAddHarkIntServer_1 Output : [10] [ INFO] [1289790940.300574616]: Request [1 + 11 = 12] [thread=0xa07fe00] node_RosAddHarkIntClient_1 Published : [12] node_RosAddHarkIntServer_1 Output : [12]
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.
As seen in the standard output, the RosAddHarkIntClient publishes two values like “[0, 10]” or “[1, 11]”.
The RosAddHarkIntServer calculates “0 + 10” and “1 + 11” and returns to the RosAddHarkIntClient.
Finally, RosAddHarkIntClient successfully outputs “10” and “12” …