Open rokusottervanger opened 7 years ago
While reading the documentation you wrote, an alternative could be to write a few functions that create or modify the json dict:
requests = add_navigate_room("kitchen", None)
requests = add_find_object("coke", requests)
requests = add_give_object("it", "operator", requests)
send_to_action_server(requests)
This fixes the interface by means of the function parameters at the time of construction (rather than receiving at the action server), and hides having to manipulate the nested dict stuff manually.
Obviously, you can expand this further, and have a class for each type of action with the data, that you give to the functions. (Not sure it's useful at the client side however.)
At the server side you can do the reverse, although that may already happen.
Sample implementation of the 'add_navigate_room' is then:
def add_navigate_room(roomtype, requests=None):
if requests is None:
requests = {'actions':[]}
cmd = {"action": "navigate-to",
"object": {"type" : "room",
"name" : roomtype}}
requests['actions'].append(cmd)
return requests
https://github.com/tue-robotics/action_server/pull/84#pullrequestreview-78435341 describes a nice consequence of working with json schemas: using a configuration parser taking the configuration and the schema and constructing an object with the attributes as specified in the schema.
It would be great if we could use this in some tooling that also checks the grammar specifications in the robocup_knowledge for accordance with the schemas (or whatever we use to define the interface) specified in the action implementations...
http://json-schema.org/