コード例 #1
0
ファイル: light_sensor.py プロジェクト: wakeupppp/revolve
    def _initialize(self, **kwargs):
        """
        :param kwargs:
        :return:
        """
        self.mass = MASS
        self.x = SENSOR_BASE_THICKNESS
        self.y = self.z = SENSOR_BASE_WIDTH
        super(LightSensor, self)._initialize(**kwargs)

        # Add the SDF camera sensor
        camera = SdfSensor(
                name="{}_light_sensor".format(self.id),
                sensor_type="camera",
                update_rate=self.conf.sensor_update_rate)

        # TODO: Set field of view
        cam_details = "<camera>" \
                      "<image>" \
                      "<width>1</width><height>1</height>" \
                      "</image>" \
                      "<clip><near>{}</near><far>{}</far></clip>" \
                      "</camera>".format(nf(in_mm(1)), nf(in_mm(50000)))
        camera.add_element(cam_details)
        camera.set_position(Vector3(0.5 * self.x, 0, 0))
        self.component.add_sensor(camera, "light")

        if self.conf.visualize_sensors:
            camera.add_element("<visualize>1</visualize>")

        self.apply_color()
コード例 #2
0
ファイル: util.py プロジェクト: wakeupppp/revolve
def apply_surface_parameters(model, intended_step_size=0.005):
    """
    Applies surface parameters to all collisions in the given model.
    :param model:
    :type model: Model
    :param intended_step_size:
    :return:
    """
    surface_kd = SURFACE_ERP / (SURFACE_CFM * intended_step_size)
    surface_kp = 1.0 / SURFACE_CFM - (SURFACE_ERP / SURFACE_CFM)

    # Add friction surfaces to all body parts
    surf = Element(tag_name="surface")
    friction = Friction(friction=SURFACE_FRICTION1,
                        friction2=SURFACE_FRICTION2,
                        slip1=SURFACE_SLIP1,
                        slip2=SURFACE_SLIP2)
    contact = "<contact>" \
              "<ode>" \
              "<kd>{}</kd>" \
              "<kp>{}</kp>" \
              "</ode>" \
              "</contact>".format(
                  nf(surface_kd), nf(surface_kp)
              )

    surf.add_element(contact)
    surf.add_element(friction)

    collisions = model.get_elements_of_type(Collision, recursive=True)
    for collision in collisions:
        collision.add_element(surf)
コード例 #3
0
ファイル: util.py プロジェクト: ci-group/revolve
def apply_surface_parameters(model, intended_step_size=0.005):
    """
    Applies surface parameters to all collisions in the given model.
    :param model:
    :type model: Model
    :param intended_step_size:
    :return:
    """
    surface_kd = SURFACE_ERP / (SURFACE_CFM * intended_step_size)
    surface_kp = 1.0 / SURFACE_CFM - (SURFACE_ERP / SURFACE_CFM)

    # Add friction surfaces to all body parts
    surf = Element(tag_name="surface")
    friction = Friction(
        friction=SURFACE_FRICTION1,
        friction2=SURFACE_FRICTION2,
        slip1=SURFACE_SLIP1,
        slip2=SURFACE_SLIP2
    )
    contact = "<contact>" \
              "<ode>" \
              "<kd>{}</kd>" \
              "<kp>{}</kp>" \
              "</ode>" \
              "</contact>".format(
                  nf(surface_kd), nf(surface_kp)
              )

    surf.add_element(contact)
    surf.add_element(friction)

    collisions = model.get_elements_of_type(Collision, recursive=True)
    for collision in collisions:
        collision.add_element(surf)
コード例 #4
0
 def render_attributes(self):
     """
     :return:
     """
     attrs = super(VelocityMotor, self).render_attributes()
     attrs.update({
         'min_velocity': nf(self.min_velocity),
         'max_velocity': nf(self.max_velocity)
     })
     return attrs
コード例 #5
0
ファイル: birth_clinic.py プロジェクト: wakeupppp/revolve
    def __init__(self, diameter=3.0, height=3.0, name="birth_clinic"):
        """

        :param diameter: Intended diameter of the birth clinic
        :param name:
        :return:
        """
        super(BirthClinic, self).__init__(name=name, static=True)

        self.diameter = diameter
        scale = diameter / MESH_DIAMETER

        # Cannot go higher than mesh height, or lower than the bottom
        # of the slice.
        scaled_height = scale * MESH_HEIGHT
        self.height = max(arg1=min(height, scaled_height),
                          arg2=(SLICE_FRACTION * scaled_height))

        mesh = Mesh("model://tol_arena/meshes/BirthClinic.dae", scale=scale)

        col = Collision("bc_col", mesh)
        surf = Element(tag_name="surface")
        friction = Friction(
            friction=0.01,
            friction2=0.01,
            slip1=1.0,
            slip2=1.0
        )
        contact = "<contact>" \
                  "<ode>" \
                  "<kd>%s</kd>" \
                  "<kp>%s</kp>" \
                  "</ode>" \
                  "</contact>" % (
                      nf(constants.SURFACE_KD), nf(constants.SURFACE_KP)
                  )
        surf.add_element(friction)
        surf.add_element(contact)
        col.add_element(surf)

        vis = Visual("bc_vis", mesh.copy())
        self.link = Link("bc_link", elements=[col, vis])

        # By default the model has 0.5 * scale * MESH_HEIGHT below
        # and above the surface. Translate such that we have exactly
        # the desired height instead.
        self.link.translate(Vector3(0, 0, self.height - (0.5 * scaled_height)))
        self.add_element(self.link)
コード例 #6
0
ファイル: birth_clinic.py プロジェクト: ci-group/revolve
    def __init__(self, diameter=3.0, height=3.0, name="birth_clinic"):
        """

        :param diameter: Intended diameter of the birth clinic
        :param name:
        :return:
        """
        super(BirthClinic, self).__init__(name=name, static=True)

        self.diameter = diameter
        scale = diameter / MESH_DIAMETER

        # Cannot go higher than mesh height, or lower than the bottom
        # of the slice.
        scaled_height = scale * MESH_HEIGHT
        self.height = max(arg1=min(height, scaled_height),
                          arg2=(SLICE_FRACTION * scaled_height))

        mesh = Mesh("model://tol_arena/meshes/BirthClinic.dae", scale=scale)

        col = Collision("bc_col", mesh)
        surf = Element(tag_name="surface")
        friction = Friction(
            friction=0.01,
            friction2=0.01,
            slip1=1.0,
            slip2=1.0
        )
        contact = "<contact>" \
                  "<ode>" \
                  "<kd>%s</kd>" \
                  "<kp>%s</kp>" \
                  "</ode>" \
                  "</contact>" % (
                      nf(constants.SURFACE_KD), nf(constants.SURFACE_KP)
                  )
        surf.add_element(friction)
        surf.add_element(contact)
        col.add_element(surf)

        vis = Visual("bc_vis", mesh.copy())
        self.link = Link("bc_link", elements=[col, vis])

        # By default the model has 0.5 * scale * MESH_HEIGHT below
        # and above the surface. Translate such that we have exactly
        # the desired height instead.
        self.link.translate(Vector3(0, 0, self.height - (0.5 * scaled_height)))
        self.add_element(self.link)
コード例 #7
0
    def render_elements(self):
        """

        :return:
        """
        elms = super(BasicBattery, self).render_elements()
        return elms + [Element(tag_name="rv:level", body=nf(self.level))]
コード例 #8
0
    def sdf_robot(self,
                  robot,
                  controller_plugin=None,
                  update_rate=5,
                  name="sdf_robot",
                  analyzer_mode=False,
                  battery=None,
                  brain_conf=None):
        """
        :param robot: Protobuf robot
        :type robot: Robot
        :param controller_plugin: Name of the shared library of the model plugin
        :type controller_plugin: str|none
        :param update_rate: Update rate as used by the default controller
        :type update_rate: float
        :param name: Name of the SDF model
        :type name: str
        :param analyzer_mode:
        :type analyzer_mode: bool
        :param battery: A Battery element to be added to the plugin if
                        applicable.
        :type battery: Element
        :param brain_conf: Brain configuration data
        :type brain_conf: dict
        :return: The sdf-builder Model
        :rtype: Model
        """
        model = Model(name)

        # Create the model plugin element
        plugin = Element(tag_name='plugin',
                         attributes={
                             'name': 'robot_controller',
                             'filename': controller_plugin
                         })

        # Add body config element
        config = Element(
            tag_name='rv:robot_config',
            attributes={'xmlns:rv': 'https://github.com/ci-group/revolve'})
        config.add_element(
            Element(tag_name='rv:update_rate', body=nf(update_rate)))
        plugin.add_element(config)

        # Add brain config element
        brain_config = Element(tag_name='rv:brain', attributes=brain_conf)
        config.add_element(brain_config)

        self.brain_builder.build(robot, model, brain_config, analyzer_mode)
        self.body_builder.build(robot, model, config, analyzer_mode)

        if battery:
            config.add_element(battery)

        if controller_plugin:
            # Only add the plugin element when required
            model.add_element(plugin)

        return model
コード例 #9
0
    def render_elements(self):
        sub = []
        for attr in ['p', 'i', 'd', 'i_max', 'i_min', 'cmd_max', 'cmd_min']:
            v = getattr(self, attr, None)
            if v is not None:
                sub.append(Element(tag_name='rv:' + attr, body=nf(v)))

        return super(PID, self).render_elements() + sub
コード例 #10
0
ファイル: neuron.py プロジェクト: ci-group/revolve
 def render_elements(self):
     """
     Adds attributes as elements
     """
     elms = [Element(
             tag_name='rv:'+param,
             body=nf(self.params[param])) for param in self.params]
     return super(Neuron, self).render_elements() + elms
コード例 #11
0
ファイル: neuron.py プロジェクト: wakeupppp/revolve
 def render_elements(self):
     """
     Adds attributes as elements
     """
     elms = [
         Element(tag_name='rv:' + param, body=nf(self.params[param]))
         for param in self.params
     ]
     return super(Neuron, self).render_elements() + elms
コード例 #12
0
ファイル: neuron.py プロジェクト: wakeupppp/revolve
    def render_attributes(self):
        """
        """
        attrs = super(NeuralConnection, self).render_attributes()
        attrs.update({
            'src': self.conn.src,
            'dst': self.conn.dst,
            'weight': nf(self.conn.weight)
        })

        return attrs
コード例 #13
0
ファイル: neuron.py プロジェクト: ci-group/revolve
    def render_attributes(self):
        """
        """
        attrs = super(NeuralConnection, self).render_attributes()
        attrs.update({
            'src': self.conn.src,
            'dst': self.conn.dst,
            'weight': nf(self.conn.weight)
        })

        return attrs
コード例 #14
0
ファイル: builder.py プロジェクト: ci-group/revolve
    def sdf_robot(
            self,
            robot,
            controller_plugin=None,
            update_rate=5,
            name="sdf_robot",
            analyzer_mode=False,
            battery=None,
            brain_conf=None
    ):
        """
        :param robot: Protobuf robot
        :type robot: Robot
        :param controller_plugin: Name of the shared library of the model plugin
        :type controller_plugin: str|none
        :param update_rate: Update rate as used by the default controller
        :type update_rate: float
        :param name: Name of the SDF model
        :type name: str
        :param analyzer_mode:
        :type analyzer_mode: bool
        :param battery: A Battery element to be added to the plugin if
                        applicable.
        :type battery: Element
        :param brain_conf: Brain configuration data
        :type brain_conf: dict
        :return: The sdf-builder Model
        :rtype: Model
        """
        model = Model(name)

        # Create the model plugin element
        plugin = Element(
                tag_name='plugin',
                attributes={
                    'name': 'robot_controller',
                    'filename': controller_plugin
                })

        # Add body config element
        config = Element(
                tag_name='rv:robot_config',
                attributes={
                    'xmlns:rv': 'https://github.com/ci-group/revolve'
                })
        config.add_element(Element(
                tag_name='rv:update_rate',
                body=nf(update_rate)))
        plugin.add_element(config)

        # Add brain config element
        brain_config = Element(
                tag_name='rv:brain',
                attributes=brain_conf)
        config.add_element(brain_config)

        self.brain_builder.build(robot, model, brain_config, analyzer_mode)
        self.body_builder.build(robot, model, config, analyzer_mode)

        if battery:
            config.add_element(battery)

        if controller_plugin:
            # Only add the plugin element when required
            model.add_element(plugin)

        return model