PlanSys2 / ros2_planning_system

This repo contains a PDDL-based planning system for ROS2.
Apache License 2.0
384 stars 86 forks source link

Adding support for new planner: problems parsing pddl files #317

Open Rezenders opened 3 weeks ago

Rezenders commented 3 weeks ago

Hello,

I am working on adding support for the Symk planner to PlanSys2, mainly because I need a planner that supports derived predicates. I created a ros package and a plansys plugin for the planner: https://github.com/Rezenders/symk_ros And I am trying to apply it to SUAVE exemplar with the following setup: https://github.com/Rezenders/suave_planning

However, I am having some problems with the parsing of my PDDL files. The derived predicates in the domain file don't get parsed, and some predicates in the problem file are also not getting parsed. I can check this by looking into the domain and problem files created in the /tmp folder.

For example, the suave_domain_created.pddl domain file is outputted as:

(define (domain suave)
(:requirements :adl
 :derived-predicates :negative-preconditions
 :strips
 :typing
 )

(:types
        pipeline
        robot
        action
)

(:constants
 a_search_pipeline a_inspect_pipeline - action
    internal_error_string in_error_fr_string in_error_component_string in_error_nfr_string false_string false_boolean water_visibility recovered_string true_boolean
)

(:predicates
        (c_status ?x ?y)
        (component ?x)
        (fd_efficacy ?x ?y)
        (fd_error_log ?x ?y)
        (fd_realisability ?x ?y)
        (fg_status ?x ?y)
        (function ?x)
        (functiondesign ?x)
        (functiongrounding ?x)
        (hasnfr ?x ?y)
        (hasqaestimation ?x ?y)
        (hasqavalue ?x ?y)
        (hasvalue ?x ?y)
        (inferred-c_status ?x ?y)
        (inferred-component ?x)
        (inferred-fd_efficacy ?x ?y)
        (inferred-fd_error_log ?x ?y)
        (inferred-fd_realisability ?x ?y)
        (inferred-fg_status ?x ?y)
        (inferred-function ?x)
        (inferred-functiondesign ?x)
        (inferred-functiongrounding ?x)
        (inferred-hasnfr ?x ?y)
        (inferred-hasqaestimation ?x ?y)
        (inferred-hasqavalue ?x ?y)
        (inferred-hasvalue ?x ?y)
        (inferred-inconsistent)
        (inferred-isqatype ?x ?y)
        (inferred-lessthan ?x ?y)
        (inferred-o_always_improve ?x ?y)
        (inferred-o_status ?x ?y)
        (inferred-o_updatable ?x ?y)
        (inferred-objective ?x)
        (inferred-qa_comparison_operator ?x ?y)
        (inferred-qa_critical ?x ?y)
        (inferred-qavalue ?x)
        (inferred-qualityattributetype ?x)
        (inferred-requiresc ?x ?y)
        (inferred-requireso ?x ?y)
        (inferred-solvesf ?x ?y)
        (inferred-solveso ?x ?y)
        (inferred-typef ?x ?y)
        (inferred-typefd ?x ?y)
        (isqatype ?x ?y)
        (o_always_improve ?x ?y)
        (o_status ?x ?y)
        (o_updatable ?x ?y)
        (objective ?x)
        (qa_comparison_operator ?x ?y)
        (qa_critical ?x ?y)
        (qavalue ?x)
        (qualityattributetype ?x)
        (requiresc ?x ?y)
        (requireso ?x ?y)
        (solvesf ?x ?y)
        (solveso ?x ?y)
        (typef ?x ?y)
        (typefd ?x ?y)
        (action_requires ?a - action ?f1 ?f2)
        (fd_available ?fd)
        (pipeline_found ?p - pipeline)
        (pipeline_inspected ?p - pipeline)
        (robot_started ?r - robot)
)

(:action start_robot
      :parameters (?r - robot)
      :precondition (and
      )
      :effect (and
        (robot_started ?r)
      )
    )
(:action search_pipeline
      :parameters (?a - action ?p - pipeline ?r - robot ?fd1 ?fd2)
      :precondition (and
        (= ?a a_search_pipeline)
        (exists (?f1 ?f2)
          (and
            (action_requires ?a ?f1 ?f2)
            (function ?f1)
            (function ?f2)
            (functiondesign ?fd1)
            (functiondesign ?fd2)
            (solvesf ?fd1 ?f1)
            (solvesf ?fd2 ?f2)
            (not (inferred-fd_realisability ?fd1 false_boolean))
            (not (inferred-fd_realisability ?fd2 false_boolean))
          )
        )
        (robot_started ?r)
      )
      :effect (and
        (pipeline_found ?p)
      )
    )
(:action inspect_pipeline
      :parameters (?a - action ?p - pipeline ?r - robot ?fd1 ?fd2)
      :precondition (and
        (= ?a a_inspect_pipeline)
        (exists (?f1 ?f2)
          (and
            (action_requires ?a ?f1 ?f2)
            (function ?f1)
            (function ?f2)
            (functiondesign ?fd1)
            (functiondesign ?fd2)
            (solvesf ?fd1 ?f1)
            (solvesf ?fd2 ?f2)
            (not (inferred-fd_realisability ?fd1 false_boolean))
            (not (inferred-fd_realisability ?fd2 false_boolean))
          )
        )
        (robot_started ?r)
        (pipeline_found ?p)
      )
      :effect (and
        (pipeline_inspected ?p)
      )
    )
)

The suave_problem_created.pddl problem file becomes:

( define ( problem problem_1 )
( :domain suave )
( :objects
    pipeline - pipeline
    bluerov - robot
)
( :init
    ( qualityattributetype water_visibility )
)
( :goal
    ( and
        ( robot_started bluerov )
        ( pipeline_found pipeline )
        ( pipeline_inspected pipeline )
    ))
)

I will work on this the following week and propose a PR when I solve these problems. I opened this issue to let you know and check if anyone has insights on how to solve this.

I guess the problem of the derived predicates not being parsed is related to the parseDerived method https://github.com/PlanSys2/ros2_planning_system/blob/c063ce54cf86f46594e9bda160e01dc8c40d4de5/plansys2_pddl_parser/include/plansys2_pddl_parser/Domain.h#L102

But I still need to figure out why the problem file predicates are not parsed. Would anyone happen to have any ideas?

Rezenders commented 2 weeks ago

PR #318 solves the problem of the derived predicates not being parsed.

However, I still get errors with not expressions of the form (not (= ?y ?z)) such as in:

(:derived (inferred-Inconsistent )
        (exists (?x ?y ?z)
            (and
                (inferred-C_status ?x ?y)
                (inferred-C_status ?x ?z)
                (not (= ?y ?z))
            )
        )
    )

Error:

Error parsing PDDL:  does not name a known token
Error parsing PDDL:  does not name a known token

This error occurs because it is not possible to cast CompositeExpression to Ground *. Thus, cond results in a nullptr. https://github.com/PlanSys2/ros2_planning_system/blob/c063ce54cf86f46594e9bda160e01dc8c40d4de5/plansys2_pddl_parser/src/plansys2_pddl_parser/Not.cpp#L31-L35

I don't really know how to fix this problem as I don't fully understand what the Ground class does.