Пример #1
0
def geometryFromAffordance(aff):

    if isinstance(aff, affordanceitems.SphereAffordanceItem):
        radius = aff.getProperty('Radius')
        return urdf.Sphere(radius=radius)

    if isinstance(aff, affordanceitems.BoxAffordanceItem):
        dimensions = aff.getProperty('Dimensions')
        return urdf.Box(size=dimensions)

    if isinstance(aff, affordanceitems.CylinderAffordanceItem):
        return urdf.Cylinder(length=aff.getProperty('Length'),
                             radius=aff.getProperty('Radius'))

    if isinstance(aff, affordanceitems.CapsuleAffordanceItem):
        return urdf.Cylinder(length=aff.getProperty('Length'),
                             radius=aff.getProperty('Radius'))

    if isinstance(aff, affordanceitems.CapsuleRingAffordanceItem):
        raise Exception('not supported yet')

    if isinstance(aff, affordanceitems.MeshAffordanceItem):
        filename = aff.getProperty('Filename')
        filename = affordanceitems.MeshAffordanceItem.getMeshManager(
        ).getFilesystemFilename(filename)
        return urdf.Mesh(filename=filename, scale=[1.0, 1.0, 1.0])
Пример #2
0
 def from_world_body(cls, world_body, *args, **kwargs):
     """
     :type world_body: giskard_msgs.msg._WorldBody.WorldBody
     :rtype: URDFObject
     """
     links = []
     joints = []
     if world_body.type == world_body.PRIMITIVE_BODY or world_body.type == world_body.MESH_BODY:
         if world_body.shape.type == world_body.shape.BOX:
             geometry = up.Box(world_body.shape.dimensions)
         elif world_body.shape.type == world_body.shape.SPHERE:
             geometry = up.Sphere(world_body.shape.dimensions[0])
         elif world_body.shape.type == world_body.shape.CYLINDER:
             geometry = up.Cylinder(
                 world_body.shape.dimensions[
                     world_body.shape.CYLINDER_RADIUS],
                 world_body.shape.dimensions[
                     world_body.shape.CYLINDER_HEIGHT])
         elif world_body.shape.type == world_body.shape.CONE:
             raise TypeError(u'primitive shape cone not supported')
         elif world_body.type == world_body.MESH_BODY:
             geometry = up.Mesh(world_body.mesh)
         else:
             raise CorruptShapeException(
                 u'primitive shape \'{}\' not supported'.format(
                     world_body.shape.type))
         # FIXME test if this works on 16.04
         try:
             link = up.Link(world_body.name)
             link.add_aggregate(
                 u'visual',
                 up.Visual(geometry,
                           material=up.Material(u'green',
                                                color=up.Color(0, 1, 0,
                                                               1))))
             link.add_aggregate(u'collision', up.Collision(geometry))
         except AssertionError:
             link = up.Link(world_body.name,
                            visual=up.Visual(geometry,
                                             material=up.Material(
                                                 u'green',
                                                 color=up.Color(0, 1, 0,
                                                                1))),
                            collision=up.Collision(geometry))
         links.append(link)
     elif world_body.type == world_body.URDF_BODY:
         o = cls(world_body.urdf, *args, **kwargs)
         o.set_name(world_body.name)
         return o
     else:
         raise CorruptShapeException(
             u'world body type \'{}\' not supported'.format(
                 world_body.type))
     return cls.from_parts(world_body.name, links, joints, *args, **kwargs)
Пример #3
0
 def from_object_state(cls, object_state, *args, **kwargs):
     """
     :type world_body: knowrob_objects.msg._ObjectState.ObjectState
     :rtype: URDFObject
     """
     links = []
     joints = []
     shape = [object_state.size.y,
              object_state.size.x,
              object_state.size.z]
     if object_state.has_visual and object_state.mesh_path == u'':
         geometry = up.Box(shape)
     elif object_state.has_visual:
         geometry = up.Mesh(object_state.mesh_path)
     else:
         raise CorruptShapeException(u'object state has no visual')
     link = up.Link(object_state.object_id,
                    visual=up.Visual(geometry, material=up.Material(u'green', color=up.Color(0, 1, 0, 1))),
                    collision=up.Collision(geometry))
     links.append(link)
     return cls.from_parts(object_state.object_id, links, joints, *args, **kwargs)