def print_model(): model = osim.Model() model.setName('model') # Create a body with name 'body', mass of 1 kg, center of mass at # the origin of the body, and unit inertia # (Ixx = Iyy = Izz = 1 kg-m^2). body = osim.Body('body', 1.0, osim.Vec3(0), osim.Inertia(1)) # Create a free joint (all 6 degrees of freedom) with Ground as # the parent body and 'body' as the child body. joint = osim.FreeJoint('joint', model.getGround(), body) # Add the body and joint to the model. model.addComponent(body) model.addComponent(joint) # Create a TableReporter to save quantities to a file after # simulating. reporter = osim.TableReporterVec3() reporter.setName('reporter') reporter.set_report_time_interval(0.1) reporter.addToReport(model.getOutput('com_position')) reporter.getInput('inputs').setAlias(0, 'com_pos') # Display what input-output connections look like in XML # (in .osim files). print("Reporter input-output connections in XML:\n" + \ reporter.dump()) model.addComponent(reporter) model.printToXML(model_filename)
def print_model(): model = osim.Model() model.setName('model') # Create a body with name 'body', mass of 1 kg, center of mass at the # origin of the body, and unit inertia (Ixx = Iyy = Izz = 1 kg-m^2). body = osim.Body('body', 1.0, osim.Vec3(0), osim.Inertia(1)) # Create a free joint (all 6 degrees of freedom) with Ground as the parent # body and 'body' as the child body. joint = osim.FreeJoint('joint', model.getGround(), body) # Add the body and joint to the model. model.addComponent(body) model.addComponent(joint) # Create a TableReporter to save quantities to a file after simulating. reporter = osim.TableReporterVec3() reporter.setName('reporter') reporter.set_report_time_interval(0.1) # Report the position of the origin of the body. reporter.addToReport(body.getOutput('position')) # For comparison, we will also get the center of mass position from the # Model, and we can check that the two outputs are the same for our # one-body system. The (optional) second argument is an alias for the name # of the output; it is used as the column label in the table. reporter.addToReport(model.getOutput('com_position'), 'com_pos') # Display what input-output connections look like in XML (in .osim files). print("Reporter input-output connections in XML:\n" + reporter.dump()) model.addComponent(reporter) model.printToXML(model_filename)
def test_Joint(self): a = osim.Model() body = osim.Body('body', 1.0, osim.Vec3(0, 0, 0), osim.Inertia(0, 0, 0)) loc_in_parent = osim.Vec3(0, -0, 0) orient_in_parent = osim.Vec3(0, 0, 0) loc_in_body = osim.Vec3(0, 0, 0) orient_in_body = osim.Vec3(0, 0, 0) joint = osim.FreeJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) del joint spatialTransform = osim.SpatialTransform() joint = osim.CustomJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent, spatialTransform) del joint joint = osim.EllipsoidJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent, osim.Vec3(1, 1, 1)) del joint joint = osim.BallJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) del joint joint = osim.PinJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) del joint joint = osim.SliderJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) del joint joint = osim.WeldJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) del joint joint = osim.GimbalJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) del joint joint = osim.UniversalJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) del joint joint = osim.PlanarJoint("joint", a.getGround(), loc_in_parent, orient_in_parent, body, loc_in_body, orient_in_parent) del joint
def __init__(self, *args, **kwargs): super(Arm3DEnvMoBL, self).__init__(*args, **kwargs) blockos = opensim.Body('target', 0.0001, opensim.Vec3(0, 0, 0), opensim.Inertia(1, 1, .0001, 0, 0, 0)) self.target_joint = opensim.FreeJoint( 'target-joint', self.osim_model.model.getGround(), # PhysicalFrame opensim.Vec3(0, 0, 0), opensim.Vec3(0, 0, 0), blockos, # PhysicalFrame opensim.Vec3(0, 0, -0.25), opensim.Vec3(0, 0, 0)) self.noutput = self.osim_model.noutput geometry = opensim.Ellipsoid(0.02, 0.02, 0.02) geometry.setColor(opensim.Green) blockos.attachGeometry(geometry) self.osim_model.model.addJoint(self.target_joint) self.osim_model.model.addBody(blockos) self.osim_model.model.initSystem()
model_path = "../osim/models/gait9dof18musc.osim" model = opensim.Model(model_path) model.setUseVisualizer(True) # Create the ball r = 0.000001 ballBody = opensim.Body('ball', 0.0001 , opensim.Vec3(0), opensim.Inertia(1,1,.0001,0,0,0) ); ballGeometry = opensim.Ellipsoid(r, r, r) ballGeometry.setColor(opensim.Gray) ballBody.attachGeometry(ballGeometry) # Attach ball to the model ballJoint = opensim.FreeJoint("weldball", model.getGround(), # PhysicalFrame opensim.Vec3(0, 0, 0), opensim.Vec3(0, 0, 0), ballBody, # PhysicalFrame opensim.Vec3(0, 0, 0), opensim.Vec3(0, 0, 0)) model.addComponent(ballJoint) model.addComponent(ballBody) # Add contact ballContact = opensim.ContactSphere(r, opensim.Vec3(0,0,0), ballBody); model.addContactGeometry(ballContact) # Reinitialize the system with the new controller state = model.initSystem() for i in range(6): ballJoint.getCoordinate(i).setLocked(state, True)