Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (LpSensorManager.getConnectionStatus(lpmsSensor) == LpSensorManager.SENSOR_CONNECTION_CONNECTED)
     {
         SensorData sd;
         Vector3    current_rot = transform.rotation.eulerAngles;
         unsafe
         {
             sd = *((SensorData *)LpSensorManager.getSensorData(lpmsSensor));
         }
         if (Input.GetButtonDown("Fire1"))
         {
             tracking = !tracking;
             Debug.Log("Tracking:" + tracking);
             last_sensor = new Vector3(-sd.ry, -sd.rz, sd.rx);
             //transform.rotation = virtualcube.transform.rotation;
         }
         //Debug.Log("Timestamp: " + sd.timeStamp + " q: " + sd.qw + " " + sd.qx + " " + sd.qy + " " + sd.qz);
         //Quaternion q = new Quaternion(sd.qx - offset.x, sd.qz - offset.y, sd.qy - offset.z, sd.qw - offset.w);
         if (tracking)
         {
             current_sensor = new Vector3(-sd.ry, -sd.rz, sd.rx);
             //Debug.Log("OFFSET:" + offset);
         }
         offset             = current_sensor - last_sensor;
         transform.rotation = Quaternion.Euler(current_rot + offset);
         last_sensor        = current_sensor;
         if (Input.GetKeyDown("space"))
         {
             transform.rotation = new Quaternion(0, 0, 0, 0);
             //transform.rotation = virtualcube.transform.rotation;
         }
     }
 }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()

    {
        Application.targetFrameRate = 20;
        // Initialize sensor manager
        LpSensorManager.initSensorManager();

        // connects to sensor
        LpSensorManager.connectToLpms(LpSensorManager.DEVICE_LPMS_B2, lpmsSensor);

        // Wait for establishment of sensor1 connection
        while (LpSensorManager.getConnectionStatus(lpmsSensor) != 1)
        {
            //System.Threading.Thread.Sleep(100);
        }
        Debug.Log("Sensor connected");

        // Sets sensor offset
        LpSensorManager.setOrientationOffset(lpmsSensor, LpSensorManager.LPMS_OFFSET_MODE_HEADING);
        Debug.Log("Offset set");
        tracking = false;
        if (LpSensorManager.getConnectionStatus(lpmsSensor) == LpSensorManager.SENSOR_CONNECTION_CONNECTED)
        {
            SensorData sd;
            unsafe
            {
                sd = *((SensorData *)LpSensorManager.getSensorData(lpmsSensor));
            }
            last_sensor    = new Vector3(0, 0, 0);
            current_sensor = last_sensor;
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (LpSensorManager.getConnectionStatus(lpmsSensor) == LpSensorManager.SENSOR_CONNECTION_CONNECTED)
        {
            SensorData sd;
            Vector3    current_rot = transform.rotation.eulerAngles;

            unsafe
            {
                sd = *((SensorData *)LpSensorManager.getSensorData(lpmsSensor));
            }
            this.transform.rotation = new Quaternion(sd.qx, sd.qz, sd.qy, sd.qw);
            if (first_time)
            {
                created = (GameObject)Instantiate(cube);
                created.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
                //created.GetComponent<MeshRenderer>().enabled = false;
                created.transform.parent = this.transform;
                last_sensor = created.transform.rotation.eulerAngles;
                first_time  = !first_time;
            }
            //Debug.Log("Timestamp: " + sd.timeStamp + " q: " + sd.qw + " " + sd.qx + " " + sd.qy + " " + sd.qz);
            //Quaternion q = new Quaternion(sd.qx - offset.x, sd.qz - offset.y, sd.qy - offset.z, sd.qw - offset.w);
            current_sensor = created.transform.rotation.eulerAngles;
            error          = current_sensor - last_sensor;
            datamanager.GetComponent <DataManager>().set_Iniertial(this.transform.localRotation);
            last_sensor = current_sensor;
        }
    }
Ejemplo n.º 4
0
 // Update is called once per frame
 void Update()
 {
     if (LpSensorManager.getConnectionStatus(lpmsSensor) == LpSensorManager.SENSOR_CONNECTION_CONNECTED)
     {
         SensorData sd;
         unsafe
         {
             sd = *((SensorData *)LpSensorManager.getSensorData(lpmsSensor));
         }
         //Debug.Log("Timestamp: " + sd.timeStamp + " q: " + sd.qw + " " + sd.qx + " " + sd.qy + " " + sd.qz);
         Quaternion q = new Quaternion(sd.qx, sd.qz, sd.qy, sd.qw);
         transform.rotation = q;
         if (dm != null)
         {
             dm.GetComponent <DataManager>().set_Iniertial(this.transform.rotation);
         }
     }
 }
Ejemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         Debug.Log("Doing The Calibration");
         offset      = transform.rotation;
         offsetEuler = offset.eulerAngles;
         Debug.Log("OFFSET: X:" + offsetEuler.x + "Y:" + offsetEuler.z + "Z:" + offsetEuler.y);
     }
     if (LpSensorManager.getConnectionStatus(lpmsSensor) == LpSensorManager.SENSOR_CONNECTION_CONNECTED)
     {
         SensorData sd;
         unsafe
         {
             sd = *((SensorData *)LpSensorManager.getSensorData(lpmsSensor));
         }
         //Debug.Log("Timestamp: " + sd.timeStamp + " q: " + sd.qw + " " + sd.qx + " " + sd.qy + " " + sd.qz);
         //Quaternion q = new Quaternion(sd.qx - offset.x, sd.qz - offset.y, sd.qy - offset.z, sd.qw - offset.w);
         Quaternion q = new Quaternion(sd.qx, sd.qz, sd.qy, sd.qw);
     }
 }