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))
# Minibox is... well, a mini box minibox.make_box(0.1, 0.2, 0.2, 0.2) minibox.align( # Bottom left corner of minibox Vector3(-0.1, -0.1, -0.1), # Normal vector Vector3(-0.1, -0.1, -0.1), # Tangent vector Vector3(-0.1, -0.1, 0.2), # Top left of link Vector3(-1, -1, 2), # Normal vector Vector3(0, 0, 1), # Tangent vector Vector3(1, 0, 0), # Link to align with link, # All vectors relative to child frame relative_to_child=True ) # Add link and minibox to a posable group so we can move # them around together.
# 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))
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))
# Minibox is... well, a mini box minibox.make_box(0.1, 0.2, 0.2, 0.2) minibox.align( # Bottom left corner of minibox Vector3(-0.1, -0.1, -0.1), # Normal vector Vector3(-0.1, -0.1, -0.1), # Tangent vector Vector3(-0.1, -0.1, 0.2), # Top left of link Vector3(-1, -1, 2), # Normal vector Vector3(0, 0, 1), # Tangent vector Vector3(1, 0, 0), # Link to align with link, # All vectors relative to child frame relative_to_child=True) # Add link and minibox to a posable group so we can move # them around together. group = PosableGroup()