sample-client.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import roslib
3 import rospy
4 import os
5 
6 import actionlib
7 import pddl_msgs
8 from pddl_msgs.msg import *
9 
10 import sys
11 import unittest
12 
13 class TestPddlPlanner(unittest.TestCase):
14 
15  def test_pddl_planner(self):
16  client = actionlib.SimpleActionClient('pddl_planner',
17  PDDLPlannerAction)
18  client.wait_for_server()
19  goal = PDDLPlannerGoal()
20  goal.domain.name = "manip"
21  goal.domain.requirements = ":typing"
22  goal.domain.types = "object"
23  goal.domain.predicates = ["(on ?obj0 ?obj1 - object)",
24  "(clear ?obj - object)",
25  "(ontable ?obj - object)",
26  "(holding ?obj - object)",
27  "(handempty)"]
28  pickup = PDDLAction()
29  pickup.name = "pickup"
30  pickup.parameters = "(?obj - object)"
31  pickup.precondition = "(and (ontable ?obj) (clear ?obj) (handempty))"
32  pickup.effect = """(and (not (ontable ?obj)) (not (clear ?obj)) (not (handempty)) (holding ?obj))"""
33  putdown = PDDLAction()
34  putdown.name = "putdown"
35  putdown.parameters = "(?obj - object)"
36  putdown.precondition = "(and (holding ?obj))"
37  putdown.effect = """(and
38  (not (holding ?obj))
39  (ontable ?obj)
40  (clear ?obj)
41  (handempty))"""
42  stack = PDDLAction()
43  stack.name = "stack"
44  stack.parameters = "(?obj0 ?obj1 - object)"
45  stack.precondition = """(and
46  (holding ?obj0)
47  (clear ?obj1))"""
48  stack.effect = """(and
49  (not (holding ?obj0))
50  (not (clear ?obj1))
51  (handempty)
52  (on ?obj0 ?obj1)
53  (clear ?obj0))"""
54  unstack = PDDLAction()
55  unstack.name = "unstack"
56  unstack.parameters = "(?obj0 ?obj1 - object)"
57  unstack.precondition = """(and
58  (handempty)
59  (on ?obj0 ?obj1)
60  (clear ?obj0))"""
61  unstack.effect = """(and
62  (not (handempty))
63  (not (on ?obj0 ?obj1))
64  (not (clear ?obj0))
65  (holding ?obj0)
66  (clear ?obj1))"""
67  goal.domain.actions = [pickup, unstack, stack, putdown]
68  goal.problem.name = "sample"
69  goal.problem.domain = "manip"
70  goal.problem.objects = [PDDLObject(name="a", type="object"),
71  PDDLObject(name="b", type="object"),
72  PDDLObject(name="c", type="object")]
73  goal.problem.initial = ["(on c a)",
74  "(ontable a)",
75  "(ontable b)",
76  "(clear b)",
77  "(clear c)",
78  "(handempty)"]
79  goal.problem.goal = "(and (on a b) (on b c))"
80  rospy.loginfo(str(goal))
81  client.send_goal(goal)
82  client.wait_for_result()
83  result = client.get_result()
84  rospy.logdebug(str(result))
85  rospy.loginfo(str(result.sequence))
86  self.assertEquals(len(result.sequence), 6, "result sequence is 6")
87 
88 if __name__ == '__main__':
89  import rosunit
90  rospy.init_node('pddl_planner_client', anonymous=True)
91  rosunit.unitrun('pddl_planner', 'test_pddl_planner', TestPddlPlanner)


pddl_planner
Author(s): Ryohei Ueda (ueda@jsk.t.u-tokyo.ac.jp)
autogenerated on Fri Oct 21 2022 02:26:17