tue-robotics / action_server

0 stars 0 forks source link

Use json schemas to let the client know about the structure of the semantics #23

Open rokusottervanger opened 7 years ago

rokusottervanger commented 7 years ago

http://json-schema.org/

alberth commented 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.

alberth commented 7 years ago

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
rokusottervanger commented 6 years ago

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.

rokusottervanger commented 6 years ago

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...