def setup_scene(rbt, config): if config["with_ground"] is True: AddFlatTerrainToWorld(rbt) for i, instance_config in enumerate(config["instances"]): add_single_instance_to_rbt(rbt, config, instance_config, i, floating_base_type=FloatingBaseType.kFixed) # Add camera geometry! camera_link = RigidBody() camera_link.set_name("camera_link") # necessary so this last link isn't pruned by the rbt.compile() call camera_link.set_spatial_inertia(np.eye(6)) camera_link.add_joint( rbt.world(), RollPitchYawFloatingJoint("camera_floating_base", np.eye(4))) rbt.add_rigid_body(camera_link) # - Add frame for camera fixture. camera_frame = RigidBodyFrame(name="rgbd_camera_frame", body=camera_link, xyz=[0.0, 0., 0.], rpy=[0., 0., 0.]) rbt.addFrame(camera_frame) rbt.compile()
def test_rigid_body_api(self): # Tests as much of the RigidBody API as is possible in isolation. # Adding collision geometry is *not* tested here, as it needs to # be done in the context of the RigidBodyTree. body = RigidBody() name = "body" body.set_name(name) self.assertEqual(body.get_name(), name) inertia = np.eye(6) body.set_spatial_inertia(inertia) self.assertTrue(np.allclose(inertia, body.get_spatial_inertia())) # Try adding a joint to a dummy body. body_joint = PrismaticJoint("z", np.eye(4), np.array([0., 0., 1.])) self.assertFalse(body.has_joint()) dummy_body = RigidBody() body.add_joint(dummy_body, body_joint) self.assertEqual(body.getJoint(), body_joint) self.assertTrue(body.has_joint()) # Try adding visual geometry. box_element = shapes.Box([1.0, 1.0, 1.0]) box_visual_element = shapes.VisualElement(box_element, np.eye(4), [1., 0., 0., 1.]) body.AddVisualElement(box_visual_element) body_visual_elements = body.get_visual_elements() self.assertEqual(len(body_visual_elements), 1) self.assertEqual(body_visual_elements[0].getGeometry().getShape(), box_visual_element.getGeometry().getShape()) # Test collision-related methods. self.assertEqual(body.get_num_collision_elements(), 0) self.assertEqual(len(body.get_collision_element_ids()), 0)
def test_rigid_body_api(self): # Tests as much of the RigidBody API as is possible in isolation. # Adding collision geometry is *not* tested here, as it needs to # be done in the context of the RigidBodyTree. body = RigidBody() name = "body" body.set_name(name) self.assertEqual(body.get_name(), name) inertia = np.eye(6) body.set_spatial_inertia(inertia) self.assertTrue(np.allclose(inertia, body.get_spatial_inertia())) # Try adding a joint to a dummy body. body_joint = PrismaticJoint("z", np.eye(4), np.array([0., 0., 1.])) self.assertFalse(body.has_joint()) dummy_body = RigidBody() body.add_joint(dummy_body, body_joint) self.assertEqual(body.getJoint(), body_joint) self.assertTrue(body.has_joint()) # Try adding visual geometry. box_element = shapes.Box([1.0, 1.0, 1.0]) box_visual_element = shapes.VisualElement( box_element, np.eye(4), [1., 0., 0., 1.]) body.AddVisualElement(box_visual_element) body_visual_elements = body.get_visual_elements() self.assertEqual(len(body_visual_elements), 1) self.assertEqual(body_visual_elements[0].getGeometry().getShape(), box_visual_element.getGeometry().getShape()) # Test collision-related methods. self.assertEqual(body.get_num_collision_elements(), 0) self.assertEqual(len(body.get_collision_element_ids()), 0)