def __init__(self, World, Length, Diameter, MinSpringForce=0, MaxSpringForce=0): """Create a visualized pistion with spring, damping, and actuation properties. World: The pyode world that this object resides in Length: The fully extended length of the pistion Diameter: The diameter of the outer cylinder MinSpringForce: The spring force applied at the minimum length position MaxSpringForce: The spring force applied at the maximum length position Note: A positive spring force makes the pistons expand A negative spring force makes the pistons contract """ # Initialize the vpyode.GDMFrameAssembly class vpyode.GDMFrameAssembly.__init__(self, World) self._length = Length # We might want to keep this around cylLength = Length / 2.0 # The le3ngth of each cylinder is half of the total. # Create the two halves of the piston -- Build it collapsed innerCylBody = vpyode.GDMFrameBody(World) innerCylElement = vpyode.GDMElement(False).DefineCylinder( 2000, 0.75 * Diameter, cylLength) innerCylBody.AddGDMElement('cyl', innerCylElement) innerCylBody.DefineConnectionPoint('Tip', (0, 0, cylLength / 2.0)) innerCylBody.DefineConnectionPoint('Slider', (0, 0, 0), (0, 0, 1)) # Along the z-axis outerCylBody = vpyode.GDMFrameBody(World) outerCylElement = vpyode.GDMElement(False).DefineCylinder( 2000, Diameter, cylLength) outerCylBody.AddGDMElement('cyl', outerCylElement) outerCylBody.DefineConnectionPoint('Tip', (0, 0, -cylLength / 2.0)) outerCylBody.DefineConnectionPoint('Slider', (0, 0, 0), (0, 0, 1)) # Along the z-axis self._linearActuatorJoint = odelib.LinearActuator(World) # This order gives us positive slider positions whith fully extended being cylLength innerCylBody.Connect(self._linearActuatorJoint, 'Slider', outerCylBody, 'Slider') # Add these bodies to the assembly self.AddBody('Inner', innerCylBody) self.AddBody('Outer', outerCylBody) # MinSpringForce is the force you get at MinStop # MaxSpringForce is the force you get at MaxStop # A positive spring force makes the pistons expand # A negative spring force makes the pistons contract self._linearActuatorJoint.ChangeProperties( MinSpringForce=MinSpringForce, MaxSpringForce=MaxSpringForce, MinStop=0, MaxStop=cylLength)
def makeWorld(self): body = vpyode.GDMFrameBody(self.world) element = vpyode.GDMElement() mesh = self.makeMesh() element.DefineMeshTotal(100.0, (0, 0, 0), self.faces[0], mesh) body.AddGDMElement('Mesh', element) return body
def create_box(world, density, lx, ly, lz,position,rotation, colour): """Create a box body and its corresponding geom.""" # Create body body = vpyode.GDMFrameBody(world) element = vpyode.GDMElement() element.DefineBox(density, lx, ly, lz, colour) body.AddGDMElement('box', element) body.setPosition(position) body.setQuaternion((rotation,0,1,0)) return body
def create_cylinder(world, density, radius, length): '''Create a cylinder body and its corresponding geom.''' body = vpyode.GDMFrameBody(world) element = vpyode.GDMElement() element.DefineCylinder(density, radius, length) element.GetDisplayObject().color = (random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1)) body.AddGDMElement('Cylinder', element) return body
def create_box(world, density, lx, ly, lz): """Create a box body and its corresponding geom.""" # Create body body = vpyode.GDMFrameBody(world) element = vpyode.GDMElement() element.DefineBox(density, lx, ly, lz) element.GetDisplayObject().color = (random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1)) body.AddGDMElement('Box', element) return body
def makeCamera(self): camera = vpyode.GDMElement() camera.DefineBox(1000,0.15,0.1,0.1,color.red,self.box.GetFeature("box").pos + (0.25,0.25,0)) self.box.AddGDMElement("camera",camera)