KCL-Planning / ROSPlan

The ROSPlan framework provides a generic method for task planning in a ROS system.
http://kcl-planning.github.io/ROSPlan
BSD 2-Clause "Simplified" License
359 stars 158 forks source link

removing goals from KB #325

Open Ogusch opened 1 year ago

Ogusch commented 1 year ago

Hello,

I have written a coordinator that checks the KB predicates. Depending on the state, the target should be changed. However, I am not able to remove the current targets. E.g.

Initial Problem.pddl

(:goal (and
    (= (n_drinks tableb1) 2)
    (= (n_drinks tableb2) 1)
))

I want followig:

(:goal (and
))

Snippet of function, which should remove goals:

    print("___main_executor___: remove_goal")

    sps = rospy.ServiceProxy('/rosplan_knowledge_base/state/goals', GetAttributeService)
    goals = {}

    gas = GetAttributeServiceRequest()
    gas.predicate_name = 'n_drinks'
    facts = sps(gas)
    for k in facts.attributes:
        table = k.ineq.LHS.tokens[0].function.typed_parameters[0].value
        amount = k.ineq.RHS.tokens[0].constant
        goals[table] = amount

    kus = KnowledgeUpdateServiceRequest()
    # REMOVE_GOAL=3 https://kcl-planning.github.io/ROSPlan//tutorials/tutorial_08
    kus.update_type = 3

    kus.knowledge.knowledge_type = 2
    kus.knowledge.attribute_name = 'n_drinks'

    for key,value in goals.items():
        kv = KeyValue()
        kv.key = key
        kv.value = value
        string_goal = "(= (n_drinks " + kv.key + ") " + str(int(kv.value)) +")"
        print("___main_executor___: remove_goal: remove goal " + string_goal)
        kus.knowledge.values.append(kv)
        kus.knowledge.values.append(string_goal)
        kuc = rospy.ServiceProxy('/rosplan_knowledge_base/update', KnowledgeUpdateService)

The problem instance is getting overwritten. Only the goal does not change.

gerardcanal commented 1 year ago

Hi Ogusch, I believe this is because you are not specifying the values of the kus.knowledge to be removed (that is, the parameters of n_drinks). Here: https://github.com/KCL-Planning/ROSPlan/blob/639037230073997d3ed3fea7391f1e1b3c6b1ffa/rosplan_knowledge_base/src/KnowledgeComparitor.cpp#L154 it checks that the value is the same, and this is used by remove goal (which, in the case of a function, it checks as if it was a fact, so it only checks for the function name and parameters to be equal).