Reasoning about actions


This page describes the 'catkinized' version of KnowRob that uses the catkin buildsystem and the pure Java-based rosjava. The documentation for the older version, which was based on the rosbuild buildsystem and rosjava_jni, can be found here.


Loading a task description

The knowrob_tutorial package contains an example task description for making pancakes. You can start the system for this tutorial using the following commands. The content of this task description is visualized in the picture below.

rosrun rosprolog rosprolog knowrob_basics_tutorial
?- owl_parse('package://knowrob_actions/owl/pancake-making.owl').

Query for a sequence of actions that fulfils the ordering constraints

The class_properties(S,P,O) predicate can be used to read action properties specified on the class level, such as the subActions:

?- class_properties(make_pancakes:'MakingPancakes', knowrob:subAction, Sub).
Sub = make_pancakes:'CrackingAnEgg' ;
Sub = make_pancakes:'FlippingAPancake' ;
Sub = make_pancakes:'MixEggAndDough' ;
Sub = make_pancakes:'MixFlourAndMilk' ;
Sub = make_pancakes:'PourDoughOntoPancakeMaker'

The visualization shows the actions in the task in the correct order, although they are unordered in the OWL file (e.g. FlippingAPancake is the second action in the OWL file). Before visualization, the sub-actions have automatically been sorted based on the specified ordering constraints. The plan_subevents(Super, Sub) predicate reads the sub-actions of a plan and applies topological sorting based on the partial ordering constraints between the sub-actions to generate a sequence of actions that complies with these constraints:

?- plan_subevents(make_pancakes:'MakingPancakes', Sub).
Sub = [make_pancakes:'CrackingAnEgg',
       make_pancakes:'MixFlourAndMilk',
       make_pancakes:'MixEggAndDough',
       make_pancakes:'PourDoughOntoPancakeMaker',
       make_pancakes:'FlippingAPancake'].

There is also a recursive version of the plan_subevents predicate that also returns sub-actions of sub-actions:

?- plan_subevents_recursive(pancake:'MakingPancakes', Sub).

Query for action properties: fromLocation, toLocation, objectActedOn,...

Using the class_properties predicate, one can query for properties of an action such as the objectActedOn or the toLocation:

?- class_properties(make_pancakes:'PourDoughOntoPancakeMaker', P, O).
P = knowrob:'objectActedOn',
O = knowrob:'LiquidTangibleThing' ;
P = knowrob:'objectActedOn',
O = knowrob:'Dough' ;
P = knowrob:'toLocation',
O = knowrob:'PancakeMaker'
By giving the desired property as argument, one can select only specific results, e.g. only the objectActedOn:
?- class_properties(pancake:'MixFlourAndMilk', knowrob:objectActedOn, O).
O = knowrob:'CowsMilk-Product' ;
O = knowrob:'WheatFlour' ;

Reasoning about action requirements

Actions can have prerequisites in terms of components or capabilities a robot needs to have in order to execute them. The Semantic Robot Description Language allows to describe robot components, robot capabilities, and dependencies of actions.

The following are just some examples, a full overview of SRDL can be found in the tutorial.

?- register_ros_package(knowrob_srdl).
?- srdl2:required_cap_for_action(pancake:'MakingPancakes', Cap).
Cap = srdl2cap:'PickingUpAnObjectCapability' ;
Cap = srdl2cap:'ArmMotionCapability' ;
Cap = srdl2cap:'PickingUpAnObjectCapability' ;
Cap = srdl2cap:'ArmMotionCapability'

After loading a robot definition, the action requirements can be matched against the available capabilities to determine which ones are missing:

?- owl_parse('package://knowrob_srdl/owl/PR2.owl').
?- missing_cap_for_action(make_pancakes:'MakingPancakes', pr2:'PR2Robot1', M).
false.