@@ -25,42 +25,87 @@ class TestModifyPlanningScene(unittest.TestCase):
2525 def setUp (self ):
2626 super (TestModifyPlanningScene , self ).setUp ()
2727 self .psi = PlanningSceneInterface (synchronous = True )
28+ self .make_box = self .psi ._PlanningSceneInterface__make_box
2829 # insert a box to collide with
2930 self .psi .add_box ("box" , make_pose (0.8 , 0.25 , 1.25 ), [0.2 , 0.2 , 0.2 ])
31+ self .task = task = core .Task ()
32+ task .add (stages .CurrentState ("current" ))
3033
34+ def insertMove (self , position = - 1 ):
3135 # colliding motion
3236 move = stages .MoveRelative ("move" , core .JointInterpolationPlanner ())
3337 move .group = self .PLANNING_GROUP
3438 move .setDirection ({"joint_1" : 0.3 })
35-
36- self .task = task = core .Task ()
37- task .add (stages .CurrentState ("current" ), move )
39+ self .task .insert (move , position )
3840
3941 def test_collision (self ):
42+ self .insertMove ()
4043 self .assertFalse (self .task .plan ())
4144
4245 def test_allow_collision_list (self ):
43- mps = stages .ModifyPlanningScene ("mps " )
46+ mps = stages .ModifyPlanningScene ("allow specific collisions for box " )
4447 mps .allowCollisions ("box" , ["link_4" , "link_5" , "link_6" ], True )
45- self .task .insert (mps , 1 )
48+ self .task .add (mps )
49+ self .insertMove ()
4650 self .assertTrue (self .task .plan ())
4751
4852 def test_allow_collision_all (self ):
4953 # insert an extra collision object that is unknown to ACM
5054 self .psi .add_box ("block" , make_pose (0.8 , 0.55 , 1.25 ), [0.2 , 0.2 , 0.2 ])
5155 # attach box to end effector
5256 self .psi .attach_box ("link_6" , "box" )
53- mps = stages . ModifyPlanningScene ( "mps" )
57+ self . insertMove ( )
5458 self .assertFalse (self .task .plan ())
5559
5660 # allow all collisions for attached "box" object
61+ mps = stages .ModifyPlanningScene ("allow all collisions for box" )
5762 mps .allowCollisions ("box" , True )
5863 self .task .insert (mps , 1 )
5964 self .assertTrue (self .task .plan ())
6065 # restore original state
6166 self .psi .remove_attached_object ("link_6" , "box" )
6267 self .psi .remove_world_object ("block" )
6368
69+ def test_fw_add_object (self ):
70+ mps = stages .ModifyPlanningScene ("addObject(block)" )
71+ mps .addObject (self .make_box ("block" , make_pose (0.8 , 0.55 , 1.25 ), [0.2 , 0.2 , 0.2 ]))
72+ self .task .add (mps )
73+ self .insertMove ()
74+ self .assertFalse (self .task .plan ())
75+
76+ def test_fw_remove_object (self ):
77+ mps = stages .ModifyPlanningScene ("removeObject(box)" )
78+ mps .removeObject ("box" )
79+ self .task .insert (mps , 1 )
80+ self .assertTrue (self .task .plan ())
81+ s = self .task .solutions [0 ].toMsg ()
82+ self .assertEqual (s .sub_trajectory [1 ].scene_diff .world .collision_objects [0 ].id , "box" )
83+
84+ def test_bw_add_object (self ):
85+ # add object to move_group's planning scene
86+ self .psi .add_box ("block" , make_pose (0.8 , 0.55 , 1.25 ), [0.2 , 0.2 , 0.2 ])
87+
88+ # backward operation will actually remove the object
89+ mps = stages .ModifyPlanningScene ("addObject(block) backwards" )
90+ mps .addObject (self .make_box ("block" , make_pose (0.8 , 0.55 , 1.25 ), [0.2 , 0.2 , 0.2 ]))
91+ self .task .insert (mps , 0 )
92+ self .insertMove (0 )
93+ self .assertTrue (self .task .plan ())
94+
95+ self .psi .remove_world_object ("block" ) # restore original state
96+
97+ s = self .task .solutions [0 ].toMsg ()
98+ for ps in [s .start_scene ] + [s .sub_trajectory [i ].scene_diff for i in [0 , 1 ]]:
99+ objects = [o .id for o in ps .world .collision_objects ]
100+ self .assertTrue (objects == ["block" , "box" ])
101+
102+ def test_bw_remove_object (self ):
103+ mps = stages .ModifyPlanningScene ("removeObject(box) backwards" )
104+ mps .removeObject ("box" )
105+ self .task .insert (mps , 0 )
106+ self .insertMove (0 )
107+ self .assertFalse (self .task .plan ())
108+
64109
65110if __name__ == "__main__" :
66111 roscpp_initialize ("test_mtc" )
0 commit comments