Example #1
0
    def __init__(self,
                 *args,
                 one_target=False,
                 max_speed=5.,
                 kin_coef=0.,
                 vel_prof_coef=0.,
                 acc_coef=0.,
                 **kwargs):
        super(Arm2DEnv, self).__init__(*args, **kwargs)
        blockos = opensim.Body('target', 0.0001, opensim.Vec3(0),
                               opensim.Inertia(1, 1, .0001, 0, 0, 0))
        self.target_joint = opensim.PlanarJoint(
            '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))

        geometry = opensim.Ellipsoid(0.02, 0.02, 0.02)
        geometry.setColor(opensim.Green)
        blockos.attachGeometry(geometry)
        self.one_target = one_target
        self.target_generated = False
        self.osim_model.model.addJoint(self.target_joint)
        self.osim_model.model.addBody(blockos)
        self.osim_model.model.initSystem()
        self.kin_coef = kin_coef
        self.vel_prof_coef = vel_prof_coef
        self.max_speed = max_speed
Example #2
0
def test(model_path, visualize):
    model = opensim.Model(model_path)
    brain = opensim.PrescribedController()
    model.addController(brain)
    state = model.initSystem()

    muscleSet = model.getMuscles()
    for j in range(muscleSet.getSize()):
        brain.addActuator(muscleSet.get(j))
        func = opensim.Constant(1.0)
        brain.prescribeControlForActuator(j, func)

    block = opensim.Body('block', 0.0001, opensim.Vec3(0),
                         opensim.Inertia(1, 1, .0001, 0, 0, 0))
    model.addComponent(block)
    pj = opensim.PlanarJoint(
        'pin',
        model.getGround(),  # PhysicalFrame
        opensim.Vec3(0, 0, 0),
        opensim.Vec3(0, 0, 0),
        block,  # PhysicalFrame
        opensim.Vec3(0, 0, 0),
        opensim.Vec3(0, 0, 0))
    model.addComponent(pj)
    model.initSystem()
    pj.getCoordinate(1)
Example #3
0
    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
Example #4
0
    def __init__(self, *args, **kwargs):
        super(Arm2DEnv, self).__init__(*args, **kwargs)
        blockos = opensim.Body('target', 0.0001 , opensim.Vec3(0), opensim.Inertia(1,1,.0001,0,0,0) );
        self.target_joint = opensim.PlanarJoint('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))

        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()
Example #5
0
    def create_obstacles(self):
        x = 0.
        y = 0.
        r = 0.1
        for i in range(self.max_obstacles):
            name = i.__str__()
            blockos = opensim.Body(name + '-block', 0.0001, opensim.Vec3(0),
                                   opensim.Inertia(1., 1., .0001, 0., 0., 0.))
            pj = opensim.PlanarJoint(
                name + '-joint',
                self.osim_model.model.getGround(),  # PhysicalFrame
                opensim.Vec3(0., 0., 0.),
                opensim.Vec3(0., 0., 0.),
                blockos,  # PhysicalFrame
                opensim.Vec3(0., 0., 0.),
                opensim.Vec3(0., 0., 0.))

            self.osim_model.model.addJoint(pj)
            self.osim_model.model.addBody(blockos)

            block = opensim.ContactSphere(r, opensim.Vec3(0., 0., 0.), blockos)
            block.setName(name + '-contact')
            self.osim_model.model.addContactGeometry(block)

            force = opensim.HuntCrossleyForce()
            force.setName(name + '-force')

            force.addGeometry(name + '-contact')
            force.addGeometry("r_heel")
            force.addGeometry("l_heel")
            force.addGeometry("r_toe")
            force.addGeometry("l_toe")

            force.setStiffness(1.0e6 / r)
            force.setDissipation(1e-5)
            force.setStaticFriction(0.0)
            force.setDynamicFriction(0.0)
            force.setViscousFriction(0.0)

            self.osim_model.model.addForce(force)