Exemplo n.º 1
0
    def get_sdf_model(
            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/ElteHupkes/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
Exemplo n.º 2
0
    def get_sdf_model(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/ElteHupkes/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
Exemplo n.º 3
0
def gen_boxes(model_name,
              dimensions=4,
              spacing=0.5,
              size=0.05,
              height=0.015,
              center_sq=1):
    model = Model(model_name, static=True)
    for x in range(-dimensions, dimensions + 1):
        for y in range(-dimensions, dimensions + 1):
            l = Link("box")
            if (abs(x) >= center_sq or abs(y) >= center_sq):
                l.make_box(1, size, size, height)
            pos = Vector3(spacing * x, spacing * y, height / 2)
            l.set_position(pos)
            #l.rotate_around(Vector3(0, 0, 1), math.radians(x*y), relative_to_child=False)
            model.add_element(l)
    return model
Exemplo n.º 4
0
def gen_steps(model_name,
              num_steps=6,
              offset=0.4,
              height=0.02,
              width=3.0,
              depth=0.2,
              incline=0):
    model = Model(model_name, static=True)
    steps = PosableGroup()
    for x in range(0, num_steps):
        l = Link("box")
        l.make_box(1, depth, width, height)
        pos = Vector3(offset + depth * x, 0, height / 2 + x * height)
        l.set_position(pos)
        steps.add_element(l)

    for x in range(0, 4):
        steps.set_rotation(
            Quaternion.from_rpy(0, math.radians(-incline),
                                math.radians(90 * x)))
        model.add_element(steps.copy())

    return model
Exemplo n.º 5
0
from sdfbuilder import Link, SDF, Model
from sdfbuilder.structure import Collision, Visual, Box, StructureCombination
from sdfbuilder.math import Vector3
import math

from tol.build.builder import apply_surface_parameters

MASS = in_grams(3)
SENSOR_BASE_WIDTH = in_mm(34)
SENSOR_BASE_THICKNESS = in_mm(1.5)
SENSOR_THICKNESS = in_mm(9)
SENSOR_WIDTH = in_mm(18.5)
SENSOR_HEIGHT = in_mm(16)
SEPARATION = in_mm(1)

m = Model(name="mybot")
sdf = SDF(elements=[m])

geom = Box(SENSOR_BASE_THICKNESS, SENSOR_BASE_WIDTH, SENSOR_BASE_WIDTH, MASS)
base = StructureCombination("base", geom)

x_sensors = 0.5 * (SENSOR_BASE_THICKNESS + SENSOR_THICKNESS)
y_left_sensor = -0.5 * SENSOR_WIDTH - SEPARATION
y_right_sensor = 0.5 * SENSOR_WIDTH + SEPARATION

left = StructureCombination("left", Box(SENSOR_THICKNESS, SENSOR_WIDTH, SENSOR_HEIGHT, MASS))
left.set_position(Vector3(x_sensors, y_left_sensor, 0))

right = StructureCombination("right", Box(SENSOR_THICKNESS, SENSOR_WIDTH, SENSOR_HEIGHT, MASS))
right.set_position(Vector3(x_sensors, y_right_sensor, 0))
Exemplo n.º 6
0
from __future__ import print_function
import sys
from sdfbuilder import Link, Model, SDF
from sdfbuilder.math import Vector3
from sdfbuilder.structure import Box, Cylinder, Collision, Visual, StructureCombination

import math

sdf = SDF()
model = Model("obstacles",static=True)


def gen_boxes(dimensions=4, spacing=0.5, size=0.05):
        for x in range(-dimensions,dimensions+1):
            for y in range(-dimensions,dimensions+1):
                l = Link("box")

                #box_geom = Box(1.0, 1.0, 1.0, mass=0.5)
                #b = StructureCombination("box", box_geom)
                #l.add_element(b)

                if (x!=0 or y!=0):
                    l.make_box(1, size, size, 0.01*max(abs(x),abs(y)))

                pos = Vector3(spacing*x,spacing*y,0)

                l.set_position(pos)
                l.rotate_around(Vector3(0, 0, 1), math.radians(x*y), relative_to_child=False)

                model.add_element(l)
Exemplo n.º 7
0
from __future__ import print_function
import sys
from sdfbuilder import Link, Model, SDF
from sdfbuilder.math import Vector3

# Create two similar boxes
link1 = Link("box1")
link1.make_box(1.0, 0.1, 0.3, 0.5)

link2 = Link("box2")
link2.make_box(1.0, 0.1, 0.3, 0.5)

# Align the top of box2 with the front of box1
link2.align(Vector3(0, 0, 0.25), Vector3(0, 0, -1), Vector3(1, 0, 0),
            Vector3(0, -0.15, 0), Vector3(0, 1, 0), Vector3(0, 0, 1), link1)

if __name__ == '__main__':
    sdf = SDF()
    model = Model("my_model")
    model.add_element(link1)
    model.add_element(link2)
    sdf.add_element(model)
    print(str(sdf))
Exemplo n.º 8
0
group.align(
    # Center of the right face of box 1
    Vector3(1, 0, 0),

    # Vector normal to box 2 right face
    Vector3(1, 0, 0),

    # Vector normal to box 2 top face should align with...(*)
    Vector3(0, 0, 1),

    # Center of the top face of box 2
    Vector3(0, 0, 1.5),

    # Vector normal to box 2 top face
    Vector3(0, 0, 1),

    # (*)...vector normal to box 2 right face
    Vector3(1, 0, 0),

    # the link to align with
    link2
)

if __name__ == '__main__':
    sdf = SDF()
    model = Model("my_model")
    model.add_element(group)
    model.add_element(link2)
    sdf.add_element(model)
    print(str(sdf))
Exemplo n.º 9
0
# the collision elements.
link.align_center_of_mass()
link.calculate_inertial()

# Rotate the link 45 degrees around the x-axis, specified in the parent frame
# just to demonstrate how that works (and to demonstrate align is still
# going to work after the rotation).
link.rotate_around(Vector3(1, 0, 0), math.radians(45), relative_to_child=False)

# Okay, not sure what this is supposed to be, but let's another wheel-like cylinder in
# a new link, and connect them with joints
wheel_geom = Cylinder(0.75, 0.1, mass=0.1)
wheel = StructureCombination("wheel", wheel_geom)
wheel_link = Link("my_wheel", elements=[wheel])

attachment_point = Vector3(0, 0, 0.5 * wheel_geom.length)
wheel_link.align(attachment_point, Vector3(0, 0, 1), Vector3(0, 1, 0),
                 Vector3(0, 0, 0.5 * box_geom.size[0] + cyl_geom.length),
                 Vector3(0, 0, 1), Vector3(1, 0, 0), link)

# Create a joint link, and set its position (which is in the child frame)
joint = Joint("revolute", link, wheel_link, axis=Vector3(0, 0, 1))
joint.set_position(attachment_point)

# Create a model and a wrapping SDF element, and output
# Move the model up so it won't intersect with the ground when inserted.
model = Model("my_robot", elements=[link, wheel_link, joint])
model.set_position(Vector3(0, 0, math.sqrt(0.5)))
sdf = SDF(elements=[model])
print(str(sdf))
Exemplo n.º 10
0
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__))+'/../')

import trollius
from trollius import From
from tol.config import Config
from tol.manage import World

from sdfbuilder import SDF, Link, Model
from sdfbuilder.sensor import Sensor

conf = Config(visualize_sensors=True)

sdf = SDF()
model = Model("crash")
link = Link("my_link")
link.make_box(1.0, 1, 1, 1)
sensor = Sensor("sense", "contact")
link.add_element(sensor)
model.add_element(link)
sdf.add_element(model)
model.set_position(Vector3(0, 0, 0.5))


@trollius.coroutine
def run_server():
    world = yield From(World.create(conf))

    counter = 0
    while True:
Exemplo n.º 11
0
# the collision elements.
link.align_center_of_mass()
link.calculate_inertial()

# Rotate the link 45 degrees around the x-axis, specified in the parent frame
# just to demonstrate how that works (and to demonstrate align is still
# going to work after the rotation).
link.rotate_around(Vector3(1, 0, 0), math.radians(45), relative_to_child=False)

# Okay, not sure what this is supposed to be, but let's another wheel-like cylinder in
# a new link, and connect them with joints
wheel_geom = Cylinder(0.75, 0.1, mass=0.1)
wheel = StructureCombination("wheel", wheel_geom)
wheel_link = Link("my_wheel", elements=[wheel])

attachment_point = Vector3(0, 0, 0.5 * wheel_geom.length)
wheel_link.align(attachment_point, Vector3(0, 0, 1), Vector3(0, 1, 0),
                 Vector3(0, 0, 0.5 * box_geom.size[0] + cyl_geom.length),
                 Vector3(0, 0, 1), Vector3(1, 0, 0), link)

# Create a joint link, and set its position (which is in the child frame)
joint = Joint("revolute", link, wheel_link, axis=Vector3(0, 0, 1))
joint.set_position(attachment_point)

# Create a model and a wrapping SDF element, and output
# Move the model up so it won't intersect with the ground when inserted.
model = Model("my_robot", elements=[link, wheel_link, joint])
model.set_position(Vector3(0, 0, math.sqrt(0.5)))
sdf = SDF(elements=[model])
print(str(sdf))
Exemplo n.º 12
0
from sdfbuilder import Link, Model, SDF
from sdfbuilder.math import Vector3

# Create two similar boxes
link1 = Link("box1")
link1.make_box(1.0, 0.1, 0.3, 0.5)

link2 = Link("box2")
link2.make_box(1.0, 0.1, 0.3, 0.5)

# Align the top of box2 with the front of box1
link2.align(
    Vector3(0, 0, 0.25),
    Vector3(0, 0, -1),
    Vector3(1, 0, 0),

    Vector3(0, -0.15, 0),
    Vector3(0, 1, 0),
    Vector3(0, 0, 1),

    link1
)

if __name__ == '__main__':
    sdf = SDF()
    model = Model("my_model")
    model.add_element(link1)
    model.add_element(link2)
    sdf.add_element(model)
    print(str(sdf))
Exemplo n.º 13
0
# the top center of link 2
group.align(
    # Center of the right face of box 1
    Vector3(1, 0, 0),

    # Vector normal to box 2 right face
    Vector3(1, 0, 0),

    # Vector normal to box 2 top face should align with...(*)
    Vector3(0, 0, 1),

    # Center of the top face of box 2
    Vector3(0, 0, 1.5),

    # Vector normal to box 2 top face
    Vector3(0, 0, 1),

    # (*)...vector normal to box 2 right face
    Vector3(1, 0, 0),

    # the link to align with
    link2)

if __name__ == '__main__':
    sdf = SDF()
    model = Model("my_model")
    model.add_element(group)
    model.add_element(link2)
    sdf.add_element(model)
    print(str(sdf))