Exemple #1
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)
    def test_robot_material(self):
        xml = '''<?xml version="1.0"?>
<robot name="test" version="1.0">
  <material name="mat">
    <color rgba="0.0 0.0 0.0 1.0"/>
  </material>
</robot>'''
        self.parse_and_compare(xml)

        robot = urdf.Robot(name='test', version='1.0')
        material = urdf.Material(name='mat', color=urdf.Color([0.0, 0.0, 0.0, 1.0]))
        robot.add_aggregate('material', material)
        self.xml_and_compare(robot, xml)
Exemple #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)
Exemple #4
0
def colorFromAffordance(aff):
    color = aff.getProperty('Color')
    return urdf.Color(color[0], color[1], color[2], 1)
Exemple #5
0
def black():
    col_black = urdf.Material(name="black", color=urdf.Color([0, 0, 0, 1.0]))
    return col_black
Exemple #6
0
def orange():
    col_orange = urdf.Material(
        name="orange",
        color=urdf.Color([1.0, 0.423529411765, 0.0392156862745, 1.0]))
    return col_orange
def white():
    col_white = urdf.Material(name="white",
                              color=urdf.Color([1.0, 1.0, 1.0, 1.0]))
    return col_white