static void Main(string[] args) { while (true) { Thread.Sleep(2000); LogitechGSDK.LogiSteeringInitialize(true); for (int i = 0; i < 1000000; i++) { //All the test functions are called on the first device plugged in(index = 0) LogitechGSDK.LogiSteeringInitialize(true); if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SPRING)) { LogitechGSDK.LogiStopSpringForce(0); } else { LogitechGSDK.LogiPlaySpringForce(0, 50, 50, 50); } } else { LogitechGSDK.LogiPlayDirtRoadEffect(0, 100); } } Console.WriteLine("The program it's going to stop! "); LogitechGSDK.LogiSteeringShutdown(); } }
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); }
void FixedUpdate() { if (isPaused) { return; } if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { LogitechGSDK.DIJOYSTATE2ENGINES rec; //float h, v;, velo; //int e, marchaEngatada, op; //bool flagMarcha = false; rec = LogitechGSDK.LogiGetStateUnity(0); horizontalInput = (float)rec.lX / 32768; //volante Steer(); TurnSteeringWheel(); if (!isCarOn) //se carro estiver desligado não faz nada, só mexe o volante { CheckCarStart(); return; } accelInput = (float)(rec.lY - 32768) / -65536; brakeInput = 32767 - rec.lRz; //verticalInput = (float)(rec.lY - rec.lRz) / -65534; //rec.lY acelerador / rec.lRz freio int e = rec.rglSlider[0]; //embreagemSteer(); currentSpeed = carRigidbody.velocity.magnitude * 3.6f; Accelerate(); UpdateWheelPoses(); Stabilize(); } }
// Use this for initialization void Start() { LogitechGSDK.LogiSteeringInitialize(true); properties = new LogitechGSDK.LogiControllerPropertiesData(); properties.wheelRange = 900; LogitechGSDK.LogiSetPreferredControllerProperties(properties); wheelValue = 0.0f; valveCurrState = IsWheelValveClosed = true; for (int i = 0; i < 10; i++) { if (LogitechGSDK.LogiIsConnected(i)) { wheelIndex = i; } } joynames = new List <string>(Input.GetJoystickNames()); if (joynames[0].Contains("G27")) { axesName = "Joystick" + 0; } else { axesName = "Joystick" + 1; } }
/// <summary> /// 输入方式 /// </summary> public void InputValue() { //判断设备是否接入 if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { //获取键位值 LogitechGSDK.DIJOYSTATE2ENGINES rec; rec = LogitechGSDK.LogiGetStateUnity(0); steeringWheel = rec.lX / 32767f; //获取方向盘偏移量 accelerator = Mathf.Clamp01(rec.lY / -32767f); //获取油门偏移量 footbrake = Mathf.Clamp01(rec.lRz / -32767f); //获取刹车偏移量 clutch = rec.rglSlider[0] / -32767f; //获取偏移量 isStartEngine = LogitechGSDK.LogiButtonTriggered(0, 23); //判断是否启动引擎23 isOpenLowHeadLight = LogitechGSDK.LogiButtonTriggered(0, 11); //判断是否打开近光灯11 isOpenHighHeadLight = LogitechGSDK.LogiButtonTriggered(0, 10); //判断是否打开远光灯10 isOpenRightIndicator = LogitechGSDK.LogiButtonTriggered(0, 6); //判断是否打开右指示灯6 isOpenLeftIndicator = LogitechGSDK.LogiButtonTriggered(0, 7); //判断是否打开左指示灯7 isUseHandbrake = LogitechGSDK.LogiButtonTriggered(0, 2); //判断是否使用手刹2 isOpenDoubleFlash = LogitechGSDK.LogiButtonTriggered(0, 5); //判断是否打开双闪灯5 } else { steeringWheel = Input.GetAxis("Horizontal"); //获取方向盘偏移量 accelerator = Mathf.Clamp01(Input.GetAxis("Vertical")); //获取油门偏移量 footbrake = Mathf.Clamp01(-Input.GetAxis("Vertical")); //获取刹车偏移量 } }
private void DrivingInput() { if(LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)){ LogitechGSDK.LogiControllerPropertiesData actualProperties = new LogitechGSDK.LogiControllerPropertiesData(); LogitechGSDK.DIJOYSTATE2ENGINES rec; rec = LogitechGSDK.LogiGetStateUnity(0); direction = Mathf.Lerp(/*wheelDegrees/2*/1,/*-wheelDegrees/2*/-1,(-rec.lX /32767f + 1f)/2f); steeringWheelDegrees = Mathf.Lerp(wheelDegrees/2,-wheelDegrees/2,(-rec.lX /32767f + 1f)/2f); gasPedal = Mathf.Lerp(0,1,( -rec.lY/32767f + 1)/2 ); breakPedal = Mathf.Lerp(0,-1,( -rec.lRz/32767f + 1)/2); clutchPedal = Mathf.Lerp(0,1,( -rec.rglSlider[1]/32767f + 1)/2); gasbreak = gasPedal + breakPedal; gear = -1; for(int i = 8; i < 14; i++){ if(rec.rgbButtons[i] == 128){ gear = i - 7; if(gear == 6){ gear = 0; } break; } gear = -1; } } }
private void Update() { if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { MapAxesValues(); ApplyDamperForce(); ApplySpringForce(); } }
public bool change_car2() { if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero) { return(false); } return(LogitechGSDK.LogiGetStateCSharp(0).rgbButtons[12] == 128); }
public bool escape() { if (!LogitechGSDK.LogiUpdate() || !LogitechGSDK.LogiIsConnected(0) || LogitechGSDK.LogiGetStateENGINES(0) == IntPtr.Zero) { return(false); } return(LogitechGSDK.LogiGetStateCSharp(0).rgbButtons[24] != 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); }
/// <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); }
/// <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); }
void g29_control() { int rotationAngle = 0; int savedAngle = 0; const int thresholdAngle = 7; System.Random crandom = new System.Random(); rec = LogitechGSDK.LogiGetStateUnity(0); moveToDegree(WHEEL_RANGE / 2); // init, centering Thread.Sleep(1000); // sleep 1 sec while (true) { #if false if (loopCount++ > 10000) { if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { LogitechGSDK.LogiStopConstantForce(0); } break; } #endif rotationAngle = Convert.ToInt16(modelAngle); //Debug.Log ("savedAngle = "+savedAngle); //Debug.Log ("rotationAngle = "+rotationAngle); if (Math.Abs(savedAngle - rotationAngle) < thresholdAngle) { //Debug.Log ("continue"); Thread.Sleep(25 + crandom.Next(5, 25)); // random sleep,TBC continue; } savedAngle = rotationAngle; //rotationAngle = rotationAngle * 6; rotationAngle = rotationAngle * 2; if (manualMode == false) { moveToDegree((WHEEL_RANGE / 2) + rotationAngle); } Thread.Sleep(25 + crandom.Next(5, 25)); // random sleep,TBC } }
// Update is called once per frame void Update() { if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { LogitechGSDK.DIJOYSTATE2ENGINES rec; rec = LogitechGSDK.LogiGetStateUnity(0); xAxes = rec.lX / 32769f; gasInput = rec.lY; } else { print("Nicht verbunden."); } }
// Update is called once per frame /* void Update () * { * * if (recording) * storeRecord(); * else * startRecord(); * * } */ private void Update() { if (LogitechGSDK.LogiIsConnected(0) == false) { h = CrossPlatformInputManager.GetAxis("Horizontal"); v = CrossPlatformInputManager.GetAxis("Vertical"); b = CrossPlatformInputManager.GetAxis("Vertical"); } else { LogitechGSDK.DIJOYSTATE2ENGINES rec; rec = LogitechGSDK.LogiGetStateUnity(0); // pass the input to the car! //h = CrossPlatformInputManager.GetAxis("Horizontal"); h = Mathf.Abs(rec.lX - 32767); v = Mathf.Abs(rec.lY - 32767); b = -Mathf.Abs(rec.lRz - 32767); //Debug.Log(h + " "+ v +" " + b); } if (recording && carRB) { allData.Add(new List <object> { getZone(zoneName), getTime(), getSpeed(), getWheel(h), getBrake(b), getAcceleration(v), getPositionX(), getPositionZ() }); //Debug.Log(allData.Count); } if (Input.GetKeyDown(KeyCode.S)) { storeData(); } if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } if (Input.GetKeyDown(KeyCode.R)) { foreach (var item in allData) { item.Clear(); } allData.Clear(); SceneManager.LoadScene(SceneManager.GetActiveScene().name); } }
private void Update() { #if UNITY_STANDALONE_WIN if (handleIndex >= 0 && LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(handleIndex)) { LogitechGSDK.DIJOYSTATE2ENGINES rec; rec = LogitechGSDK.LogiGetStateUnity(handleIndex); Accel = (-rec.lY + 32768f) / 65535f * 0.65f; Brake = (-rec.lRz + 32768f) / 65535f; Clutch = (rec.rglSlider[1] + 32768f) / 65535f; if (rec.rgbButtons[8] == 128) { Gear = 1; } else if (rec.rgbButtons[9] == 128) { Gear = 2; } else if (rec.rgbButtons[10] == 128) { Gear = 3; } else if (rec.rgbButtons[11] == 128) { Gear = 4; } else if (rec.rgbButtons[12] == 128) { Gear = 5; } else if (rec.rgbButtons[13] == 128) { Gear = 6; } else { Gear = 0; } EngineToggle = rec.rgbButtons[18] == 128; return; } #endif UpdateGear(); UpdateAccel(); UpdateBrake(); UpdateClutch(); UpdateStartEngine(); }
public void update() { //All the test functions are called on the first device plugged in(index = 0) if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SPRING)) { LogitechGSDK.LogiStopSpringForce(0); } else { LogitechGSDK.LogiPlaySpringForce(0, 50, 50, 50); } } }
public static void Main(string[] args) { LogitechGSDK.LogiSteeringInitialize(false); Console.WriteLine("Gebe bitte den gewünschten Maximalwinkel ein (180° = 90° in jede Richtung)"); int response = Int32.Parse(Console.ReadLine()); Console.WriteLine($"Ist Lenkrad verbunden? {LogitechGSDK.LogiIsConnected(0)}"); while (true) { if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { LogitechGSDK.LogiStopSpringForce(0); LogitechGSDK.LogiPlaySpringForce(0, 0, 0, 0); LogitechGSDK.LogiSetOperatingRange(0, response); } } }
void moveToDegree(float deg) { deg = (deg / WHEEL_RANGE) * 100; moveToPos = Convert.ToInt16(deg); if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { int min, max; while (true) { rec = LogitechGSDK.LogiGetStateUnity(0); currentPos = normalize(rec.lX, -32767, +32767, 0, 100); if (deg < currentPos) { LogitechGSDK.LogiPlayConstantForce(0, +40); } else { LogitechGSDK.LogiPlayConstantForce(0, -40); } rec = LogitechGSDK.LogiGetStateUnity(0); currentPos = normalize(rec.lX, -32767, +32767, 0, 100); min = moveToPos - 1; max = moveToPos + 1; if (currentPos >= min && currentPos <= max) { //Debug.Log ("wheel at pos:" + currentPos); //Debug.Log ("move complete, turn off force"); LogitechGSDK.LogiPlayConstantForce(0, 0); //LogitechGSDK.LogiStopConstantForce (0); break; } } } }
// YC added void Update() { if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { if (moved == false) { moved = true; thread.Start(); } // enter key : manual/auto mode switch if (LogitechGSDK.LogiButtonTriggered(0, 23)) { manualMode = !manualMode; } // ps key : reload scene if (LogitechGSDK.LogiButtonTriggered(0, 24)) { loopCount = 0; Scene scene = SceneManager.GetActiveScene(); SceneManager.LoadScene(scene.name); } // option key : change scene if (LogitechGSDK.LogiButtonTriggered(0, 9)) { loopCount = 0; Scene scene = SceneManager.GetActiveScene(); if (scene.name == "JungleTrackAutonomous") { SceneManager.LoadScene("LakeTrackautonomous"); } else { SceneManager.LoadScene("JungleTrackAutonomous"); } } } }
private void Start() { Gear = 0; Accel = 0; Brake = 0; Clutch = 1; #if UNITY_STANDALONE_WIN if (LogitechGSDK.LogiSteeringInitialize(false)) { Debug.Log("LogiSteering Initialized"); LogitechGSDK.LogiControllerPropertiesData properties = new LogitechGSDK.LogiControllerPropertiesData(); properties.forceEnable = true; properties.overallGain = 100; properties.springGain = 100; properties.damperGain = 100; properties.defaultSpringEnabled = true; properties.defaultSpringGain = 100; properties.combinePedals = false; properties.wheelRange = 900; properties.gameSettingsEnabled = false; properties.allowGameSettings = false; LogitechGSDK.LogiSetPreferredControllerProperties(properties); for (int i = 0; ; i++) { if (!LogitechGSDK.LogiIsConnected(i)) { break; } if (LogitechGSDK.LogiIsDeviceConnected(i, LogitechGSDK.LOGI_DEVICE_TYPE_WHEEL)) { handleIndex = i; StringBuilder deviceName = new StringBuilder(256); LogitechGSDK.LogiGetFriendlyProductName(0, deviceName, 256); Debug.Log(deviceName); break; } } } #endif }
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); }
// Update is called once per frame void Update() { if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { LogitechGSDK.DIJOYSTATE2ENGINES wheel; wheel = LogitechGSDK.LogiGetStateUnity(0); x_axis = wheel.lX; // right is positive, left is negative throttle = wheel.lY; // negative is pressed. car_break = wheel.lZ; // positive is not pressed, negative is floored. clutch = wheel.rglSlider[0]; // positive is not pressed, negative is floored. //rec = LogitechGSDK.LogiGetStateUnity(0); //actualState += "x-axis position :" + rec.lX + "\n"; //actualState += "y-axis position :" + rec.lY + "\n"; //actualState += "z-axis position :" + rec.lZ + "\n"; //actualState += "x-axis rotation :" + rec.lRx + "\n"; //actualState += "y-axis rotation :" + rec.lRy + "\n"; //actualState += "z-axis rotation :" + rec.lRz + "\n"; //actualState += "extra axes positions 1 :" + rec.rglSlider[0] + "\n"; //actualState += "extra axes positions 2 :" + rec.rglSlider[1] + "\n"; } }
public void FixedUpdate() { if (isHardware && LogitechGSDK.LogiIsConnected (0)) { if ((SetGear != null && clutchPedal > 0.5f && prev_gear == -1 && gasPedal < 0.3f) || gear == -1) { SetGear (gear); } } else { if ((SetGear != null && clutchPedal > 0.5f) || gear == -1) { SetGear (gear); } } prev_gear = gear; if(Steering != null){ Steering(steeringWheelDegrees); } if(Move != null && (gasPedal > 0 || breakPedal < 0 || direction != 0)){ Move(direction,gasbreak); } }
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); }
// YC added void Awake() { ui = GameObject.Find("UISystem").GetComponent <UISystem> (); properties = new LogitechGSDK.LogiControllerPropertiesData(); properties.forceEnable = false; properties.overallGain = 100; properties.springGain = 100; properties.damperGain = 100; properties.defaultSpringEnabled = true; properties.defaultSpringGain = 100; properties.combinePedals = false; properties.wheelRange = WHEEL_RANGE; properties.gameSettingsEnabled = false; properties.allowGameSettings = false; LogitechGSDK.LogiSetPreferredControllerProperties(properties); initflag = LogitechGSDK.LogiSteeringInitialize(false); Debug.Log("SteeringInit:" + initflag); Thread.Sleep(500); // // move the wheel to generate a read event // if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { LogitechGSDK.LogiPlayConstantForce(0, 40); Thread.Sleep(20); } // generate thread, run later. thread = new Thread(g29_control); thread.IsBackground = true; }
/// <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; } } }
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"); } } }
// Update is called once per frame void Update() { //All the test functions are called on the first device plugged in(index = 0) if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { //CONTROLLER PROPERTIES StringBuilder deviceName = new StringBuilder(256); LogitechGSDK.LogiGetFriendlyProductName(0, deviceName, 256); propertiesEdit = "Current Controller : " + deviceName + "\n"; propertiesEdit += "Current controller properties : \n\n"; LogitechGSDK.LogiControllerPropertiesData actualProperties = new LogitechGSDK.LogiControllerPropertiesData(); LogitechGSDK.LogiGetCurrentControllerProperties(0, ref actualProperties); propertiesEdit += "forceEnable = " + actualProperties.forceEnable + "\n"; propertiesEdit += "overallGain = " + actualProperties.overallGain + "\n"; propertiesEdit += "springGain = " + actualProperties.springGain + "\n"; propertiesEdit += "damperGain = " + actualProperties.damperGain + "\n"; propertiesEdit += "defaultSpringEnabled = " + actualProperties.defaultSpringEnabled + "\n"; propertiesEdit += "combinePedals = " + actualProperties.combinePedals + "\n"; propertiesEdit += "wheelRange = " + actualProperties.wheelRange + "\n"; propertiesEdit += "gameSettingsEnabled = " + actualProperties.gameSettingsEnabled + "\n"; propertiesEdit += "allowGameSettings = " + actualProperties.allowGameSettings + "\n"; //CONTROLLER STATE actualState = "Steering wheel current state : \n\n"; LogitechGSDK.DIJOYSTATE2ENGINES rec; rec = LogitechGSDK.LogiGetStateUnity(0); actualState += "x-axis position :" + rec.lX + "\n"; actualState += "y-axis position :" + rec.lY + "\n"; actualState += "z-axis position :" + rec.lZ + "\n"; actualState += "x-axis rotation :" + rec.lRx + "\n"; actualState += "y-axis rotation :" + rec.lRy + "\n"; actualState += "z-axis rotation :" + rec.lRz + "\n"; actualState += "extra axes positions 1 :" + rec.rglSlider[0] + "\n"; actualState += "extra axes positions 2 :" + rec.rglSlider[1] + "\n"; switch (rec.rgdwPOV[0]) { case (0): actualState += "POV : UP\n"; break; case (4500): actualState += "POV : UP-RIGHT\n"; break; case (9000): actualState += "POV : RIGHT\n"; break; case (13500): actualState += "POV : DOWN-RIGHT\n"; break; case (18000): actualState += "POV : DOWN\n"; break; case (22500): actualState += "POV : DOWN-LEFT\n"; break; case (27000): actualState += "POV : LEFT\n"; break; case (31500): actualState += "POV : UP-LEFT\n"; break; default: actualState += "POV : CENTER\n"; break; } //Button status : buttonStatus = "Button pressed : \n\n"; for (int i = 0; i < 128; i++) { if (rec.rgbButtons[i] == 128) { buttonStatus += "Button " + i + " pressed\n"; } } /* THIS AXIS ARE NEVER REPORTED BY LOGITECH CONTROLLERS * * actualState += "x-axis velocity :" + rec.lVX + "\n"; * actualState += "y-axis velocity :" + rec.lVY + "\n"; * actualState += "z-axis velocity :" + rec.lVZ + "\n"; * actualState += "x-axis angular velocity :" + rec.lVRx + "\n"; * actualState += "y-axis angular velocity :" + rec.lVRy + "\n"; * actualState += "z-axis angular velocity :" + rec.lVRz + "\n"; * actualState += "extra axes velocities 1 :" + rec.rglVSlider[0] + "\n"; * actualState += "extra axes velocities 2 :" + rec.rglVSlider[1] + "\n"; * actualState += "x-axis acceleration :" + rec.lAX + "\n"; * actualState += "y-axis acceleration :" + rec.lAY + "\n"; * actualState += "z-axis acceleration :" + rec.lAZ + "\n"; * actualState += "x-axis angular acceleration :" + rec.lARx + "\n"; * actualState += "y-axis angular acceleration :" + rec.lARy + "\n"; * actualState += "z-axis angular acceleration :" + rec.lARz + "\n"; * actualState += "extra axes accelerations 1 :" + rec.rglASlider[0] + "\n"; * actualState += "extra axes accelerations 2 :" + rec.rglASlider[1] + "\n"; * actualState += "x-axis force :" + rec.lFX + "\n"; * actualState += "y-axis force :" + rec.lFY + "\n"; * actualState += "z-axis force :" + rec.lFZ + "\n"; * actualState += "x-axis torque :" + rec.lFRx + "\n"; * actualState += "y-axis torque :" + rec.lFRy + "\n"; * actualState += "z-axis torque :" + rec.lFRz + "\n"; * actualState += "extra axes forces 1 :" + rec.rglFSlider[0] + "\n"; * actualState += "extra axes forces 2 :" + rec.rglFSlider[1] + "\n"; */ int shifterTipe = LogitechGSDK.LogiGetShifterMode(0); string shifterString = ""; if (shifterTipe == 1) { shifterString = "Gated"; } else if (shifterTipe == 0) { shifterString = "Sequential"; } else { shifterString = "Unknown"; } actualState += "\nSHIFTER MODE:" + shifterString; // FORCES AND EFFECTS activeForces = "Active forces and effects :\n"; //Spring Force -> S if (Input.GetKeyUp(KeyCode.S)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SPRING)) { LogitechGSDK.LogiStopSpringForce(0); activeForceAndEffect[0] = ""; } else { LogitechGSDK.LogiPlaySpringForce(0, 50, 50, 50); activeForceAndEffect[0] = "Spring Force\n "; } } //Constant Force -> C if (Input.GetKeyUp(KeyCode.C)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_CONSTANT)) { LogitechGSDK.LogiStopConstantForce(0); activeForceAndEffect[1] = ""; } else { LogitechGSDK.LogiPlayConstantForce(0, 50); activeForceAndEffect[1] = "Constant Force\n "; } } //Damper Force -> D if (Input.GetKeyUp(KeyCode.D)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_DAMPER)) { LogitechGSDK.LogiStopDamperForce(0); activeForceAndEffect[2] = ""; } else { LogitechGSDK.LogiPlayDamperForce(0, 50); activeForceAndEffect[2] = "Damper Force\n "; } } //Side Collision Force -> left or right arrow if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)) { LogitechGSDK.LogiPlaySideCollisionForce(0, 60); } //Front Collision Force -> up arrow if (Input.GetKeyUp(KeyCode.UpArrow)) { LogitechGSDK.LogiPlayFrontalCollisionForce(0, 60); } //Dirt Road Effect-> I if (Input.GetKeyUp(KeyCode.I)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_DIRT_ROAD)) { LogitechGSDK.LogiStopDirtRoadEffect(0); activeForceAndEffect[3] = ""; } else { LogitechGSDK.LogiPlayDirtRoadEffect(0, 50); activeForceAndEffect[3] = "Dirt Road Effect\n "; } } //Bumpy Road Effect-> B if (Input.GetKeyUp(KeyCode.B)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_BUMPY_ROAD)) { LogitechGSDK.LogiStopBumpyRoadEffect(0); activeForceAndEffect[4] = ""; } else { LogitechGSDK.LogiPlayBumpyRoadEffect(0, 50); activeForceAndEffect[4] = "Bumpy Road Effect\n"; } } //Slippery Road Effect-> L if (Input.GetKeyUp(KeyCode.L)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SLIPPERY_ROAD)) { LogitechGSDK.LogiStopSlipperyRoadEffect(0); activeForceAndEffect[5] = ""; } else { LogitechGSDK.LogiPlaySlipperyRoadEffect(0, 50); activeForceAndEffect[5] = "Slippery Road Effect\n "; } } //Surface Effect-> U if (Input.GetKeyUp(KeyCode.U)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SURFACE_EFFECT)) { LogitechGSDK.LogiStopSurfaceEffect(0); activeForceAndEffect[6] = ""; } else { LogitechGSDK.LogiPlaySurfaceEffect(0, LogitechGSDK.LOGI_PERIODICTYPE_SQUARE, 50, 1000); activeForceAndEffect[6] = "Surface Effect\n"; } } //Car Airborne -> A if (Input.GetKeyUp(KeyCode.A)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_CAR_AIRBORNE)) { LogitechGSDK.LogiStopCarAirborne(0); activeForceAndEffect[7] = ""; } else { LogitechGSDK.LogiPlayCarAirborne(0); activeForceAndEffect[7] = "Car Airborne\n "; } } //Soft Stop Force -> O if (Input.GetKeyUp(KeyCode.O)) { if (LogitechGSDK.LogiIsPlaying(0, LogitechGSDK.LOGI_FORCE_SOFTSTOP)) { LogitechGSDK.LogiStopSoftstopForce(0); activeForceAndEffect[8] = ""; } else { LogitechGSDK.LogiPlaySoftstopForce(0, 20); activeForceAndEffect[8] = "Soft Stop Force\n"; } } //Set preferred controller properties -> PageUp if (Input.GetKeyUp(KeyCode.PageUp)) { //Setting example values properties.wheelRange = 90; properties.forceEnable = true; properties.overallGain = 80; properties.springGain = 80; properties.damperGain = 80; properties.allowGameSettings = true; properties.combinePedals = false; properties.defaultSpringEnabled = true; properties.defaultSpringGain = 80; LogitechGSDK.LogiSetPreferredControllerProperties(properties); } //Play leds -> P if (Input.GetKeyUp(KeyCode.P)) { LogitechGSDK.LogiPlayLeds(0, 20, 20, 20); } for (int i = 0; i < 9; i++) { activeForces += activeForceAndEffect[i]; } } else if (!LogitechGSDK.LogiIsConnected(0)) { actualState = "PLEASE PLUG IN A STEERING WHEEL OR A FORCE FEEDBACK CONTROLLER"; } else { actualState = "THIS WINDOW NEEDS TO BE IN FOREGROUND IN ORDER FOR THE SDK TO WORK PROPERLY"; } }
void FixedUpdate() { if (LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)) { LogitechGSDK.DIJOYSTATE2ENGINES rec; float h, v, velo; int e, marchaEngatada, op; //bool flagMarcha = false; rec = LogitechGSDK.LogiGetStateUnity(0); h = (float)rec.lX / 32768; //volante v = (float)(rec.lY - rec.lRz) / -65534; //rec.lY acelerador / rec.lRz freio e = rec.rglSlider[0]; //embreagem velo = m_Car.CurrentSpeed; marchaEngatada = getMarchaEngatada(); if (e < 0) { rpmaux = rpm > rpmaux ? rpm : rpmaux; //pega o maior rpm depois de pisar na embreagem rpm = changeRpm(-7, 1); //rotacao cai if (marchaEngatada > -1) // && velo > rangeMarchas[marchaEngatada,0]) { //calcula nova rotacao - se a rotacao anterior estiver baixa come�a com pouco, se tiver alta come�a com alto - ver se esta dentro da raange normal //coloca uma marcha verifica se a velo ta no range, se tiver abaixo reduz, se tiver acima acelera pouco, se tiver entre normal if (marchaAtual != marchaEngatada) { if (velo > rangeMarchas[marchaEngatada, 0] && velo < rangeMarchas[marchaEngatada, 1]) //velocidade normal - rotacao normal { op = 0; } else if (velo > rangeMarchas[marchaEngatada, 1]) //velocidade acima do range - rotacao fica alta { op = 1; } else //velocidade abaixo do range - rotacao fica baixa { op = 2; } //Debug.Log("op = " + op); //Debug.Log("marcha atual = " + marchaAtual + " marcha engatada = " + marchaEngatada); rpm = newRpm(op, marchaAtual - marchaEngatada, rpmaux); marchaAtual = marchaEngatada; } } } else { rpmaux = 0; if (marchaAtual == marchaEngatada) //engatou a marcha { if (marchaAtual == 0) // ré { v *= -1; } if (v < 0)//freiando { brakerate -= 0.1f; rpm = changeRpm(-10, v * brakerate); //Debug.Log("brakerate = "+ brakerate + " v = " + v); } else { brakerate = 0; rpm = changeRpm(10, v); } } else if (marchaEngatada == -1)//ponto morto { } } // o que fazer = reduzir drasticamente ou esgasgar o motor / deixar acelerar devagar [marchas erradas] & manter marcha nao engatada & r� //quando freia tem que perder rpm tbm if (marchaEngatada >= 0) { m_Car.Move(h, v, v, 0); } else { m_Car.Move(h, 0, 0, 0);// o ultimo � o freio de mao } //Debug.Log("velo = " + velo); //Debug.Log("marcha atual = " + marchaAtual + "marcha engatada = " + marchaEngatada); //Debug.Log("h = " + h + "v = " + v); moverVolante(h); //speedometer.text = string.Format("{0,00}", velo) + " - " + marchaAtual; //rotationsPerMinute.text = "rpm = " + rpm; m_Car.Move(h, v, v, 0); } }