Example #1
0
    void Update()
    {
        data = ctrl.getAxiomData();

        txt.text = " PedalTurnTime: " + (data.IsPedalTurning() ? "" + data.pedalTurnTime : "No Turn") +
                   "\n WheelTurnTime: " + (data.IsRollerTurning() ? "" + data.rollerTurnTime : "No Turn") +
                   "\n HeartFrequency: " + data.heartRate;
    }
 AxiomSerialController()
 {
     parity    = System.IO.Ports.Parity.Even;
     stopBits  = System.IO.Ports.StopBits.One;
     dataBits  = 8;
     baudRate  = 9600;
     axiomData = new AxiomDataPackage();
 }
    public AxiomDataPackage getAxiomData()
    {
        if (!isActive)
        {
            return(axiomData);
        }

        if (Time.time == oldTime)
        {
            return(axiomData);
        }

        oldTime = Time.time;

        while (GetSerialIO().GetInputQueueSize() > 0)
        {
            axiomData = (AxiomDataPackage)GetSerialIO().GetNextInput();
        }

        // not enough new data, return the old one
        return(axiomData);
    }
Example #4
0
    void Update()
    {
        // axiom data
        data = axiomserialController.getAxiomData();

        // get angles from sensors
        float backWheelAngle = GetRelativeRearWheelAngle(smoothingMethod);
        float pedalAngle     = bfPedalController.GetAbsoluteAngle();

#if USING_STEAMVR
        float steeringAngle = (trackedSteering.transform.eulerAngles.y + 180f) % 360f - 180f;
#else
        float steeringAngle = 0;
#endif

        float leaningAngle = MathUtils.GetSignedAngleDiff(bfTiltController.GetAbsoluteAngle(), 360f) * tiltFactor;

        // Steering weight (for animation) from -1 to 1
        float steeringWeight = Mathf.Clamp(steeringAngle * INV_MAX_STEERING_ANGLE, -1, 1);

        // override data with gamePad data
        if (useGamePad)
        {
            steeringWeight = Input.GetAxis("Turn");
            steeringAngle  = steeringWeight * MAX_STEERING_ANGLE;
            backWheelAngle = Input.GetAxis("Speed") * 10;
            leaningAngle   = -Input.GetAxis("OrbitX") * 25f;
        }

        // update animations
        UpdateWheelAnimation(backWheelAngle);
        UpdatePedalAnimation(pedalAngle);
        UpdateSteeringAnimation(steeringWeight);

        float distanceTraveled = backWheelAngle * sWheelPerDegree;
        float wheelSpeed       = (distanceTraveled / Time.deltaTime) * 3.6f;

        // Change the bicycle's Y position and pitch so that wheels always make contact with the ground
        float slope = AdjustBicycleToGround(leaningAngle);

        if (useResistance)
        {
            AdjustAxiomResistance(wheelSpeed, slope);
        }

        // move forward
        if (moveForward)
        {
            Move(distanceTraveled, steeringAngle * Mathf.Deg2Rad, leaningAngle * Mathf.Deg2Rad);
        }

        // Reset
#if USING_STEAMVR
        if (trackedSteering.gripped || Input.GetKeyDown(KeyCode.R))
#else
        if (Input.GetKeyDown(KeyCode.R))
#endif
        {
            UnityEngine.VR.InputTracking.Recenter();
#if USING_STEAMVR
            Valve.VR.OpenVR.System.ResetSeatedZeroPose();
            Valve.VR.OpenVR.Compositor.SetTrackingSpace(Valve.VR.ETrackingUniverseOrigin.TrackingUniverseSeated);
#endif
            bfPedalController.SetReference();
            bfTiltController.SetReference();
        }
    }