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

Update README

parent 5871467b
......@@ -180,13 +180,150 @@ For most of the scripts to run correctly a *roscore* need to be started.
### testservice1.py and testservice2.py
### testservice1.py and testclient1.py
Two testservices
A testservice
#### Sample usage
Can be started through
`rosrun grafchart testservice1.py`
A test client can be started using
`python testclient1.py Mathias` which calls the service with the argument Mathias.
```
Requesting Mathias
Mathias = Hello Mathias
```
### testservice2.py and testclient2.py
Another testservice
#### Sample usage
`rosrun grafchart testservice2.py`
A test client can be started using
`python testclient2.py 1 2`
```
Requesting 1+2
1 + 2 = 3
```
### jgrafchartbridge.py
jgrafchartbridge acts as a bridge between a running statemachine in JGrafChart and the ROS dispatchservice described below. It waits for a connection from a statemachine. After execution of the statemachine it waits for another connection. Should be started before the JGrafChart tool is started.
#### Sample usage
`python jgrafchartbridge.py`
```
Starting jgrafchart bridge
Waiting for connection...
```
### dispatchservice.py
dispatchservice waits for action strings from a statemachine, interprets these and issues ROS service calls. The mapping from action-string to function call is hand-crafted.
#### Sample usage
`rosrun grafchart dispatchservice.py`
```
Ready to dispatch.
```
#### Testing
There is a client script *dispatchclient.py* that can be used to test the dispatch service. Sample usage
`python dispatchclient.py "A|call=addtwoints,x=1,y=2"` calling the service testclient2.py
```
Dispatching A|call=addtwoints,x=1,y=2
Response sum=3
```
`python dispatchclient.py "Output|node=http://node/e1aacfb7-c17b-4924-8e7f-155248a91fef,xml_file=/home/mathias/certh/samples/xml_parser/keyframes_sequence_001/kf0.xml,result_reset=no,call=folding_initial,result_values=yes;no,result_name=initial_result_1"`
```
Dispatching Output|node=http://node/e1aacfb7-c17b-4924-8e7f-155248a91fef,xml_file=/home/mathias/certh/samples/xml_parser/keyframes_sequence_001/kf0.xml,result_reset=no,call=folding_initial,result_values=yes;no,result_name=initial_result_1
Response initial_result_1=yes
```
#### Editing dispatchservice.py
##### Adding new dispatch function
```
def identifyobjects(context):
print("Calling identifyobjects")
print("Context %s"%(str(context)))
#sample use of libxml2 xpath to read xml parameter
doc = context['xml_doc']
xmlcontext = doc.xpathNewContext()
xmlcontext.xpathRegisterNs('sarafun', 'http://www.SARAFunXML.com')
object_interaction = str(xmlcontext.xpathEval('//sarafun:ObjectInteraction/@id')[0].children)
print("ObjectInteraction %s"%object_interaction)
time.sleep(2) # Simulate work
# AssemblyType/id=(folding)/general, description=initial
# call object detector - specified return values (needed for sfc transitions)
# call ros node calculating transformation between cover pose to actual scene, need to transform/update all keyframes -> store in kif for now
# return result to state machine that triggers transition
reply = {}
result_name = context['result_name'].strip()
result_values = context['result_values'].strip().split(';')
reply[result_name] = result_values[0]
print("Result %s"%reply)
return reply
```
```
fmap = []
fmap += [("addtwoints", addtwoints)]
fmap += [("appendstring", appendstring)]
fmap += [("folding_initial", identifyobjects)]
fmap += [("folding_grasp", grasp)]
fmap += [("folding_pickup", pickup)]
fmap += [("folding_align", folding_align)]
fmap += [("folding_contact", folding_contact)]
fmap += [("folding_assembled", completed_assembly)]
fmap += [("folding_retract", retract)]
registry = dict(fmap)
```
```
def addtwoints(context):
reply = {}
try:
rospy.wait_for_service('add_two_ints', timeout=5)
add_two_ints = rospy.ServiceProxy('add_two_ints', TestService2)
resp1 = add_two_ints(int(context['x']), int(context['y']))
reply['sum'] = resp1.sum
except rospy.ServiceException, e:
print "Service call failed: %s"%e
return 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