Commit da93ba08 authored by Mathias Haage's avatar Mathias Haage
Browse files


parent ed952429
......@@ -269,6 +269,10 @@ Response initial_result_1=yes
##### Adding new dispatch function
A dispatch function signature takes one parameter, a python dictionary called *context* as input and returns another dictionary called *reply*.
The *context* contains the data from the statemachine comma-separated action string as key-value pairs. An important key is *xml_file* which if present contains the absolute path to a keyframe xml file. If the *xml_file* is present, the dispatcher has automatically loaded the contents of the file into a XML DOM object available as key *xml_dom*. The DOM object can be queried using xpath as shown below. Another important keys are *result_name* and *result_values* which contains the name of the expected (from a statemachine perspective) return value and the allowed return values as a semicolon-separated list of values. In the example below the reply dictionary is populated with one entry containing the result variable as key and the first of the allowed return values as value.
def identifyobjects(context):
print("Calling identifyobjects")
......@@ -299,6 +303,10 @@ def identifyobjects(context):
return reply
Before the function can be called it need to be registered in the *fmap* structure. It maps a name to a function. The name is what will be called from the statemachine action string, i.e. `call=name`.
fmap = []
fmap += [("addtwoints", addtwoints)]
......@@ -314,6 +322,9 @@ fmap += [("folding_retract", retract)]
registry = dict(fmap)
Below is an example of how to call a ROS service from within a function. In order for the dispatchservice to recognize srv-files from other services it will be needed to change the CMakeLists.txt, package.xml and/or update the srv folder of the grafchart_utils package, followed by a catkin_make.
def addtwoints(context):
reply = {}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment