sample-client.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib
00003 import rospy
00004 import os
00005 
00006 import actionlib
00007 import pddl_msgs
00008 from pddl_msgs.msg import *
00009 
00010 import sys
00011 import unittest
00012 
00013 class TestPddlPlanner(unittest.TestCase):
00014 
00015     def test_pddl_planner(self):
00016         client = actionlib.SimpleActionClient('pddl_planner',
00017                                               PDDLPlannerAction)
00018         client.wait_for_server()
00019         goal = PDDLPlannerGoal()
00020         goal.domain.name = "manip"
00021         goal.domain.requirements = ":typing"
00022         goal.domain.types = "object"
00023         goal.domain.predicates = ["(on ?obj0 ?obj1 - object)",
00024                                   "(clear ?obj - object)",
00025                                   "(ontable ?obj - object)",
00026                                   "(holding ?obj - object)",
00027                                   "(handempty)"]
00028         pickup = PDDLAction()
00029         pickup.name = "pickup"
00030         pickup.parameters = "(?obj - object)"
00031         pickup.precondition = "(and (ontable ?obj) (clear ?obj) (handempty))"
00032         pickup.effect = """(and (not (ontable ?obj)) (not (clear ?obj))  (not (handempty)) (holding ?obj))"""
00033         putdown = PDDLAction()
00034         putdown.name = "putdown"
00035         putdown.parameters = "(?obj - object)"
00036         putdown.precondition = "(and (holding ?obj))"
00037         putdown.effect = """(and
00038                                 (not (holding ?obj))
00039                                 (ontable ?obj)
00040                                 (clear ?obj)
00041                                 (handempty))"""
00042         stack = PDDLAction()
00043         stack.name = "stack"
00044         stack.parameters = "(?obj0 ?obj1 - object)"
00045         stack.precondition = """(and 
00046                                         (holding ?obj0)
00047                                         (clear ?obj1))"""
00048         stack.effect = """(and
00049                                 (not (holding ?obj0))
00050                                 (not (clear ?obj1))
00051                                 (handempty)
00052                                 (on ?obj0 ?obj1)
00053                                 (clear ?obj0))"""
00054         unstack = PDDLAction()
00055         unstack.name = "unstack"
00056         unstack.parameters = "(?obj0 ?obj1 - object)"
00057         unstack.precondition = """(and 
00058                                         (handempty)
00059                                         (on ?obj0 ?obj1)
00060                                         (clear ?obj0))"""
00061         unstack.effect = """(and
00062                                  (not (handempty))
00063                                  (not (on ?obj0 ?obj1))
00064                                  (not (clear ?obj0))
00065                                  (holding ?obj0)
00066                                  (clear ?obj1))"""
00067         goal.domain.actions = [pickup, unstack, stack, putdown]
00068         goal.problem.name = "sample"
00069         goal.problem.domain = "manip"
00070         goal.problem.objects = [PDDLObject(name="a", type="object"),
00071                                 PDDLObject(name="b", type="object"),
00072                                 PDDLObject(name="c", type="object")]
00073         goal.problem.initial = ["(on c a)", 
00074                                 "(ontable a)",
00075                                 "(ontable b)",
00076                                 "(clear b)",
00077                                 "(clear c)",
00078                                 "(handempty)"]
00079         goal.problem.goal = "(and (on a b) (on b c))"
00080         rospy.loginfo(str(goal))
00081         client.send_goal(goal)
00082         client.wait_for_result()
00083         result = client.get_result()
00084         rospy.logdebug(str(result))
00085         rospy.loginfo(str(result.sequence))
00086         self.assertEquals(len(result.sequence), 6, "result sequence is 6")
00087 
00088 if __name__ == '__main__':
00089     import rosunit
00090     rospy.init_node('pddl_planner_client', anonymous=True)
00091     rosunit.unitrun('pddl_planner', 'test_pddl_planner', TestPddlPlanner)


pddl_planner
Author(s): Ryohei Ueda (ueda@jsk.t.u-tokyo.ac.jp)
autogenerated on Sat Jun 8 2019 19:23:56