Exemplo n.º 1
0
    // Setup the Bicycle Configuration
    void Start()
    {
        // Set component sizes
        const float wheelWidth = 0.01f;
        const float frameWidth = 0.05f;
        Vector3     v          = new Vector3(2 * rR, wheelWidth, 2 * rR);

        rearWheel.transform.localScale = v;
        v = new Vector3(2 * rF, wheelWidth, 2 * rF);
        frontWheel.transform.localScale = v;

        // set camera offset from bicycle origin
        camera.transform.localPosition = new Vector3(0.162f, 0.0f, -1.38f);
        cameraRoll = true;

        q = new VizState();
        SetBicycleTransform(q);
        countdownInfo.text = "";

        if (GamePrefs.device != null)
        {
            serial = new SerialThread(GamePrefs.device, 115200);
        }
        else
        {
            serial = new SerialThread("/dev/tty.usbmodem311", 115200);
        }
        stopwatch = new System.Diagnostics.Stopwatch();
        pose      = new BicyclePose();

        serial.Start();
        timestamp = 0;
        stopwatch.Start();
    }
Exemplo n.º 2
0
    void SetBicycleTransform(VizState q)
    {
        // Update x and y positions of the rear wheel contact, yaw and lean of
        // the rear frame by modifying the transform of robot bicycle game
        // object.
        // Explicitly apply the yaw and lean rotations.

        //    y and z axes are switched
        transform.localPosition = new Vector3(q.x, 0.0f, -q.y);
        transform.localRotation = Quaternion.Euler(90.0f, 0, 0) *
                                  Quaternion.Euler(0.0f, 0.0f, -Mathf.Rad2Deg * q.yaw) *
                                  Quaternion.Euler(-Mathf.Rad2Deg * q.lean, 0.0f, 0.0f);

        // camera roll
        float roll = 270;

        if (!cameraRoll)
        {
            roll = (roll + Mathf.Rad2Deg * q.lean) % 360.0f; // fails for angles > 360
        }
        camera.transform.localRotation = Quaternion.Euler(
            camera.transform.localEulerAngles.x,
            camera.transform.localEulerAngles.y,
            roll);

        // All wheel and frame local transforms are with respect to the
        // container game or lean frame
        //   Update rear wheel angle
        rearWheel.transform.localRotation =
            Quaternion.Euler(0.0f, Mathf.Rad2Deg * q.wheelAngle, 0.0f);
        rearWheel.transform.localPosition = new Vector3(0.0f, 0.0f, -rR);

        //   Update pitch of the rear frame
        rearFrame.transform.localRotation =
            Quaternion.Euler(0.0f, Mathf.Rad2Deg * q.pitch, 0.0f);
        //   Set rear frame origin at rear wheel position, then translate alone
        //   the frame axis
        rearFrame.transform.localPosition = rearWheel.transform.localPosition;
        rearFrame.transform.Translate(new Vector3(cR / 2, 0.0f, 0.0f),
                                      rearFrame.transform);

        //   Update pitch and steer of the front frame
        frontFrame.transform.localRotation =
            Quaternion.Euler(0.0f, Mathf.Rad2Deg * q.pitch,
                             -Mathf.Rad2Deg * q.steer);
        //   Set front frame origin at rear frame position, then translate
        //   alone the frame axes
        frontFrame.transform.localPosition = rearFrame.transform.localPosition;
        frontFrame.transform.Translate(
            new Vector3(cR / 2, 0.0f, ls / 2), rearFrame.transform);

        //   Update front wheel angle
        frontWheel.transform.localRotation =
            frontFrame.transform.localRotation *
            Quaternion.Euler(0.0f, Mathf.Rad2Deg * q.wheelAngle, 0.0f);
        frontWheel.transform.localPosition =
            frontFrame.transform.localPosition;
        frontWheel.transform.Translate(
            new Vector3(cF, 0.0f, ls / 2), frontFrame.transform);
    }