|
| 1 | +#! /usr/bin/env python |
| 2 | + |
| 3 | +from __future__ import print_function |
| 4 | +import unittest |
| 5 | +import rostest |
| 6 | +from moveit_commander.roscpp_initializer import roscpp_initialize |
| 7 | +from moveit_commander import PlanningSceneInterface |
| 8 | +from moveit.task_constructor import core, stages |
| 9 | +from geometry_msgs.msg import PoseStamped |
| 10 | + |
| 11 | + |
| 12 | +def make_pose(x, y, z): |
| 13 | + pose = PoseStamped() |
| 14 | + pose.header.frame_id = "base_link" |
| 15 | + pose.pose.position.x = x |
| 16 | + pose.pose.position.y = y |
| 17 | + pose.pose.position.z = z |
| 18 | + pose.pose.orientation.w = 1.0 |
| 19 | + return pose |
| 20 | + |
| 21 | + |
| 22 | +class TestModifyPlanningScene(unittest.TestCase): |
| 23 | + PLANNING_GROUP = "manipulator" |
| 24 | + |
| 25 | + def setUp(self): |
| 26 | + super(TestModifyPlanningScene, self).setUp() |
| 27 | + self.psi = PlanningSceneInterface(synchronous=True) |
| 28 | + # insert a box to collide with |
| 29 | + self.psi.add_box("box", make_pose(0.8, 0.25, 1.25), [0.2, 0.2, 0.2]) |
| 30 | + |
| 31 | + # colliding motion |
| 32 | + move = stages.MoveRelative("move", core.JointInterpolationPlanner()) |
| 33 | + move.group = self.PLANNING_GROUP |
| 34 | + move.setDirection({"joint_1": 0.3}) |
| 35 | + |
| 36 | + self.task = task = core.Task() |
| 37 | + task.add(stages.CurrentState("current"), move) |
| 38 | + |
| 39 | + def test_collision(self): |
| 40 | + self.assertFalse(self.task.plan()) |
| 41 | + |
| 42 | + def test_allow_collision_list(self): |
| 43 | + mps = stages.ModifyPlanningScene("mps") |
| 44 | + mps.allowCollisions("box", ["link_4", "link_5", "link_6"], True) |
| 45 | + self.task.insert(mps, 1) |
| 46 | + self.assertTrue(self.task.plan()) |
| 47 | + |
| 48 | + def test_allow_collision_all(self): |
| 49 | + # insert an extra collision object that is unknown to ACM |
| 50 | + self.psi.add_box("block", make_pose(0.8, 0.55, 1.25), [0.2, 0.2, 0.2]) |
| 51 | + # attach box to end effector |
| 52 | + self.psi.attach_box("link_6", "box") |
| 53 | + mps = stages.ModifyPlanningScene("mps") |
| 54 | + self.assertFalse(self.task.plan()) |
| 55 | + |
| 56 | + # allow all collisions for attached "box" object |
| 57 | + mps.allowCollisions("box", True) |
| 58 | + self.task.insert(mps, 1) |
| 59 | + self.assertTrue(self.task.plan()) |
| 60 | + # restore original state |
| 61 | + self.psi.remove_attached_object("link_6", "box") |
| 62 | + self.psi.remove_world_object("block") |
| 63 | + |
| 64 | + |
| 65 | +if __name__ == "__main__": |
| 66 | + roscpp_initialize("test_mtc") |
| 67 | + rostest.rosrun("mtc", "mps", TestModifyPlanningScene) |
0 commit comments