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
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
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
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
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)) link = Link("my_link") link.add_elements([base, left, right]) link.align_center_of_mass() link.calculate_inertial() m.add_element(link) apply_surface_parameters(m) m.translate(Vector3(0, 0, in_mm(30))) with open("/home/elte/.gazebo/models/test_bot/model.sdf", "w") as f: f.write(str(sdf))
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))
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))
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: model.name = "test_bot_%d" % counter print("Inserting %s..." % model.name) fut = yield From(world.insert_model(sdf)) yield From(fut) print("Done. Waiting...")
# 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))