コード例 #1
0
        public int switch_car()
        {
            if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero)
            {
                return(0);
            }

            int ret = 0;

            if (LogitechGSDK.LogiGetStateCSharp(0).rgdwPOV[0] == 0)
            {
                ret = 1;
            }

            if (LogitechGSDK.LogiGetStateCSharp(0).rgdwPOV[0] == 9000)
            {
                ret = 2;
            }

            if (LogitechGSDK.LogiGetStateCSharp(0).rgdwPOV[0] == 18000)
            {
                ret = 3;
            }

            if (LogitechGSDK.LogiGetStateCSharp(0).rgdwPOV[0] == 27000)
            {
                ret = 4;
            }


            return(ret);
        }
コード例 #2
0
        public bool change_car2()
        {
            if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero)
            {
                return(false);
            }

            return(LogitechGSDK.LogiGetStateCSharp(0).rgbButtons[12] == 128);
        }
コード例 #3
0
        public bool escape()
        {
            if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero)
            {
                return(false);
            }

            return(LogitechGSDK.LogiGetStateCSharp(0).rgbButtons[24] != 0);
        }
コード例 #4
0
        /// <summary>
        /// 刹车开度范围
        /// </summary>
        /// <returns>0-99</returns>
        public int brake_range()
        {
            if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero)
            {
                return(0);
            }

            int ret = -99 * (LogitechGSDK.LogiGetStateCSharp(0).lRz - 32767) / 65536;

            return(ret);
        }
コード例 #5
0
        /// <summary>
        /// 油门开度范围
        /// </summary>
        /// <returns>0-99</returns>
        public int accelerator_range()
        {
            if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero)
            {
                return(0);
            }

            int ret = -100 * (LogitechGSDK.LogiGetStateCSharp(0).lY - 32767) / 65536;

            return(ret);
        }
コード例 #6
0
        /// <summary>
        /// 读取方向盘转角
        /// </summary>
        /// <returns>[-450, 450], 左正右负</returns>
        public double SteeringWheelAngle()
        {
            if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero)
            {
                return(0);
            }

            double ret = -450 * (double)(LogitechGSDK.LogiGetStateCSharp(0).lX) / 32767;

            return(ret);
        }
コード例 #7
0
        public int control_sign()
        {
            int ret = 0;

            if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero)
            {
                ret = 0;
            }

            if (LogitechGSDK.LogiGetStateCSharp(0).rgbButtons[23] != 0)
            {
                ret = 1;
            }

            if (LogitechGSDK.LogiGetStateCSharp(0).rgbButtons[11] != 0)
            {
                ret = 0;
            }

            return(ret);
        }
コード例 #8
0
        public int car_gear()
        {
            int ret = 0;

            if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero)
            {
                ret = 3;
            }

            if (LogitechGSDK.LogiGetStateCSharp(0).rgbButtons[14] != 0)
            {
                ret = 4;
            }

            if (LogitechGSDK.LogiGetStateCSharp(0).rgbButtons[15] != 0)
            {
                ret = 2;
            }

            return(ret);
        }
コード例 #9
0
        /// <summary>
        /// 启动定时器,轮询获取罗技G29模拟器数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_Tick(object sender, EventArgs e)
        {
            int DeviceIndex = 0;

            if (LogitechGSDK.LogiUpdate())
            {
                if (LogitechGSDK.LogiIsConnected(DeviceIndex))
                {
                    var Properties = new LogitechGSDK.LogiControllerPropertiesData();
                    LogitechGSDK.LogiGetCurrentControllerProperties(DeviceIndex, ref Properties);

                    var State = LogitechGSDK.LogiGetStateCSharp(DeviceIndex);

                    realTimeData.index           = DeviceIndex;
                    realTimeData.AcceleratePedal = accleratePedal(State.lY).ToString();
                    realTimeData.BreakPedal      = breakPedal(State.lRz).ToString();
                    realTimeData.direction_flag  = directionFlag(State.lX);
                    realTimeData.gear            = 1;
                    realTimeData.SteeringAngle   = steeringAngle(State.lX).ToString();


                    string OutputTail = "Steering Angle: " + steeringAngle(State.lX).ToString() + "\r\n";
                    OutputTail += "Direction flag: " + directionFlag(State.lX).ToString() + "\r\n";
                    OutputTail += "Accelerate Pedal: " + accleratePedal(State.lY).ToString() + "\r\n";
                    OutputTail += "Break Pedal: " + breakPedal(State.lRz).ToString() + "\r\n";
                    OutputTail += "Clutch Pedal: " + State.rglSlider[0].ToString() + "\r\n";

                    string Output107 = realTimeData.AcceleratePedal + ','
                                       + realTimeData.BreakPedal + ','
                                       + realTimeData.direction_flag + ','
                                       + realTimeData.gear + ','
                                       + realTimeData.SteeringAngle;

                    this.Output.Text = OutputTail + "发送给云服务器的107协议: " + Output107;
                }
            }
        }
コード例 #10
0
    void Update()
    {
        /* update current in-game time and round to nearest millisecond */
        gameTime = Time.timeSinceLevelLoad;
        gameTime = (float)(Math.Round((double)gameTime, 3));


        /* check if game is over */
        if ((int)gameTime > gameLength)
        {
            gameIsRunning = false;
            saveScoreFile(errorData.ToArray());
            SceneManager.LoadScene(5);
        }

        /* check for Esc key press */
        if (Input.GetKey("escape"))
        {
            /* go to Main Menu if pressed */
            SceneManager.LoadScene(0);
        }


        /* if game is not over & still running */
        if (gameIsRunning)
        {
            //horizontalLine.SetPositions(new Vector3[2] { new Vector3(-11, 0, 1), new Vector3(11, 0, 1) });

            /* update action quantization level & notification */
            actionQuantizationLevel             = (int)Math.Ceiling(actionQuantizationCurve.Evaluate(gameTime));
            actionQuantizationNotification.text = "Action Quant: " + actionQuantizationLevel;

            /* update vision quantization level & notification */
            visionQuantizationLevel             = (int)Math.Ceiling(visionQuantizationCurve.Evaluate(gameTime));
            visionQuantizationNotification.text = "Vision Quant: " + visionQuantizationLevel;

            /* update path line */
            lineUpdate(ref pathLine, visionDelayCurve.Evaluate(gameTime), pathHistory);

            /* update path position variable */
            pathPositionXPos = trailPositionCurve.Evaluate(gameTime);

            /*update time notification*/
            timeNotification.text = (int)gameTime + "s";

            /* update bump size variable */
            bumpSize = bumpSizeCurve.Evaluate(gameTime);

            /* update vision delay notification */
            visionDelay = visionDelayCurve.Evaluate(gameTime);
            visionDelayNotification.text = "Vision Delay: " + visionDelay;

            /* update action delay notification */
            actionDelay = actionDelayCurve.Evaluate(gameTime);
            actionDelayNotification.text = "Action Delay: " + actionDelay;

            /* make sure steering wheel is initialized and connected: */
            if (!logiIni)
            {
                logiIni = LogitechGSDK.LogiSteeringInitialize(false);
            }


            if (!LogitechGSDK.LogiIsConnected(deviceIdx))
            {
                Debug.Log("PLEASE PLUG IN A STEERING WHEEL OR A FORCE FEEDBACK CONTROLLER");
            }

            /**********************************
            * Wheel is Connected and Working *
            **********************************/

            else if (LogitechGSDK.LogiUpdate())
            {
                /* record state of the wheel and converts to an angle in degrees */
                rec             = LogitechGSDK.LogiGetStateCSharp(deviceIdx);
                normalizedAngle = rec.lX * 900 / 65536;

                wheelAngles.Add(new float[] { gameTime, normalizedAngle });

                for (int i = 0; i < wheelAngles.Count; i++)
                {
                    if (gameTime - wheelAngles[i][0] > actionDelay)
                    {
                        quantizedAngle = QuantizeAngle(wheelAngles[i][1], actionQuantizationLevel);
                        wheelAngles.RemoveRange(0, i);
                    }
                }


                /* add to the player position with a scaled factor of the angle of the wheel
                 * NOTE: player position is related to previous position of the player.
                 */
                playerLineXPos = playerLineXPos + sensitivity * quantizedAngle;

                LogitechGSDK.LogiPlayConstantForce(deviceIdx, (int)bumpSize);

                /* keep the player position from going off the screen */
                if (playerLineXPos < XminScreen)
                {
                    playerLineXPos = XminScreen;
                }
                else if (playerLineXPos > XmaxScreen)
                {
                    playerLineXPos = XmaxScreen;
                }

                /* set position of the player line */
                playerLine.SetPositions(new Vector3[2] {
                    new Vector3(playerLineXPos, -playerLineHeight, 0), new Vector3(playerLineXPos, playerLineHeight, 0)
                });

                /* calculate the error and add to list */
                reportPositions();
            }

            else
            {
                Debug.Log("THIS WINDOW NEEDS TO BE IN FOREGROUND IN ORDER FOR THE SDK TO WORK PROPERLY... OR TEST ENDED");
            }
        }
    }
コード例 #11
0
    private float visionDelay;      /* current amount of vision delay in seconds */

    void Start()
    {
        /* load variables from menu class */
        inputFilePath  = BeginButtonControl.inputFilePath;
        RecordFileName = BeginButtonControl.saveFileName;
        sensitivity    = 0.01f * BeginButtonControl.sensitivity;


        LoadTestParameters(ref trailPositionCurve, ref actionQuantizationCurve, ref visionDelayCurve, ref bumpSizeCurve, ref actionDelayCurve, ref visionQuantizationCurve);

        /**************************************
        * Initialize Logitech Steering Wheel *
        **************************************/

        /* allow full range of motion for the steering wheel & set steering wheel gains */
        logiIni = LogitechGSDK.LogiSteeringInitialize(false);
        LogitechGSDK.LogiControllerPropertiesData properties = new LogitechGSDK.LogiControllerPropertiesData();
        wheelPropSetup(ref properties);
        LogitechGSDK.LogiSetPreferredControllerProperties(properties); /* set properties of wheel */
        rec = LogitechGSDK.LogiGetStateCSharp(deviceIdx);

        /***********************
         * Set Up GUI Elements *
         **********************/

        /* create the horizontal axis line */
        horizontalLine.SetWidth(horizontalLineWidth, horizontalLineWidth);
        horizontalLine.SetVertexCount(2);
        horizontalLine.SetPositions(new Vector3[2] {
            new Vector3(-11, 0, 0), new Vector3(11, 0, 0)
        });
        horizontalLine.material = new Material(Shader.Find("Sprites/Default"));
        horizontalLine.SetColors(Color.magenta, Color.magenta);


        /* create path line */
        pathLine.SetWidth(pathLineWidth, pathLineWidth);
        pathLine.SetVertexCount(2);
        pathLine.SetPositions(new Vector3[2] {
            new Vector3(0, -pathLineHeight, 0), new Vector3(0, pathLineHeight, 0)
        });
        pathLine.material = new Material(Shader.Find("Sprites/Default"));
        pathLine.SetColors(Color.grey, Color.grey);
        pathHistory = 1f; /* amount of history of path shown in seconds */

        /* create vertical line that represents player position */
        playerLine.SetWidth(playerLineWidth, playerLineWidth);
        playerLine.SetVertexCount(2);
        playerLineXPos = 0;
        playerLine.SetPositions(new Vector3[2] {
            new Vector3(playerLineXPos, -playerLineHeight, 0), new Vector3(playerLineXPos, playerLineHeight, 0)
        });
        playerLine.material = new Material(Shader.Find("Sprites/Default"));
        playerLine.SetColors(Color.green, Color.green);
        playerLine.sortingOrder = 1;

        /******************************************
        * Set up Parameters for Game Experiments *
        ******************************************/

        saveFilePath = Path.GetDirectoryName(Application.dataPath);

        gameDate = DateTime.UtcNow.ToString("yyyyMMddhhmmss");

        gameIsRunning = true;
    }
コード例 #12
0
    void Update()
    {
        // Stimulate for starting check and trainning time check
        var theClient = GameObject.Find("PressController").GetComponent <ForPress>();

        signal = theClient.signal;


        //--------------------------------------------------------------------------
        if (signal[0] < BeginningCommmand || signal[0] > FinalCommmand)
        {  // If exception, than default case. And checking the default command(protocol == 0).
            command = 0;
        }
        else
        {
            for (int i = BeginningCommmand; i <= FinalCommmand; i++)
            {
                if (signal[0] >= i && signal[0] < (i + 1))  // If it was 1, then (1 <= x < 2).
                {
                    command = i;
                    break;
                }
            }
        }



        /*
         * When racing wheel is connected and available
         */

        if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0))
        {
            //Debug.Log("logitech is connected!");
            LogitechGSDK.DIJOYSTATE2ENGINES rec;
            rec = LogitechGSDK.LogiGetStateCSharp(0);

            xAxes = rec.lX;
            //Quaternion Right = Quaternion.identity;
            //Right.eulerAngles = new Vector3(0, 80 + (xAxes / 5000 * 80), 0);
            LogitechGSDK.LogiPlaySpringForce(0, 0, 50, 20);
            transform.Rotate(new Vector3(0, xAxes / 4000, 0));

            //--------------------Set Speed of Car-------------------------------

            switch (command)
            {
            case 0: speed = 2.0f; break;

            case 1: speed = 2.5f; break;

            case 2: speed = 3.0f; break;

            case 3: speed = 3.3f; break;

            case 4: speed = 3.7f; break;

            case 5: speed = 4.0f; break;

            case 6: speed = 4.2f; break;

            case 7: speed = 4.3f; LogitechGSDK.LogiPlayDirtRoadEffect(0, 5); break;

            case 8: speed = 4.5f; LogitechGSDK.LogiPlayDirtRoadEffect(0, 10); break;

            case 9: speed = 4.8f; LogitechGSDK.LogiPlayDirtRoadEffect(0, 14); break;

            case 10: speed = 5.0f; LogitechGSDK.LogiPlayDirtRoadEffect(0, 18); break;

            default: break;
            }

            CarDefault.volume = 0.5f + (speed / 10f);

            transform.Translate(new Vector3(0, 0, speed));
        }


        /*
         * When racing wheel is not connected so unavailable
         */
        else
        {
            switch (command)
            {
            case 0: speed = 2.0f; break;

            case 1: speed = 2.5f; break;

            case 2: speed = 3.0f; break;

            case 3: speed = 3.3f; break;

            case 4: speed = 3.7f; break;

            case 5: speed = 4.0f; break;

            case 6: speed = 4.2f; break;

            case 7: speed = 4.3f; break;

            case 8: speed = 4.5f; break;

            case 9: speed = 4.8f; break;

            case 10: speed = 5.0f; break;

            default: break;
            }

            //if (Input.GetKey(KeyCode.UpArrow))
            transform.Translate(new Vector3(0, 0, speed));

            if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow))
            {
                timePassed = Time.time;
            }

            if (Input.GetKey(KeyCode.RightArrow) && (Time.time - timePassed) < 0.7f)
            {
                transform.Rotate(new Vector3(0, 2, 0));
            }

            if (Input.GetKey(KeyCode.LeftArrow) && (Time.time - timePassed) < 0.7f)
            {
                transform.Rotate(new Vector3(0, -2, 0));
            }


            CarDefault.volume = 0.5f + (speed / 10f);
        }



        Marker.transform.position = new Vector3(this.transform.position.x, -1290, this.transform.position.z);

        SpeedobarConverter.ShowSpeed(speed, 0, 10);
    }
コード例 #13
0
    private int gameLength;  /* gameLength in seconds */

    void Start()
    {
        /* get file interaction & sensitivity values from menu class */
        RecordFileName = BeginButtonControl.saveFileName;
        inputFilePath  = BeginButtonControl.inputFilePath;
        sensitivity    = 0.1f * ValSensitivity.sensitivity;


        LoadTestParameters(ref distances, ref widths);

        /**************************************
        * Initialize Logitech Steering Wheel *
        **************************************/

        /* allow full range of motion for the steering wheel & set steering wheel gains */
        wheelProp = "";
        logiIni   = LogitechGSDK.LogiSteeringInitialize(false);
        LogitechGSDK.LogiControllerPropertiesData properties = new LogitechGSDK.LogiControllerPropertiesData();
        wheelPropSetup(ref properties);
        LogitechGSDK.LogiSetPreferredControllerProperties(properties);
        rec = LogitechGSDK.LogiGetStateCSharp(deviceIdx);  /*responsible for recording state of the wheel*/


        /* create the horizontal axis line */
        horizontalLine.SetWidth(0.1f, 0.1f);
        horizontalLine.SetVertexCount(2);
        horizontalLine.SetPositions(new Vector3[2] {
            new Vector3(-11, 0, 0), new Vector3(11, 0, 0)
        });
        horizontalLine.material = new Material(Shader.Find("Sprites/Default"));
        horizontalLine.SetColors(Color.magenta, Color.magenta);


        /* create vertical line that represents player position */
        playerLine.SetWidth(0.05f, 0.05f);
        playerLine.SetVertexCount(2);
        playerLineXPos = 0;
        playerLine.SetPositions(new Vector3[2] {
            new Vector3(playerLineXPos, -playerLineHeight, 0), new Vector3(playerLineXPos, playerLineHeight, 0)
        });
        playerLine.material = new Material(Shader.Find("Sprites/Default"));
        playerLine.SetColors(Color.green, Color.green);
        playerLine.sortingOrder = 2;

        /*create fat line that represent goal zone*/
        goalLineWidth = widths.Evaluate(0.1f);
        goalLine.SetWidth(goalLineWidth, goalLineWidth);
        goalLine.SetVertexCount(2);
        goalLineHeight = 10;
        goalLineXPos   = distances.Evaluate(0.1f);
        goalLine.SetPositions(new Vector3[2] {
            new Vector3(goalLineXPos, -goalLineHeight, 0), new Vector3(goalLineXPos, goalLineHeight, 0)
        });
        goalLine.material = new Material(Shader.Find("Sprites/Default"));
        goalLine.SetColors(Color.gray, Color.gray);
        goalLine.sortingOrder = 1;


        errorData = new List <string>();

        DateTime nowDate = DateTime.UtcNow;

        gameDate = nowDate.ToString("yyyyMMddhhmmss");


        /******************************************
        * Set up Parameters for Game Experiments *
        ******************************************/
        saveFilePath  = Path.GetDirectoryName(Application.dataPath);
        gameIsRunning = true;
    }
コード例 #14
0
    void Update()
    {
        /* update current in-game time and round to nearest millisecond */
        gameTime = Time.timeSinceLevelLoad;
        gameTime = (float)(Math.Round((double)gameTime, 3));


        /* check if game is over
         * if so, write output file & open end game scene */
        if ((int)gameTime > gameLength)
        {
            gameIsRunning = false;
            saveScoreFile(errorData.ToArray());
            SceneManager.LoadScene(5);
        }

        /* if game is not over & still running */
        if (gameIsRunning)
        {
            /* update time notification */
            timeNotification.text = (int)gameTime + "s";

            /* update width of goal zone with info already loaded from text file */
            goalLineWidth = widths.Evaluate(gameTime);
            goalLine.SetWidth(goalLineWidth, goalLineWidth);
            goalLineXPos = distances.Evaluate(gameTime);

            goalLine.SetPositions(new Vector3[2] {
                new Vector3(goalLineXPos, -goalLineHeight, 0), new Vector3(goalLineXPos, goalLineHeight, 0)
            });


            /* make sure steering wheel is initialized and connected: */
            if (!logiIni)
            {
                logiIni = LogitechGSDK.LogiSteeringInitialize(false);
            }


            if (!LogitechGSDK.LogiIsConnected(deviceIdx))
            {
                Debug.Log("PLEASE PLUG IN A STEERING WHEEL OR A FORCE FEEDBACK CONTROLLER");
            }

            /**********************************
            * Wheel is Connected and Working *
            **********************************/

            else if (LogitechGSDK.LogiUpdate())
            {
                /* record state of the wheel and converts to an angle in degrees */
                rec             = LogitechGSDK.LogiGetStateCSharp(deviceIdx);
                NormalizedAngle = rec.lX * 900 / 65536;

                /* set the player position to a scaled factor of the angle of the wheel
                 * NOTE: player position is not related to previous position of the player.
                 * this means angle of the wheel = position on the screen
                 */

                playerLineXPos = sensitivity * NormalizedAngle;

                /* keep the player position from going off the screen */
                if (playerLineXPos < XminScreen)
                {
                    playerLineXPos = (float)XminScreen;
                }
                else if (playerLineXPos > XmaxScreen)
                {
                    playerLineXPos = (float)XmaxScreen;
                }

                /* set position of the player line */
                playerLine.SetPositions(new Vector3[2] {
                    new Vector3(playerLineXPos, -playerLineHeight, 0), new Vector3(playerLineXPos, playerLineHeight, 0)
                });

                /* calculate the error and add to list for output */
                reportPositions();
            }

            else
            {
                Debug.Log("THIS WINDOW NEEDS TO BE IN FOREGROUND IN ORDER FOR THE SDK TO WORK PROPERLY... OR TEST ENDED");
            }
        }
    }