Closed mgerhardt10 closed 4 years ago
There are two types of actions: SimpleAction and Action. SimpleAction is not checking preconditions automatically neither applying postconditions automatically, while Action is doing both However, if you use SimpleAction the preconditions are checked because ROSPlan does it, so it depends on ROSPlan implemented behavior. And function-based approach uses SimpleAction, see here.
Let me clarify that SimpleAction exists due to historical reasons. When this repository was diverged from the original one, I created the new Action and renamed the original one to SimpleAction. In my opinion the original action was useless because you have to apply the post-conditions manually, but this should not be user responsibility because it is very complex. But, I maintain the SimpleAction in case that someone wants to do that.
About how to apply post-conditions you should check Action source code, there you could see that it uses the CheckActionAndProcessEffects to check preconditions and to apply postconditions, see here. This class is asking ROSPlan all the information and applying the post-conditions using KB interface.
I would like to know what you are tying to do because other options could exist. For example, if you would like to use function-based approach but that postconditions are automatically applied, this could be done by using Action instead SimpleAction in the decorator. A new decorator could be created or current decorator could be extend to pass an argument to indicate the type of action.
Thanks for the detailed response! In my implementation, I'm simply trying to issue a hardware command given a ROSPlan action dispatch. In that sense, the action does not need to check or update any conditions, rather, run when the action is dispatched. The issue I'm facing is that I can't get ROSPlan to recognize that the action has completed.
This is the error I'm getting:
[WARN] [1600872574.786506, 1716.490000]: [RPpt][AIF] action 'arm_to_grab' failed.
Traceback (most recent call last):
File "/home/mitch_gerhardt/Documents/husky/src/rosplan_pytools/src/rosplan_pytools/rosplan/interfaces/action_interface.py", line 77, in _action_receiver
action.execute(**keyval_to_dict(msg.parameters))
File "/home/mitch_gerhardt/Documents/husky/src/rosplan_pytools/src/rosplan_pytools/rosplan/interfaces/action_interface.py", line 451, in execute
checker.apply_effects()
File "/home/mitch_gerhardt/Documents/husky/src/rosplan_pytools/src/rosplan_pytools/rosplan/interfaces/action_interface.py", line 361, in apply_effects
kb.remove_predicate(effect_name, **effect_value)
File "/home/mitch_gerhardt/Documents/husky/src/rosplan_pytools/src/rosplan_pytools/rosplan/controller/knowledge_base.py", line 212, in remove_predicate
return _services["update_knowledge_base"](KB_UPDATE_RM_KNOWLEDGE, kb_item).success
KeyError: 'update_knowledge_base'
First, I have to correct myself because I explained one thing incorrectly. The Action checks the parameters and apply postconditions automatically but it does not check preconditions, preconditions are checked by ROSPlan. If you check the name of the methods in CheckActionAndProcessEffects they are _validateparameters() and _applyeffects(). Sorry for that mistake.
In your case you PDDL action has postconditions and you would like that these postconditions are automatically applied after you send the hardware command, no? Then you need to use Action because it does this job for you. In fact, in you trace I can see that you are using it because the _checker.applyeffects() is called.
The problem seems to be raised when the service _update_knowledgebase is called to update information from the ROSPlan KB, it says that this service does not exist. So, have you initialized the knowledge_base interface in addition to the actions interface that you are using. The actions needs to interact with ROSPlan KB to check parameters and apply postconditions. To initialize knowledge_base interface you have to do kb.initialize().
The strange thing is that your code fails when trying to apply postconditions but not when checking parameters. After reviewing the source code I have realized that _validateparameters() method of CheckActionAndProcessEffects use services to KB ROSPlan that are created by this class, while _applyeffects() uses the knowledge interface of _rosplanpytools. And this explain why checking parameters works without initializing knowledge interface. Of course, this is wrong because this class should use the same approach to connect to ROSPlan KB, I am going to create an issue to fix this later.
@mgerhardt10, please, let me know if I could close this issue. Thanks.
@mgerhardt10, please, let me know if I could close this issue. Thanks.
Yes.
There are mentions of "In case you are using function-based approach you have to set postconditions (or effects) in your code" in the documentation, however, it's not clear how to implement it. Could you please explain further what it means to set postconditions/provide an example? Thank you.