def setUp(self):

        rospy.init_node('test_allowed_collisions')

        obj_pub = rospy.Publisher('collision_object',CollisionObject,latch=True)
        att_pub = rospy.Publisher('attached_collision_object', AttachedCollisionObject,latch=True)

        full_name = default_prefix+'/'+revert_allowed_collision_service_name
        rospy.wait_for_service(full_name)
        revert_allowed_collision_service_proxy = rospy.ServiceProxy(full_name, std_srvs.srv.Empty)   

        clear_all_att = AttachedCollisionObject()
        clear_all_att.object.header.stamp = rospy.Time.now()
        clear_all_att.object.header.frame_id = "base_link"
        clear_all_att.link_name = "all"
        clear_all_att.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.REMOVE

        clear_all_obj = CollisionObject()
        clear_all_obj.header.stamp = rospy.Time.now()
        clear_all_obj.header.frame_id = "base_link"
        clear_all_obj.id = "all"
        clear_all_obj.operation.operation = mapping_msgs.msg.CollisionObjectOperation.REMOVE
        
        empty_req = std_srvs.srv.EmptyRequest()

        revert_allowed_collision_service_proxy(empty_req)
Exemplo n.º 2
0
    def setUp(self):

        rospy.init_node('test_allowed_collisions')

        obj_pub = rospy.Publisher('collision_object',
                                  CollisionObject,
                                  latch=True)
        att_pub = rospy.Publisher('attached_collision_object',
                                  AttachedCollisionObject,
                                  latch=True)

        full_name = default_prefix + '/' + revert_allowed_collision_service_name
        rospy.wait_for_service(full_name)
        revert_allowed_collision_service_proxy = rospy.ServiceProxy(
            full_name, std_srvs.srv.Empty)

        clear_all_att = AttachedCollisionObject()
        clear_all_att.object.header.stamp = rospy.Time.now()
        clear_all_att.object.header.frame_id = "base_link"
        clear_all_att.link_name = "all"
        clear_all_att.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.REMOVE

        clear_all_obj = CollisionObject()
        clear_all_obj.header.stamp = rospy.Time.now()
        clear_all_obj.header.frame_id = "base_link"
        clear_all_obj.id = "all"
        clear_all_obj.operation.operation = mapping_msgs.msg.CollisionObjectOperation.REMOVE

        empty_req = std_srvs.srv.EmptyRequest()

        revert_allowed_collision_service_proxy(empty_req)
Exemplo n.º 3
0
def test_add_convert_objects():

    att_pub = rospy.Publisher('attached_collision_object',
                              AttachedCollisionObject)

    rospy.init_node('test_collision_objects')

    att_obj = AttachedCollisionObject()
    att_obj.link_name = "r_gripper_palm_link"
    att_obj.touch_links = [
        'r_gripper_palm_link', 'r_gripper_r_finger_link',
        'r_gripper_l_finger_link', 'r_gripper_r_finger_tip_link',
        'r_gripper_l_finger_tip_link', 'r_wrist_roll_link',
        'r_wrist_flex_link', 'r_forearm_link',
        'r_gripper_motor_accelerometer_link'
    ]
    obj2 = CollisionObject()

    obj2.header.stamp = rospy.Time.now()
    obj2.header.frame_id = "r_gripper_palm_link"
    obj2.id = "obj2"
    obj2.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
    obj2.shapes = [Shape() for _ in range(1)]
    obj2.shapes[0].type = Shape.BOX
    obj2.shapes[0].dimensions = [float() for _ in range(3)]
    obj2.shapes[0].dimensions[0] = .2
    obj2.shapes[0].dimensions[1] = .4
    obj2.shapes[0].dimensions[2] = .2
    obj2.poses = [Pose() for _ in range(1)]
    obj2.poses[0].position.x = .12
    obj2.poses[0].position.y = 0
    obj2.poses[0].position.z = 0
    obj2.poses[0].orientation.x = 0
    obj2.poses[0].orientation.y = 0
    obj2.poses[0].orientation.z = 0
    obj2.poses[0].orientation.w = 1
    att_obj.object = obj2
    r = rospy.Rate(6)

    sent_twice = 0

    while (True):
        sent_twice += 1
        if sent_twice >= 4 and sent_twice % 2 == 0:
            att_obj.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.DETACH_AND_ADD_AS_OBJECT
        elif sent_twice > 4 and sent_twice % 2 == 1:
            att_obj.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ATTACH_AND_REMOVE_AS_OBJECT
        print 'sending'
        att_obj.object.header.stamp = rospy.Time.now()
        att_pub.publish(att_obj)

        r.sleep()
def test_add_convert_objects():

    att_pub = rospy.Publisher('attached_collision_object',AttachedCollisionObject)

    rospy.init_node('test_collision_objects')

    att_obj = AttachedCollisionObject()
    att_obj.link_name = "r_gripper_palm_link"
    att_obj.touch_links = ['r_gripper_palm_link', 'r_gripper_r_finger_link', 'r_gripper_l_finger_link',
                           'r_gripper_r_finger_tip_link', 'r_gripper_l_finger_tip_link', 'r_wrist_roll_link', 'r_wrist_flex_link', 'r_forearm_link', 'r_gripper_motor_accelerometer_link']
    obj2 = CollisionObject()
    
    obj2.header.stamp = rospy.Time.now()
    obj2.header.frame_id = "r_gripper_palm_link"
    obj2.id = "obj2";
    obj2.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
    obj2.shapes = [Shape() for _ in range(1)]
    obj2.shapes[0].type = Shape.BOX
    obj2.shapes[0].dimensions = [float() for _ in range(3)]
    obj2.shapes[0].dimensions[0] = .2
    obj2.shapes[0].dimensions[1] = .4
    obj2.shapes[0].dimensions[2] = .2
    obj2.poses = [Pose() for _ in range(1)]
    obj2.poses[0].position.x = .12
    obj2.poses[0].position.y = 0
    obj2.poses[0].position.z = 0
    obj2.poses[0].orientation.x = 0
    obj2.poses[0].orientation.y = 0
    obj2.poses[0].orientation.z = 0
    obj2.poses[0].orientation.w = 1
    att_obj.object = obj2
    r = rospy.Rate(6)

    sent_twice = 0

    while(True):
        sent_twice += 1
        if sent_twice >= 4 and sent_twice%2 == 0:
            att_obj.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.DETACH_AND_ADD_AS_OBJECT
        elif sent_twice > 4 and sent_twice%2 == 1:
            att_obj.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ATTACH_AND_REMOVE_AS_OBJECT
        print 'sending'    
        att_obj.object.header.stamp = rospy.Time.now()
        att_pub.publish(att_obj)     
        
        r.sleep()
Exemplo n.º 5
0
    def test_add_convert_objects(self):

        rospy.init_node('test_collision_objects')

        obj_pub = rospy.Publisher('collision_object',
                                  CollisionObject,
                                  latch=True)
        att_pub = rospy.Publisher('attached_collision_object',
                                  AttachedCollisionObject,
                                  latch=True)

        global get_collision_objects_service_name
        full_name = default_prefix + '/' + get_collision_objects_service_name
        rospy.wait_for_service(full_name)
        get_collision_objects_service = rospy.ServiceProxy(
            full_name, arm_navigation_msgs.srv.GetCollisionObjects)

        clear_all_att = AttachedCollisionObject()
        clear_all_att.object.header.stamp = rospy.Time.now()
        clear_all_att.object.header.frame_id = "base_link"
        clear_all_att.link_name = "all"
        clear_all_att.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.REMOVE

        clear_all_obj = CollisionObject()
        clear_all_obj.header.stamp = rospy.Time.now()
        clear_all_obj.header.frame_id = "base_link"
        clear_all_obj.id = "all"
        clear_all_obj.operation.operation = mapping_msgs.msg.CollisionObjectOperation.REMOVE

        #tripling for publish wonkitude

        att_pub.publish(clear_all_att)

        obj_pub.publish(clear_all_obj)

        rospy.sleep(2.)

        get_collision_objects_req = arm_navigation_msgs.srv.GetCollisionObjectsRequest(
        )
        try:
            get_collision_objects_res = get_collision_objects_service(
                get_collision_objects_req)
        except rospy.ServiceException, e:
            print "Service call failed: %s" % e
    def setUp(self):

        self.tf = TransformListener()

        self.move_arm_action_client = actionlib.SimpleActionClient("move_right_arm", MoveArmAction)

        att_pub = rospy.Publisher("attached_collision_object", AttachedCollisionObject)
        obj_pub = rospy.Publisher("collision_object", CollisionObject)

        rospy.init_node("test_motion_execution_buffer")

        # let everything settle down
        rospy.sleep(5.0)

        obj1 = CollisionObject()

        obj1.header.stamp = rospy.Time.now() - rospy.Duration(0.1)
        obj1.header.frame_id = "base_footprint"
        obj1.id = "obj2"
        obj1.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        obj1.shapes = [Shape() for _ in range(3)]
        obj1.poses = [Pose() for _ in range(3)]

        obj1.shapes[0].type = Shape.BOX
        obj1.shapes[0].dimensions = [float() for _ in range(3)]
        obj1.shapes[0].dimensions[0] = 0.5
        obj1.shapes[0].dimensions[1] = 1.0
        obj1.shapes[0].dimensions[2] = 0.2
        obj1.poses[0].position.x = 0.95
        obj1.poses[0].position.y = -0.25
        obj1.poses[0].position.z = 0.62
        obj1.poses[0].orientation.x = 0
        obj1.poses[0].orientation.y = 0
        obj1.poses[0].orientation.z = 0
        obj1.poses[0].orientation.w = 1

        obj1.shapes[2].type = Shape.BOX
        obj1.shapes[2].dimensions = [float() for _ in range(3)]
        obj1.shapes[2].dimensions[0] = 0.5
        obj1.shapes[2].dimensions[1] = 0.1
        obj1.shapes[2].dimensions[2] = 1.0
        obj1.poses[2].position.x = 0.95
        obj1.poses[2].position.y = -0.14
        obj1.poses[2].position.z = 1.2
        obj1.poses[2].orientation.x = 0
        obj1.poses[2].orientation.y = 0
        obj1.poses[2].orientation.z = 0
        obj1.poses[2].orientation.w = 1

        obj1.shapes[1].type = Shape.BOX
        obj1.shapes[1].dimensions = [float() for _ in range(3)]
        obj1.shapes[1].dimensions[0] = 0.5
        obj1.shapes[1].dimensions[1] = 0.1
        obj1.shapes[1].dimensions[2] = 1.0
        obj1.poses[1].position.x = 0.95
        obj1.poses[1].position.y = 0.12
        obj1.poses[1].position.z = 1.2
        obj1.poses[1].orientation.x = 0
        obj1.poses[1].orientation.y = 0
        obj1.poses[1].orientation.z = 0
        obj1.poses[1].orientation.w = 1

        obj_pub.publish(obj1)

        att_object = AttachedCollisionObject()
        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "r_gripper_r_finger_tip_link"
        att_object.link_name = "r_gripper_r_finger_tip_link"
        att_object.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        att_object.object = CollisionObject()

        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "r_gripper_r_finger_tip_link"
        att_object.object.id = "pole"
        att_object.object.shapes = [Shape() for _ in range(1)]
        att_object.object.shapes[0].type = Shape.CYLINDER
        att_object.object.shapes[0].dimensions = [float() for _ in range(2)]
        att_object.object.shapes[0].dimensions[0] = 0.02
        att_object.object.shapes[0].dimensions[1] = 0.1
        att_object.object.poses = [Pose() for _ in range(1)]
        att_object.object.poses[0].position.x = -0.02
        att_object.object.poses[0].position.y = 0.04
        att_object.object.poses[0].position.z = 0
        att_object.object.poses[0].orientation.x = 0
        att_object.object.poses[0].orientation.y = 0
        att_object.object.poses[0].orientation.z = 0
        att_object.object.poses[0].orientation.w = 1

        att_pub.publish(att_object)

        rospy.sleep(5.0)
Exemplo n.º 7
0
    def setUp(self):

        rospy.init_node('test_attached_object_collisions')

        self.obj_pub = rospy.Publisher('collision_object',
                                       CollisionObject,
                                       latch=True)
        self.att_pub = rospy.Publisher('attached_collision_object',
                                       AttachedCollisionObject,
                                       latch=True)

        rospy.wait_for_service(default_prefix + '/get_state_validity')
        self.get_state_validity_server = rospy.ServiceProxy(
            default_prefix + '/get_state_validity', GetStateValidity)

        self.state_req = GetStateValidityRequest()
        self.state_req.robot_state.joint_state.name = [
            'r_shoulder_pan_joint', 'r_shoulder_lift_joint',
            'r_upper_arm_roll_joint', 'r_elbow_flex_joint',
            'r_forearm_roll_joint', 'r_wrist_flex_joint', 'r_wrist_roll_joint'
        ]
        self.state_req.robot_state.joint_state.position = [
            float(0.0) for _ in range(7)
        ]
        self.state_req.check_collisions = True

        self.table = CollisionObject()

        self.table.header.stamp = rospy.Time.now()
        self.table.header.frame_id = "base_link"
        self.table.id = "tabletop"
        self.table.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        self.table.shapes = [Shape() for _ in range(1)]
        self.table.shapes[0].type = Shape.BOX
        self.table.shapes[0].dimensions = [float() for _ in range(3)]
        self.table.shapes[0].dimensions[0] = 1.0
        self.table.shapes[0].dimensions[1] = 1.0
        self.table.shapes[0].dimensions[2] = .05
        self.table.poses = [Pose() for _ in range(1)]
        self.table.poses[0].position.x = 1.0
        self.table.poses[0].position.y = 0
        self.table.poses[0].position.z = .5
        self.table.poses[0].orientation.x = 0
        self.table.poses[0].orientation.y = 0
        self.table.poses[0].orientation.z = 0
        self.table.poses[0].orientation.w = 1

        #not publishing table right away

        self.att_object = AttachedCollisionObject()
        self.att_object.object.header.stamp = rospy.Time.now()
        self.att_object.object.header.frame_id = "r_gripper_r_finger_tip_link"
        self.att_object.link_name = "r_gripper_r_finger_tip_link"
        self.att_object.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        self.att_object.object = CollisionObject()

        self.att_object.object.header.stamp = rospy.Time.now()
        self.att_object.object.header.frame_id = "r_gripper_r_finger_tip_link"
        self.att_object.object.id = "pole"
        self.att_object.object.shapes = [Shape() for _ in range(1)]
        self.att_object.object.shapes[0].type = Shape.CYLINDER
        self.att_object.object.shapes[0].dimensions = [
            float() for _ in range(2)
        ]
        self.att_object.object.shapes[0].dimensions[0] = .02
        self.att_object.object.shapes[0].dimensions[1] = 1.2
        self.att_object.object.poses = [Pose() for _ in range(1)]
        self.att_object.object.poses[0].position.x = 0
        self.att_object.object.poses[0].position.y = 0
        self.att_object.object.poses[0].position.z = 0
        self.att_object.object.poses[0].orientation.x = 0
        self.att_object.object.poses[0].orientation.y = 0
        self.att_object.object.poses[0].orientation.z = 0
        self.att_object.object.poses[0].orientation.w = 1

        self.att_pub.publish(self.att_object)

        self.touch_links = [
            'r_gripper_palm_link', 'r_gripper_r_finger_link',
            'r_gripper_l_finger_link', 'r_gripper_r_finger_tip_link',
            'r_gripper_l_finger_tip_link'
        ]

        rospy.sleep(2.)
    def test_attached_object_collision_operations(self):

        global set_allowed_collision_service_name
        global get_allowed_collision_service_name
        global revert_allowed_collision_service_name
        full_name = default_prefix+'/'+set_allowed_collision_service_name
        rospy.wait_for_service(full_name)
        set_allowed_collision_service_proxy = rospy.ServiceProxy(full_name, arm_navigation_msgs.srv.SetAllowedCollisions)  

        full_name = default_prefix+'/'+get_allowed_collision_service_name
        rospy.wait_for_service(full_name)
        get_allowed_collision_service_proxy = rospy.ServiceProxy(full_name, arm_navigation_msgs.srv.GetAllowedCollisionMatrix)

        full_name = default_prefix+'/'+revert_allowed_collision_service_name
        rospy.wait_for_service(full_name)
        revert_allowed_collision_service_proxy = rospy.ServiceProxy(full_name, std_srvs.srv.Empty)   

        att_pub = rospy.Publisher('attached_collision_object', AttachedCollisionObject)

        rospy.init_node('test_allowed_collisions')

        att_object = AttachedCollisionObject();
        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "base_link"
        att_object.link_name = "r_gripper_r_finger_tip_link"
        att_object.touch_links = [str() for _ in range(1)]
        att_object.touch_links[0] = "r_gripper_palm_link"
        att_object.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        att_object.object = CollisionObject();
        
        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "base_link"
        att_object.object.id = "obj3"
        att_object.object.shapes = [Shape() for _ in range(1)]
        att_object.object.shapes[0].type = Shape.BOX
        att_object.object.shapes[0].dimensions = [float() for _ in range(3)]
        att_object.object.shapes[0].dimensions[0] = .2
        att_object.object.shapes[0].dimensions[1] = 0.3
        att_object.object.shapes[0].dimensions[2] = .05
        att_object.object.poses = [Pose() for _ in range(1)]
        att_object.object.poses[0].position.x = .15
        att_object.object.poses[0].position.y = 0
        att_object.object.poses[0].position.z = 1.0
        att_object.object.poses[0].orientation.x = 0
        att_object.object.poses[0].orientation.y = 0
        att_object.object.poses[0].orientation.z = 0
        att_object.object.poses[0].orientation.w = 1
        att_pub.publish(att_object)

        rospy.sleep(5.0)

        get_mat = arm_navigation_msgs.srv.GetAllowedCollisionMatrixRequest()
    
        get_res = get_allowed_collision_service_proxy(get_mat)

        try:
            r_gripper_palm_link_index = get_res.matrix.link_names.index("r_gripper_palm_link")
        except ValueError:
            self.fail("No r_gripper_palm_link in AllowedCollisionMatrix link names")

        try:
            r_gripper_r_finger_tip_link_index = get_res.matrix.link_names.index("r_gripper_r_finger_tip_link")
        except ValueError:
            self.fail("No r_gripper_r_finger_tip_link in AllowedCollisionMatrix link names")

        try:
            obj3_index = get_res.matrix.link_names.index("obj3")
        except ValueError:
            self.fail("No obj3 in AllowedCollisionMatrix link names") 

        self.assertEqual(True, get_res.matrix.entries[obj3_index].enabled[r_gripper_r_finger_tip_link_index])
        self.assertEqual(True, get_res.matrix.entries[r_gripper_r_finger_tip_link_index].enabled[obj3_index])

        self.assertEqual(True, get_res.matrix.entries[obj3_index].enabled[r_gripper_palm_link_index])
        self.assertEqual(True, get_res.matrix.entries[r_gripper_palm_link_index].enabled[obj3_index])
        
        #this should overwrite touch links
        set_allowed_request = arm_navigation_msgs.srv.SetAllowedCollisionsRequest()   
        set_allowed_request.ord.collision_operations = [CollisionOperation() for _ in range(1)]
        set_allowed_request.ord.collision_operations[0].object1 = "obj3"
        set_allowed_request.ord.collision_operations[0].object2 = "r_gripper_palm_link"
        set_allowed_request.ord.collision_operations[0].operation = CollisionOperation.ENABLE

        set_allowed_collision_service_proxy(set_allowed_request)

        rospy.sleep(1.)

        get_res = get_allowed_collision_service_proxy(get_mat)

        self.assertEqual(False, get_res.matrix.entries[obj3_index].enabled[r_gripper_palm_link_index])
        self.assertEqual(False, get_res.matrix.entries[r_gripper_palm_link_index].enabled[obj3_index])

        set_allowed_request.ord.collision_operations[0].object1 = "r_gripper_palm_link"
        set_allowed_request.ord.collision_operations[0].object2 = CollisionOperation.COLLISION_SET_ATTACHED_OBJECTS
        set_allowed_request.ord.collision_operations[0].operation = CollisionOperation.DISABLE

        set_allowed_collision_service_proxy(set_allowed_request)

        rospy.sleep(1.)

        get_res = get_allowed_collision_service_proxy(get_mat)

        self.assertEqual(True, get_res.matrix.entries[obj3_index].enabled[r_gripper_palm_link_index])
        self.assertEqual(True, get_res.matrix.entries[r_gripper_palm_link_index].enabled[obj3_index])
Exemplo n.º 9
0
class TestCollisionObjects(unittest.TestCase):
    def test_add_convert_objects(self):

        rospy.init_node('test_collision_objects')

        obj_pub = rospy.Publisher('collision_object',
                                  CollisionObject,
                                  latch=True)
        att_pub = rospy.Publisher('attached_collision_object',
                                  AttachedCollisionObject,
                                  latch=True)

        global get_collision_objects_service_name
        full_name = default_prefix + '/' + get_collision_objects_service_name
        rospy.wait_for_service(full_name)
        get_collision_objects_service = rospy.ServiceProxy(
            full_name, arm_navigation_msgs.srv.GetCollisionObjects)

        clear_all_att = AttachedCollisionObject()
        clear_all_att.object.header.stamp = rospy.Time.now()
        clear_all_att.object.header.frame_id = "base_link"
        clear_all_att.link_name = "all"
        clear_all_att.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.REMOVE

        clear_all_obj = CollisionObject()
        clear_all_obj.header.stamp = rospy.Time.now()
        clear_all_obj.header.frame_id = "base_link"
        clear_all_obj.id = "all"
        clear_all_obj.operation.operation = mapping_msgs.msg.CollisionObjectOperation.REMOVE

        #tripling for publish wonkitude

        att_pub.publish(clear_all_att)

        obj_pub.publish(clear_all_obj)

        rospy.sleep(2.)

        get_collision_objects_req = arm_navigation_msgs.srv.GetCollisionObjectsRequest(
        )
        try:
            get_collision_objects_res = get_collision_objects_service(
                get_collision_objects_req)
        except rospy.ServiceException, e:
            print "Service call failed: %s" % e

        #should have no objects
        self.assertEquals(0, len(get_collision_objects_res.collision_objects))
        self.assertEquals(
            0, len(get_collision_objects_res.attached_collision_objects))

        # first add a couple objects to the environment

        obj1 = CollisionObject()

        obj1.header.stamp = rospy.Time.now()
        obj1.header.frame_id = "base_link"
        obj1.id = "obj1"
        obj1.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        obj1.shapes = [Shape() for _ in range(2)]
        obj1.shapes[0].type = Shape.BOX
        obj1.shapes[0].dimensions = [float() for _ in range(3)]
        obj1.shapes[0].dimensions[0] = 1.0
        obj1.shapes[0].dimensions[1] = 1.0
        obj1.shapes[0].dimensions[2] = .05
        obj1.shapes[1].type = Shape.BOX
        obj1.shapes[1].dimensions = [float() for _ in range(3)]
        obj1.shapes[1].dimensions[0] = 1.0
        obj1.shapes[1].dimensions[1] = 1.0
        obj1.shapes[1].dimensions[2] = .05
        obj1.poses = [Pose() for _ in range(2)]
        obj1.poses[0].position.x = 1.0
        obj1.poses[0].position.y = 0
        obj1.poses[0].position.z = .5
        obj1.poses[0].orientation.x = 0
        obj1.poses[0].orientation.y = 0
        obj1.poses[0].orientation.z = 0
        obj1.poses[0].orientation.w = 1
        obj1.poses[1].position.x = 1.0
        obj1.poses[1].position.y = 0
        obj1.poses[1].position.z = .75
        obj1.poses[1].orientation.x = 0
        obj1.poses[1].orientation.y = 0
        obj1.poses[1].orientation.z = 0
        obj1.poses[1].orientation.w = 1

        obj_pub.publish(obj1)

        rospy.sleep(2.)

        obj2 = CollisionObject()

        obj2.header.stamp = rospy.Time.now()
        obj2.header.frame_id = "base_link"
        obj2.id = "obj2"
        obj2.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        obj2.shapes = [Shape() for _ in range(1)]
        obj2.shapes[0].type = Shape.BOX
        obj2.shapes[0].dimensions = [float() for _ in range(3)]
        obj2.shapes[0].dimensions[0] = 1.0
        obj2.shapes[0].dimensions[1] = 1.0
        obj2.shapes[0].dimensions[2] = .05
        obj2.poses = [Pose() for _ in range(1)]
        obj2.poses[0].position.x = .15
        obj2.poses[0].position.y = 0
        obj2.poses[0].position.z = .5
        obj2.poses[0].orientation.x = 0
        obj2.poses[0].orientation.y = 0
        obj2.poses[0].orientation.z = 0
        obj2.poses[0].orientation.w = 1

        obj_pub.publish(obj2)

        rospy.loginfo("WTF")

        rospy.sleep(2.)

        get_collision_objects_req = arm_navigation_msgs.srv.GetCollisionObjectsRequest(
        )

        get_collision_objects_res = get_collision_objects_service(
            get_collision_objects_req)

        #should have two objects and no attached objects
        self.assertEquals(2, len(get_collision_objects_res.collision_objects))
        self.assertEquals(
            0, len(get_collision_objects_res.attached_collision_objects))

        conv_object = AttachedCollisionObject()
        conv_object.object.header.stamp = rospy.Time.now()
        conv_object.object.header.frame_id = "base_link"
        conv_object.link_name = "base_link"
        conv_object.object.id = "obj2"
        conv_object.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ATTACH_AND_REMOVE_AS_OBJECT
        att_pub.publish(conv_object)

        rospy.sleep(2.)

        get_collision_objects_req = arm_navigation_msgs.srv.GetCollisionObjectsRequest(
        )

        get_collision_objects_res = get_collision_objects_service(
            get_collision_objects_req)

        #should have one object non-attached and one attached
        self.assertEquals(1, len(get_collision_objects_res.collision_objects))
        self.assertEquals(
            1, len(get_collision_objects_res.attached_collision_objects))
        self.assertEquals("obj1",
                          get_collision_objects_res.collision_objects[0].id)
        self.assertEquals(
            "obj2",
            get_collision_objects_res.attached_collision_objects[0].object.id)

        #now we add attach another object directly to a different link
        att_object = AttachedCollisionObject()
        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "base_link"
        att_object.link_name = "r_gripper_r_finger_tip_link"
        att_object.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        att_object.object = CollisionObject()

        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "base_link"
        att_object.object.id = "obj3"
        att_object.object.shapes = [Shape() for _ in range(1)]
        att_object.object.shapes[0].type = Shape.BOX
        att_object.object.shapes[0].dimensions = [float() for _ in range(3)]
        att_object.object.shapes[0].dimensions[0] = .2
        att_object.object.shapes[0].dimensions[1] = 0.3
        att_object.object.shapes[0].dimensions[2] = .05
        att_object.object.poses = [Pose() for _ in range(1)]
        att_object.object.poses[0].position.x = .15
        att_object.object.poses[0].position.y = 0
        att_object.object.poses[0].position.z = 1.0
        att_object.object.poses[0].orientation.x = 0
        att_object.object.poses[0].orientation.y = 0
        att_object.object.poses[0].orientation.z = 0
        att_object.object.poses[0].orientation.w = 1
        att_pub.publish(att_object)

        rospy.sleep(2.)

        get_collision_objects_req = arm_navigation_msgs.srv.GetCollisionObjectsRequest(
        )

        get_collision_objects_res = get_collision_objects_service(
            get_collision_objects_req)

        #should have one object and two attached
        self.assertEquals(1, len(get_collision_objects_res.collision_objects))
        self.assertEquals(
            2, len(get_collision_objects_res.attached_collision_objects))
        self.assertEquals("obj1",
                          get_collision_objects_res.collision_objects[0].id)

        #deleting those attached to base link
        del_object = AttachedCollisionObject()
        del_object.object.header.stamp = rospy.Time.now()
        del_object.object.header.frame_id = "base_link"
        del_object.link_name = "base_link"
        del_object.object.id = "all"
        del_object.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.REMOVE
        att_pub.publish(del_object)

        rospy.sleep(2.)

        get_collision_objects_req = arm_navigation_msgs.srv.GetCollisionObjectsRequest(
        )

        get_collision_objects_res = get_collision_objects_service(
            get_collision_objects_req)

        #should have one object and two attached
        self.assertEquals(1, len(get_collision_objects_res.collision_objects))
        self.assertEquals(
            1, len(get_collision_objects_res.attached_collision_objects))
        self.assertEquals("obj1",
                          get_collision_objects_res.collision_objects[0].id)
        self.assertEquals(
            "obj3",
            get_collision_objects_res.attached_collision_objects[0].object.id)

        #converting back to object
        back_object = AttachedCollisionObject()
        back_object.object.header.stamp = rospy.Time.now()
        back_object.object.header.frame_id = "base_link"
        back_object.link_name = "r_gripper_r_finger_tip_link"
        back_object.object.id = "obj3"
        back_object.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.DETACH_AND_ADD_AS_OBJECT
        att_pub.publish(back_object)

        rospy.sleep(2.)

        get_collision_objects_req = arm_navigation_msgs.srv.GetCollisionObjectsRequest(
        )

        get_collision_objects_res = get_collision_objects_service(
            get_collision_objects_req)

        #should have one object and two attached
        self.assertEquals(2, len(get_collision_objects_res.collision_objects))
        self.assertEquals(
            0, len(get_collision_objects_res.attached_collision_objects))
Exemplo n.º 10
0
    def setUp(self):

        self.tf = TransformListener()

        self.move_arm_action_client = actionlib.SimpleActionClient(
            "move_right_arm", MoveArmAction)

        att_pub = rospy.Publisher('attached_collision_object',
                                  AttachedCollisionObject)
        obj_pub = rospy.Publisher('collision_object', CollisionObject)

        rospy.init_node('test_motion_execution_buffer')

        #let everything settle down
        rospy.sleep(5.)

        obj1 = CollisionObject()

        obj1.header.stamp = rospy.Time.now() - rospy.Duration(.1)
        obj1.header.frame_id = "base_footprint"
        obj1.id = "obj2"
        obj1.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        obj1.shapes = [Shape() for _ in range(3)]
        obj1.poses = [Pose() for _ in range(3)]

        obj1.shapes[0].type = Shape.BOX
        obj1.shapes[0].dimensions = [float() for _ in range(3)]
        obj1.shapes[0].dimensions[0] = .5
        obj1.shapes[0].dimensions[1] = 1.0
        obj1.shapes[0].dimensions[2] = .2
        obj1.poses[0].position.x = .95
        obj1.poses[0].position.y = -.25
        obj1.poses[0].position.z = .62
        obj1.poses[0].orientation.x = 0
        obj1.poses[0].orientation.y = 0
        obj1.poses[0].orientation.z = 0
        obj1.poses[0].orientation.w = 1

        obj1.shapes[2].type = Shape.BOX
        obj1.shapes[2].dimensions = [float() for _ in range(3)]
        obj1.shapes[2].dimensions[0] = .5
        obj1.shapes[2].dimensions[1] = .1
        obj1.shapes[2].dimensions[2] = 1.0
        obj1.poses[2].position.x = .95
        obj1.poses[2].position.y = -.14
        obj1.poses[2].position.z = 1.2
        obj1.poses[2].orientation.x = 0
        obj1.poses[2].orientation.y = 0
        obj1.poses[2].orientation.z = 0
        obj1.poses[2].orientation.w = 1

        obj1.shapes[1].type = Shape.BOX
        obj1.shapes[1].dimensions = [float() for _ in range(3)]
        obj1.shapes[1].dimensions[0] = .5
        obj1.shapes[1].dimensions[1] = .1
        obj1.shapes[1].dimensions[2] = 1.0
        obj1.poses[1].position.x = .95
        obj1.poses[1].position.y = .12
        obj1.poses[1].position.z = 1.2
        obj1.poses[1].orientation.x = 0
        obj1.poses[1].orientation.y = 0
        obj1.poses[1].orientation.z = 0
        obj1.poses[1].orientation.w = 1

        obj_pub.publish(obj1)

        att_object = AttachedCollisionObject()
        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "r_gripper_r_finger_tip_link"
        att_object.link_name = "r_gripper_r_finger_tip_link"
        att_object.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        att_object.object = CollisionObject()

        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "r_gripper_r_finger_tip_link"
        att_object.object.id = "pole"
        att_object.object.shapes = [Shape() for _ in range(1)]
        att_object.object.shapes[0].type = Shape.CYLINDER
        att_object.object.shapes[0].dimensions = [float() for _ in range(2)]
        att_object.object.shapes[0].dimensions[0] = .02
        att_object.object.shapes[0].dimensions[1] = .1
        att_object.object.poses = [Pose() for _ in range(1)]
        att_object.object.poses[0].position.x = -.02
        att_object.object.poses[0].position.y = .04
        att_object.object.poses[0].position.z = 0
        att_object.object.poses[0].orientation.x = 0
        att_object.object.poses[0].orientation.y = 0
        att_object.object.poses[0].orientation.z = 0
        att_object.object.poses[0].orientation.w = 1

        att_pub.publish(att_object)

        rospy.sleep(5.0)
Exemplo n.º 11
0
    def test_attached_object_collision_operations(self):

        global set_allowed_collision_service_name
        global get_allowed_collision_service_name
        global revert_allowed_collision_service_name
        full_name = default_prefix + '/' + set_allowed_collision_service_name
        rospy.wait_for_service(full_name)
        set_allowed_collision_service_proxy = rospy.ServiceProxy(
            full_name, arm_navigation_msgs.srv.SetAllowedCollisions)

        full_name = default_prefix + '/' + get_allowed_collision_service_name
        rospy.wait_for_service(full_name)
        get_allowed_collision_service_proxy = rospy.ServiceProxy(
            full_name, arm_navigation_msgs.srv.GetAllowedCollisionMatrix)

        full_name = default_prefix + '/' + revert_allowed_collision_service_name
        rospy.wait_for_service(full_name)
        revert_allowed_collision_service_proxy = rospy.ServiceProxy(
            full_name, std_srvs.srv.Empty)

        att_pub = rospy.Publisher('attached_collision_object',
                                  AttachedCollisionObject)

        rospy.init_node('test_allowed_collisions')

        att_object = AttachedCollisionObject()
        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "base_link"
        att_object.link_name = "r_gripper_r_finger_tip_link"
        att_object.touch_links = [str() for _ in range(1)]
        att_object.touch_links[0] = "r_gripper_palm_link"
        att_object.object.operation.operation = mapping_msgs.msg.CollisionObjectOperation.ADD
        att_object.object = CollisionObject()

        att_object.object.header.stamp = rospy.Time.now()
        att_object.object.header.frame_id = "base_link"
        att_object.object.id = "obj3"
        att_object.object.shapes = [Shape() for _ in range(1)]
        att_object.object.shapes[0].type = Shape.BOX
        att_object.object.shapes[0].dimensions = [float() for _ in range(3)]
        att_object.object.shapes[0].dimensions[0] = .2
        att_object.object.shapes[0].dimensions[1] = 0.3
        att_object.object.shapes[0].dimensions[2] = .05
        att_object.object.poses = [Pose() for _ in range(1)]
        att_object.object.poses[0].position.x = .15
        att_object.object.poses[0].position.y = 0
        att_object.object.poses[0].position.z = 1.0
        att_object.object.poses[0].orientation.x = 0
        att_object.object.poses[0].orientation.y = 0
        att_object.object.poses[0].orientation.z = 0
        att_object.object.poses[0].orientation.w = 1
        att_pub.publish(att_object)

        rospy.sleep(5.0)

        get_mat = arm_navigation_msgs.srv.GetAllowedCollisionMatrixRequest()

        get_res = get_allowed_collision_service_proxy(get_mat)

        try:
            r_gripper_palm_link_index = get_res.matrix.link_names.index(
                "r_gripper_palm_link")
        except ValueError:
            self.fail(
                "No r_gripper_palm_link in AllowedCollisionMatrix link names")

        try:
            r_gripper_r_finger_tip_link_index = get_res.matrix.link_names.index(
                "r_gripper_r_finger_tip_link")
        except ValueError:
            self.fail(
                "No r_gripper_r_finger_tip_link in AllowedCollisionMatrix link names"
            )

        try:
            obj3_index = get_res.matrix.link_names.index("obj3")
        except ValueError:
            self.fail("No obj3 in AllowedCollisionMatrix link names")

        self.assertEqual(
            True, get_res.matrix.entries[obj3_index].
            enabled[r_gripper_r_finger_tip_link_index])
        self.assertEqual(
            True, get_res.matrix.entries[r_gripper_r_finger_tip_link_index].
            enabled[obj3_index])

        self.assertEqual(
            True, get_res.matrix.entries[obj3_index].
            enabled[r_gripper_palm_link_index])
        self.assertEqual(
            True, get_res.matrix.entries[r_gripper_palm_link_index].
            enabled[obj3_index])

        #this should overwrite touch links
        set_allowed_request = arm_navigation_msgs.srv.SetAllowedCollisionsRequest(
        )
        set_allowed_request.ord.collision_operations = [
            CollisionOperation() for _ in range(1)
        ]
        set_allowed_request.ord.collision_operations[0].object1 = "obj3"
        set_allowed_request.ord.collision_operations[
            0].object2 = "r_gripper_palm_link"
        set_allowed_request.ord.collision_operations[
            0].operation = CollisionOperation.ENABLE

        set_allowed_collision_service_proxy(set_allowed_request)

        rospy.sleep(1.)

        get_res = get_allowed_collision_service_proxy(get_mat)

        self.assertEqual(
            False, get_res.matrix.entries[obj3_index].
            enabled[r_gripper_palm_link_index])
        self.assertEqual(
            False, get_res.matrix.entries[r_gripper_palm_link_index].
            enabled[obj3_index])

        set_allowed_request.ord.collision_operations[
            0].object1 = "r_gripper_palm_link"
        set_allowed_request.ord.collision_operations[
            0].object2 = CollisionOperation.COLLISION_SET_ATTACHED_OBJECTS
        set_allowed_request.ord.collision_operations[
            0].operation = CollisionOperation.DISABLE

        set_allowed_collision_service_proxy(set_allowed_request)

        rospy.sleep(1.)

        get_res = get_allowed_collision_service_proxy(get_mat)

        self.assertEqual(
            True, get_res.matrix.entries[obj3_index].
            enabled[r_gripper_palm_link_index])
        self.assertEqual(
            True, get_res.matrix.entries[r_gripper_palm_link_index].
            enabled[obj3_index])