Пример #1
0
 UnityEngine.Quaternion AgxHelper(AgX_Interface.Quaternion quat)
 {
     UnityEngine.Quaternion Uq = new UnityEngine.Quaternion();
     Uq.x = (float)quat.x;
     Uq.y = (float)quat.y;
     Uq.z = (float)quat.z;
     Uq.w = (float)quat.w;
     return(Uq);
 }
Пример #2
0
 public void ChangeInitRot(AgX_Interface.Quaternion rot)
 {
     if (!simulation_Running)
     {
         AgX_Assembly.SetRotation(rot);
         robot.Update();
         Update_Vis(robot);
         RobotStartRotation = rot;
     }
 }
Пример #3
0
    void Start()
    {
        //Start simulation:
        Agx_Simulation.Start(0.01);

        //Setting position and rotations:
        var pos    = new AgX_Interface.Vector3(0, 0, 0);
        var u_quat = UnityEngine.Quaternion.Euler(0, 90, 0);

        AgX_Interface.Quaternion frame_rot = new AgX_Interface.Quaternion(u_quat.x, u_quat.y, u_quat.z, u_quat.w);

        //Create Frames:
        Frame[] frames = new Frame[2];
        for (int i = 0; i < 2; i++)
        {
            frames[i] = new Frame()
            {
                guid         = Guid.NewGuid(),
                position     = pos,
                scale        = 10,
                quatRotation = frame_rot,
                //rotation = rot,
                mass         = 10,
                isStatic     = false,
                materialName = "Plastic"
            };
        }

        //download mesh obj file:
        loadmesh();

        //Set mesh of frames:
        frames[0].SetMesh(AgxHelper(leftmesh.vertices), AgxHelper(leftmesh.uv), leftmesh.triangles);
        frames[1].SetMesh(AgxHelper(rightmesh.vertices), AgxHelper(rightmesh.uv), rightmesh.triangles);

        //Create Joint:
        Simulation_Core.Joint joint = new Simulation_Core.Joint()
        {
            guid            = Guid.NewGuid(),
            leftFrameGuid   = frames[0].guid,
            rightFrameGuid  = frames[1].guid,
            type            = "Hinge",
            lowerRangeLimit = -Math.PI / 2,
            upperRangeLimit = Math.PI / 2,
            max_vel         = Math.PI / 6,
            Kp = 3
        };

        //Create Module:
        var module = new Module();

        module.Create(frames[0], joint, frames[1]);

        //Add module to robot:
        robot.Add_Module(module);

        //Add second module to robot:
        //robot.Add_Module(module2,new Simulation_Core.Joint());

        //Initialize robot:
        robot.Initialize();

        //Scene object:
        sceneobj = new SceneObject()
        {
            guid         = Guid.NewGuid(),
            shape        = "Box",
            size         = new AgX_Interface.Vector3(5, 1, 10),
            position     = new AgX_Interface.Vector3(0, -2, 0),
            quatRotation = new AgX_Interface.Quaternion(0, 0, 0, 1),
            materialName = "Rock",
            mass         = 10,
            isStatic     = true
        };
        sceneobj.Initialize();

        //Load vis from mesh and robot + scene object:
        Load_Vis();

        //Start sim update loop:
        InvokeRepeating("Update_Sim", 0.01f, 0.01f);
    }