This commit is contained in:
parent
984bc9a853
commit
7ea6ef5529
File diff suppressed because it is too large
Load Diff
|
@ -38,12 +38,12 @@ RenderSettings:
|
||||||
m_ReflectionIntensity: 1
|
m_ReflectionIntensity: 1
|
||||||
m_CustomReflection: {fileID: 0}
|
m_CustomReflection: {fileID: 0}
|
||||||
m_Sun: {fileID: 0}
|
m_Sun: {fileID: 0}
|
||||||
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
|
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
|
||||||
m_UseRadianceAmbientProbe: 0
|
m_UseRadianceAmbientProbe: 0
|
||||||
--- !u!157 &3
|
--- !u!157 &3
|
||||||
LightmapSettings:
|
LightmapSettings:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
serializedVersion: 11
|
serializedVersion: 12
|
||||||
m_GIWorkflowMode: 1
|
m_GIWorkflowMode: 1
|
||||||
m_GISettings:
|
m_GISettings:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
|
@ -98,7 +98,7 @@ LightmapSettings:
|
||||||
m_TrainingDataDestination: TrainingData
|
m_TrainingDataDestination: TrainingData
|
||||||
m_LightProbeSampleCountMultiplier: 4
|
m_LightProbeSampleCountMultiplier: 4
|
||||||
m_LightingDataAsset: {fileID: 0}
|
m_LightingDataAsset: {fileID: 0}
|
||||||
m_UseShadowmask: 1
|
m_LightingSettings: {fileID: 0}
|
||||||
--- !u!196 &4
|
--- !u!196 &4
|
||||||
NavMeshSettings:
|
NavMeshSettings:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
|
@ -118,6 +118,8 @@ NavMeshSettings:
|
||||||
manualTileSize: 0
|
manualTileSize: 0
|
||||||
tileSize: 256
|
tileSize: 256
|
||||||
accuratePlacement: 0
|
accuratePlacement: 0
|
||||||
|
maxJobWorkers: 0
|
||||||
|
preserveTilesOutsideBounds: 0
|
||||||
debug:
|
debug:
|
||||||
m_Flags: 0
|
m_Flags: 0
|
||||||
m_NavMeshData: {fileID: 0}
|
m_NavMeshData: {fileID: 0}
|
||||||
|
@ -131,6 +133,7 @@ GameObject:
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 466370289}
|
- component: {fileID: 466370289}
|
||||||
- component: {fileID: 466370290}
|
- component: {fileID: 466370290}
|
||||||
|
- component: {fileID: 466370291}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: APP
|
m_Name: APP
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -164,6 +167,18 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: beb73c429dba468f8a8c37893d1204b8, type: 3}
|
m_Script: {fileID: 11500000, guid: beb73c429dba468f8a8c37893d1204b8, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
--- !u!114 &466370291
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 466370288}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 374ccbdc1a0c8d8478a9e49fd1215a18, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
--- !u!1 &634617318
|
--- !u!1 &634617318
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -323,6 +338,7 @@ Light:
|
||||||
m_UseColorTemperature: 0
|
m_UseColorTemperature: 0
|
||||||
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
|
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
|
||||||
m_UseBoundingSphereOverride: 0
|
m_UseBoundingSphereOverride: 0
|
||||||
|
m_UseViewFrustumForShadowCasterCull: 1
|
||||||
m_ShadowRadius: 0
|
m_ShadowRadius: 0
|
||||||
m_ShadowAngle: 0
|
m_ShadowAngle: 0
|
||||||
--- !u!4 &815764611
|
--- !u!4 &815764611
|
||||||
|
|
|
@ -22,111 +22,118 @@ namespace Script
|
||||||
public float xx;
|
public float xx;
|
||||||
float steerInput, throttleInput, brakeInput, handbrakeInput;
|
float steerInput, throttleInput, brakeInput, handbrakeInput;
|
||||||
|
|
||||||
private ModbusTcpClient client;
|
|
||||||
private CarStatusData carData;
|
private CarStatusData carData;
|
||||||
|
|
||||||
float minValue = -300f; // 范围的最小值
|
float minValue = -300f; // 范围的最小值
|
||||||
float maxValue = 300; // 范围的最大值
|
float maxValue = 300; // 范围的最大值
|
||||||
|
|
||||||
public CarInfoManager carInfoManager;
|
public CarInfoManager carInfoManager;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
vehicleController = GetComponent<VehicleController>();
|
vehicleController = GetComponent<VehicleController>();
|
||||||
vehicleStandardInput = GetComponent<VehicleStandardInput>();
|
vehicleStandardInput = GetComponent<VehicleStandardInput>();
|
||||||
|
|
||||||
StartModbus();
|
// StartModbus();
|
||||||
ModBusQueue();
|
ModBusQueue();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task StartModbus()
|
// async Task StartModbus()
|
||||||
{
|
// {
|
||||||
client = new ModbusTcpClient();
|
// client = new ModbusTcpClient();
|
||||||
await client.ConnectToServer();
|
// await client.ConnectToServer();
|
||||||
while (true)
|
// while (true)
|
||||||
{
|
// {
|
||||||
await client.SendModbusRequest();
|
// await client.SendModbusRequest();
|
||||||
|
//
|
||||||
|
// await Task.Delay(TimeSpan.FromSeconds(.1));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
await Task.Delay(TimeSpan.FromSeconds(.1));
|
// void OnDestroy()
|
||||||
}
|
// {
|
||||||
}
|
// client.CloseConnection();
|
||||||
|
// }
|
||||||
void OnDestroy()
|
|
||||||
{
|
|
||||||
client.CloseConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task ModBusQueue()
|
async Task ModBusQueue()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (client.modbusQueue.Count > 0)
|
// Debug.Log(client.modbusQueue.Count);
|
||||||
|
if (ModbusTcpClient.modbusTcpClient.modbusQueue.Count > 0)
|
||||||
{
|
{
|
||||||
carData = client.modbusQueue.Dequeue();
|
carData = ModbusTcpClient.modbusTcpClient.modbusQueue.Dequeue();
|
||||||
// Debug.Log(carData.SteeringWheelAngle);
|
|
||||||
//方向盘
|
//方向盘
|
||||||
vehicleController.steerInput = NormalizeValue(carData.SteeringWheelAngle, minValue, maxValue);
|
vehicleController.steerInput = NormalizeValue(carData.SteeringWheelAngle, minValue, maxValue);
|
||||||
//手刹
|
//手刹
|
||||||
// vehicleController.throttleInput = carData.HandbrakeStatus == 0 ? 1 : 0;
|
// vehicleController.throttleInput = carData.HandbrakeStatus == 0 ? 1 : 0;
|
||||||
//挡位 00空挡,1前进档,2倒挡,3为P档
|
//挡位 00空挡,1前进档,2倒挡,3为P档
|
||||||
switch (carData.GearPosition)
|
//当钥匙为点火状态,才能启动车
|
||||||
|
if (carData.IgnitionSwitch == 2)
|
||||||
{
|
{
|
||||||
case 0:
|
switch (carData.GearPosition)
|
||||||
break;
|
{
|
||||||
case 1://1前进档
|
case 0:
|
||||||
if (carData.HandbrakeStatus == 0)
|
break;
|
||||||
{
|
case 1: //1前进档
|
||||||
if (carData.AcceleratorPedalPosition > 0)
|
if (carData.HandbrakeStatus == 0)
|
||||||
{
|
{
|
||||||
vehicleController.throttleInput = 1;
|
if (carData.AcceleratorPedalPosition > 30)
|
||||||
|
{
|
||||||
|
vehicleController.throttleInput = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vehicleController.throttleInput = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vehicleController.throttleInput = 0;
|
vehicleController.throttleInput = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vehicleController.throttleInput = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 2://2倒挡
|
case 2: //2倒挡
|
||||||
if (carData.HandbrakeStatus == 0)
|
if (carData.HandbrakeStatus == 0)
|
||||||
{
|
|
||||||
if (carData.AcceleratorPedalPosition > 0)
|
|
||||||
{
|
{
|
||||||
vehicleController.throttleInput = -0.5f;
|
if (carData.AcceleratorPedalPosition > 30)
|
||||||
|
{
|
||||||
|
vehicleController.throttleInput = -0.5f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vehicleController.throttleInput = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vehicleController.throttleInput = 0;
|
vehicleController.throttleInput = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
break;
|
||||||
{
|
case 3:
|
||||||
vehicleController.throttleInput = 0;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//转向灯 00是未开转向灯,1是左转向灯,2是右转向灯
|
//转向灯 00是未开转向灯,1是左转向灯,2是右转向灯
|
||||||
switch (carData.TurnSignalStatus)
|
//当钥匙转为通电才能启动转向灯 0熄火,1通电,2启动
|
||||||
|
if (carData.IgnitionSwitch == 1)
|
||||||
{
|
{
|
||||||
case 0:
|
switch (carData.TurnSignalStatus)
|
||||||
carInfoManager.StopBlinking();
|
{
|
||||||
break;
|
case 0:
|
||||||
case 1:
|
carInfoManager.StopBlinking();
|
||||||
carInfoManager.LeftStartBlinking();
|
break;
|
||||||
break;
|
case 1:
|
||||||
case 2:
|
carInfoManager.LeftStartBlinking();
|
||||||
carInfoManager.RightStartBlinking();
|
break;
|
||||||
break;
|
case 2:
|
||||||
|
carInfoManager.RightStartBlinking();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(TimeSpan.FromSeconds(.1));
|
await Task.Delay(TimeSpan.FromSeconds(.1));
|
||||||
|
@ -144,8 +151,8 @@ namespace Script
|
||||||
|
|
||||||
//vehicleController.steerInput = 0;
|
//vehicleController.steerInput = 0;
|
||||||
|
|
||||||
vehicleController.brakeInput = 0;
|
// vehicleController.brakeInput = 0;
|
||||||
vehicleController.handbrakeInput = 0;
|
// vehicleController.handbrakeInput = 0;
|
||||||
//Debug.Log($"{steerInput}--{throttleInput}--{brakeInput}--{handbrakeInput}");
|
//Debug.Log($"{steerInput}--{throttleInput}--{brakeInput}--{handbrakeInput}");
|
||||||
|
|
||||||
// vehicleStandardInput.SetThrottleValue(xx);
|
// vehicleStandardInput.SetThrottleValue(xx);
|
||||||
|
|
|
@ -123,14 +123,13 @@ public class CarInfoManager : MonoBehaviour
|
||||||
#region 转向灯动画
|
#region 转向灯动画
|
||||||
|
|
||||||
public void LeftStartBlinking()
|
public void LeftStartBlinking()
|
||||||
{ Indicator.SetActive(false);
|
{
|
||||||
Indicator = leftIndicator;
|
Indicator = leftIndicator;
|
||||||
StartBlinking(Indicator);
|
StartBlinking(Indicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RightStartBlinking()
|
public void RightStartBlinking()
|
||||||
{
|
{
|
||||||
Indicator.SetActive(false);
|
|
||||||
Indicator = rightIndicator;
|
Indicator = rightIndicator;
|
||||||
StartBlinking(Indicator);
|
StartBlinking(Indicator);
|
||||||
}
|
}
|
||||||
|
@ -157,6 +156,10 @@ public class CarInfoManager : MonoBehaviour
|
||||||
// 停止闪烁的方法
|
// 停止闪烁的方法
|
||||||
public void StopBlinking()
|
public void StopBlinking()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(!isBlinking)
|
||||||
|
return;
|
||||||
|
|
||||||
isBlinking = false;
|
isBlinking = false;
|
||||||
if (cancellationTokenSource != null)
|
if (cancellationTokenSource != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,14 +9,14 @@ public class CarManager : MonoBehaviour
|
||||||
public GameObject puncture; //爆胎
|
public GameObject puncture; //爆胎
|
||||||
public GameObject UIl;
|
public GameObject UIl;
|
||||||
|
|
||||||
private void OnTriggerEnter(Collider other)
|
// private void OnTriggerEnter(Collider other)
|
||||||
{
|
// {
|
||||||
if (other.name == "爆胎")
|
// if (other.name == "爆胎")
|
||||||
{
|
// {
|
||||||
puncture.SetActive(true);
|
// puncture.SetActive(true);
|
||||||
UIl.SetActive(true);
|
// UIl.SetActive(true);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// /// <summary>
|
// /// <summary>
|
||||||
// /// 爆胎
|
// /// 爆胎
|
||||||
|
|
|
@ -27,18 +27,49 @@ public class CarStatusData
|
||||||
|
|
||||||
namespace ModbusManager
|
namespace ModbusManager
|
||||||
{
|
{
|
||||||
public class ModbusTcpClient
|
public class ModbusTcpClient:MonoBehaviour
|
||||||
{
|
{
|
||||||
private TcpClient tcpClient;
|
private TcpClient tcpClient;
|
||||||
private string serverIp = "172.16.1.125";
|
private string serverIp = "172.16.1.125";
|
||||||
private int serverPort = 12315;
|
private int serverPort = 12315;
|
||||||
public Queue<CarStatusData> modbusQueue;
|
public Queue<CarStatusData> modbusQueue;
|
||||||
public ModbusTcpClient()
|
public static ModbusTcpClient modbusTcpClient;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
modbusTcpClient = this;
|
||||||
|
|
||||||
tcpClient = new TcpClient();
|
tcpClient = new TcpClient();
|
||||||
modbusQueue = new Queue<CarStatusData>();
|
modbusQueue = new Queue<CarStatusData>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
StartModbus();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task StartModbus()
|
||||||
|
{
|
||||||
|
await ConnectToServer();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
await SendModbusRequest();
|
||||||
|
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(.1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
CloseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
// public ModbusTcpClient()
|
||||||
|
// {
|
||||||
|
// tcpClient = new TcpClient();
|
||||||
|
// modbusQueue = new Queue<CarStatusData>();
|
||||||
|
// }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 接口为TCP/IP接口。
|
/// 接口为TCP/IP接口。
|
||||||
/// 协议为MODBUS/TCP,数据为十六进制数据。
|
/// 协议为MODBUS/TCP,数据为十六进制数据。
|
||||||
|
@ -74,7 +105,7 @@ namespace ModbusManager
|
||||||
if (stream.CanWrite)
|
if (stream.CanWrite)
|
||||||
{
|
{
|
||||||
await stream.WriteAsync(request, 0, request.Length);
|
await stream.WriteAsync(request, 0, request.Length);
|
||||||
//Debug.LogLine("Modbus请求已发送。");
|
// Debug.Log("Modbus请求已发送。");
|
||||||
await ReadResponse(stream);
|
await ReadResponse(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,19 +169,19 @@ namespace ModbusManager
|
||||||
carStatusData.BrakePedalPosition = dataValue;
|
carStatusData.BrakePedalPosition = dataValue;
|
||||||
break;
|
break;
|
||||||
case 4://0-100,踩到底为100
|
case 4://0-100,踩到底为100
|
||||||
// Debug.Log($"油门踏板数据: {dataValue}");
|
// Debug.Log($"油门踏板数据: {dataValue}");
|
||||||
carStatusData.AcceleratorPedalPosition = dataValue;
|
carStatusData.AcceleratorPedalPosition = dataValue;
|
||||||
break;
|
break;
|
||||||
case 5://0-100,踩到底为100
|
case 5://0-100,踩到底为100
|
||||||
//Debug.Log($"离合踏板数据: {dataValue}");
|
Debug.Log($"离合踏板数据: {dataValue}");
|
||||||
carStatusData.ClutchPedalPosition = dataValue;
|
carStatusData.ClutchPedalPosition = dataValue;
|
||||||
break;
|
break;
|
||||||
case 6://01表示手刹有效
|
case 6://01表示手刹有效
|
||||||
// Debug.Log($"手刹数据: {dataValue}");
|
// Debug.Log($"手刹数据: {dataValue}");
|
||||||
carStatusData.HandbrakeStatus = dataValue;
|
carStatusData.HandbrakeStatus = dataValue;
|
||||||
break;
|
break;
|
||||||
case 7://00空挡,1前进档,2倒挡,3为P档
|
case 7://00空挡,1前进档,2倒挡,3为P档
|
||||||
// Debug.Log($"挡位数据: {dataValue}");
|
// Debug.Log($"挡位数据: {dataValue}");
|
||||||
carStatusData.GearPosition = dataValue;
|
carStatusData.GearPosition = dataValue;
|
||||||
break;
|
break;
|
||||||
case 8://00是空档,1是手动一次雨刮,2是自动雨刮慢速,3是自动雨刮快速
|
case 8://00是空档,1是手动一次雨刮,2是自动雨刮慢速,3是自动雨刮快速
|
||||||
|
@ -162,7 +193,7 @@ namespace ModbusManager
|
||||||
carStatusData.LightStatus = dataValue;
|
carStatusData.LightStatus = dataValue;
|
||||||
break;
|
break;
|
||||||
case 10://00是未开转向灯,1是左转向灯,2是右转向灯
|
case 10://00是未开转向灯,1是左转向灯,2是右转向灯
|
||||||
Debug.Log($"转向灯状态: {dataValue}");
|
// Debug.Log($"转向灯状态: {dataValue}");
|
||||||
carStatusData.TurnSignalStatus = dataValue;
|
carStatusData.TurnSignalStatus = dataValue;
|
||||||
break;
|
break;
|
||||||
case 11://00是熄火,1是通电,2是点火
|
case 11://00是熄火,1是通电,2是点火
|
||||||
|
@ -170,7 +201,7 @@ namespace ModbusManager
|
||||||
carStatusData.KeyStatus = dataValue;
|
carStatusData.KeyStatus = dataValue;
|
||||||
break;
|
break;
|
||||||
case 12://上1,右2,下3,左4
|
case 12://上1,右2,下3,左4
|
||||||
//Debug.Log($"按键数据: {dataValue}");
|
// Debug.Log($"按键数据: {dataValue}");
|
||||||
carStatusData.ButtonData = dataValue;
|
carStatusData.ButtonData = dataValue;
|
||||||
break;
|
break;
|
||||||
// default:
|
// default:
|
||||||
|
@ -181,6 +212,8 @@ namespace ModbusManager
|
||||||
|
|
||||||
|
|
||||||
modbusQueue.Enqueue(carStatusData);
|
modbusQueue.Enqueue(carStatusData);
|
||||||
|
|
||||||
|
// Debug.Log(modbusQueue.Count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ModbusManager;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI; // 如果您使用的是UGUI
|
using UnityEngine.UI; // 如果您使用的是UGUI
|
||||||
|
|
||||||
public class SteeringWheelController : MonoBehaviour
|
public class SteeringWheelController : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static SteeringWheelController Instance;
|
public static SteeringWheelController Instance;
|
||||||
|
|
||||||
public Button[] buttons;
|
public Button[] buttons;
|
||||||
private int selectedButtonIndex = 0; // 当前选中的按钮索引
|
private int selectedButtonIndex = 0; // 当前选中的按钮索引
|
||||||
private bool hasSelected = false; // 是否已经进行了选择
|
private bool hasSelected = false; // 是否已经进行了选择
|
||||||
|
|
||||||
|
@ -21,22 +23,31 @@ public class SteeringWheelController : MonoBehaviour
|
||||||
|
|
||||||
|
|
||||||
public float testFloatV;
|
public float testFloatV;
|
||||||
|
float minValue = -300f; // 范围的最小值
|
||||||
|
float maxValue = 300; // 范围的最大值
|
||||||
|
|
||||||
|
|
||||||
|
private int NewValue = -1;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
private void Start()
|
||||||
{
|
{
|
||||||
// 更新方向盘角度
|
ModBusQueue();
|
||||||
UpdateSteeringWheelAngle();
|
|
||||||
|
|
||||||
// 检查方向盘角度并更新选中的按钮
|
|
||||||
CheckSteeringWheelAngle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void Update()
|
||||||
|
// {
|
||||||
|
// // 更新方向盘角度
|
||||||
|
// // UpdateSteeringWheelAngle();
|
||||||
|
//
|
||||||
|
// // 检查方向盘角度并更新选中的按钮
|
||||||
|
// CheckSteeringWheelAngle();
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
public void SSSS()
|
public void SSSS()
|
||||||
{
|
{
|
||||||
|
@ -53,41 +64,88 @@ public class SteeringWheelController : MonoBehaviour
|
||||||
testFloatV = -45;
|
testFloatV = -45;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
async Task ModBusQueue()
|
||||||
/// 更新方向盘角度
|
|
||||||
/// </summary>
|
|
||||||
private void UpdateSteeringWheelAngle()
|
|
||||||
{
|
{
|
||||||
// 这里需要替换成获取硬件方向盘角度的代码
|
while (true)
|
||||||
steeringWheelAngle = testFloatV;
|
{
|
||||||
|
// Debug.Log(client.modbusQueue.Count);
|
||||||
|
if (ModbusTcpClient.modbusTcpClient.modbusQueue.Count > 0)
|
||||||
|
{
|
||||||
|
CarStatusData carData = ModbusTcpClient.modbusTcpClient.modbusQueue.Dequeue();
|
||||||
|
|
||||||
|
if (carData.ClutchPedalPosition > 30)
|
||||||
|
{
|
||||||
|
SelectButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NewValue != carData.ButtonData)
|
||||||
|
{
|
||||||
|
NewValue = carData.ButtonData;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckSteeringWheelAngle(NewValue);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(.1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /// <summary>
|
||||||
|
// /// 更新方向盘角度
|
||||||
|
// /// </summary>
|
||||||
|
// private void UpdateSteeringWheelAngle()
|
||||||
|
// {
|
||||||
|
// // 这里需要替换成获取硬件方向盘角度的代码
|
||||||
|
// steeringWheelAngle = testFloatV;
|
||||||
|
// }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 判断方向盘左边还是右边
|
/// 判断方向盘左边还是右边 //上1,右2,下3,左4
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void CheckSteeringWheelAngle()
|
private void CheckSteeringWheelAngle(int btvalue)
|
||||||
{
|
{
|
||||||
if (Mathf.Abs(steeringWheelAngle) < neutralAngleThreshold)
|
if (btvalue > 0)
|
||||||
{
|
{
|
||||||
hasSelected = false;
|
if (btvalue == 4)
|
||||||
return;
|
{
|
||||||
|
SelectPreviousButton();
|
||||||
|
}
|
||||||
|
else if (btvalue == 2)
|
||||||
|
{
|
||||||
|
SelectNextButton();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasSelected)
|
|
||||||
{
|
// if (Mathf.Abs(steeringWheelAngle) < neutralAngleThreshold)
|
||||||
if (steeringWheelAngle > selectionAngleThreshold)
|
// {
|
||||||
{
|
// hasSelected = false;
|
||||||
// 向右转动
|
// return;
|
||||||
SelectNextButton();
|
// }
|
||||||
hasSelected = true;
|
|
||||||
}
|
// if (!hasSelected)
|
||||||
else if (steeringWheelAngle < -selectionAngleThreshold)
|
// {
|
||||||
{
|
// if (steeringWheelAngle > selectionAngleThreshold)
|
||||||
// 向左转动
|
// {
|
||||||
SelectPreviousButton();
|
// // 向右转动
|
||||||
hasSelected = true;
|
// SelectNextButton();
|
||||||
}
|
// hasSelected = true;
|
||||||
}
|
// }
|
||||||
|
// else if (steeringWheelAngle < -selectionAngleThreshold)
|
||||||
|
// {
|
||||||
|
// // 向左转动
|
||||||
|
// SelectPreviousButton();
|
||||||
|
// hasSelected = true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -96,7 +154,7 @@ public class SteeringWheelController : MonoBehaviour
|
||||||
private void SelectNextButton()
|
private void SelectNextButton()
|
||||||
{
|
{
|
||||||
selectedButtonIndex = (selectedButtonIndex + 1) % buttons.Length;
|
selectedButtonIndex = (selectedButtonIndex + 1) % buttons.Length;
|
||||||
Debug.Log("前进" + selectedButtonIndex);
|
// Debug.Log("前进" + selectedButtonIndex);
|
||||||
HighlightButton(selectedButtonIndex);
|
HighlightButton(selectedButtonIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,20 +169,19 @@ public class SteeringWheelController : MonoBehaviour
|
||||||
selectedButtonIndex--;
|
selectedButtonIndex--;
|
||||||
|
|
||||||
|
|
||||||
Debug.Log("后退" + selectedButtonIndex);
|
// Debug.Log("后退" + selectedButtonIndex);
|
||||||
HighlightButton(selectedButtonIndex);
|
HighlightButton(selectedButtonIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 选择按钮变换
|
/// 选择按钮变换
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="index"></param>
|
/// <param name="index"></param>
|
||||||
public void HighlightButton(int index)
|
public void HighlightButton(int index)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i = 0; i < buttons.Length; i++)
|
for (int i = 0; i < buttons.Length; i++)
|
||||||
{
|
{
|
||||||
if (buttons[i].name == buttons[index].name)
|
if (buttons[i].name == buttons[index].name)
|
||||||
{
|
{
|
||||||
buttons[i].GetComponent<BtClick>().OnClickSprite();
|
buttons[i].GetComponent<BtClick>().OnClickSprite();
|
||||||
}
|
}
|
||||||
|
@ -155,4 +212,15 @@ public class SteeringWheelController : MonoBehaviour
|
||||||
{
|
{
|
||||||
buttons[selectedButtonIndex].GetComponent<Button>().onClick.Invoke();
|
buttons[selectedButtonIndex].GetComponent<Button>().onClick.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float NormalizeValue(float originalValue, float minValue, float maxValue)
|
||||||
|
{
|
||||||
|
// 确保原始值在范围内
|
||||||
|
float clampedValue = Math.Max(minValue, Math.Min(originalValue, maxValue));
|
||||||
|
|
||||||
|
// 计算归一化值
|
||||||
|
float normalizedValue = (2 * (clampedValue - minValue) / (maxValue - minValue)) - 1;
|
||||||
|
|
||||||
|
return normalizedValue;
|
||||||
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
||||||
|
Using pre-set license
|
||||||
|
Built from '2021.1/staging' branch; Version is '2021.1.24f1 (6667702a1e7c) revision 6711152'; Using compiler version '192528614'; Build Type 'Release'
|
||||||
|
OS: 'Windows 10 Pro; OS build 19044.1682; Version 2009; 64bit' Language: 'zh' Physical Memory: 16197 MB
|
||||||
|
BatchMode: 1, IsHumanControllingUs: 0, StartBugReporterOnCrash: 0, Is64bit: 1, IsPro: 0
|
||||||
|
|
||||||
|
COMMAND LINE ARGUMENTS:
|
||||||
|
D:\2021.1.24f1\Editor\Unity.exe
|
||||||
|
-adb2
|
||||||
|
-batchMode
|
||||||
|
-noUpm
|
||||||
|
-name
|
||||||
|
AssetImportWorker1
|
||||||
|
-projectPath
|
||||||
|
E:/Unity Projects/GitLab/2023/H_SafeExperienceDrivingSystem/U3D_DrivingSystem
|
||||||
|
-logFile
|
||||||
|
Logs/AssetImportWorker1.log
|
||||||
|
-srvPort
|
||||||
|
57189
|
||||||
|
Successfully changed project path to: E:/Unity Projects/GitLab/2023/H_SafeExperienceDrivingSystem/U3D_DrivingSystem
|
||||||
|
E:/Unity Projects/GitLab/2023/H_SafeExperienceDrivingSystem/U3D_DrivingSystem
|
||||||
|
Using Asset Import Pipeline V2.
|
||||||
|
Refreshing native plugins compatible for Editor in 181.72 ms, found 8 plugins.
|
||||||
|
Preloading 0 native plugins for Editor in 0.00 ms.
|
||||||
|
Initialize engine version: 2021.1.24f1 (6667702a1e7c)
|
||||||
|
[Subsystems] Discovering subsystems at path D:/2021.1.24f1/Editor/Data/Resources/UnitySubsystems
|
||||||
|
[Subsystems] Discovering subsystems at path E:/Unity Projects/GitLab/2023/H_SafeExperienceDrivingSystem/U3D_DrivingSystem/Assets
|
||||||
|
GfxDevice: creating device client; threaded=0; jobified=0
|
||||||
|
Direct3D:
|
||||||
|
Version: Direct3D 11.0 [level 11.1]
|
||||||
|
Renderer: NVIDIA GeForce GTX 1660 SUPER (ID=0x21c4)
|
||||||
|
Vendor: NVIDIA
|
||||||
|
VRAM: 5981 MB
|
||||||
|
Driver: 31.0.15.4617
|
||||||
|
Shader 'Custom/EVP Particles Alpha Blended Shadows': fallback shader 'Particles/Alpha Blended' not found
|
||||||
|
Initialize mono
|
||||||
|
Mono path[0] = 'D:/2021.1.24f1/Editor/Data/Managed'
|
||||||
|
Mono path[1] = 'D:/2021.1.24f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit'
|
||||||
|
Mono config path = 'D:/2021.1.24f1/Editor/Data/MonoBleedingEdge/etc'
|
||||||
|
Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,server=y,suspend=n,address=127.0.0.1:56524
|
||||||
|
Begin MonoManager ReloadAssembly
|
||||||
|
Registering precompiled unity dll's ...
|
||||||
|
Register platform support module: D:/2021.1.24f1/Editor/Data/PlaybackEngines/WindowsStandaloneSupport/UnityEditor.WindowsStandalone.Extensions.dll
|
||||||
|
Registered in 0.000932 seconds.
|
||||||
|
Native extension for WindowsStandalone target not found
|
||||||
|
Refreshing native plugins compatible for Editor in 187.18 ms, found 8 plugins.
|
||||||
|
Preloading 0 native plugins for Editor in 0.00 ms.
|
||||||
|
Mono: successfully reloaded assembly
|
||||||
|
- Completed reload, in 1.181 seconds
|
||||||
|
Domain Reload Profiling:
|
||||||
|
ReloadAssembly (1182ms)
|
||||||
|
BeginReloadAssembly (55ms)
|
||||||
|
ExecutionOrderSort (0ms)
|
||||||
|
DisableScriptedObjects (0ms)
|
||||||
|
BackupInstance (0ms)
|
||||||
|
ReleaseScriptingObjects (0ms)
|
||||||
|
CreateAndSetChildDomain (1ms)
|
||||||
|
EndReloadAssembly (567ms)
|
||||||
|
LoadAssemblies (54ms)
|
||||||
|
RebuildTransferFunctionScriptingTraits (0ms)
|
||||||
|
SetupTypeCache (156ms)
|
||||||
|
ReleaseScriptCaches (0ms)
|
||||||
|
RebuildScriptCaches (34ms)
|
||||||
|
SetupLoadedEditorAssemblies (329ms)
|
||||||
|
LogAssemblyErrors (0ms)
|
||||||
|
InitializePlatformSupportModulesInManaged (7ms)
|
||||||
|
SetLoadedEditorAssemblies (0ms)
|
||||||
|
RefreshPlugins (187ms)
|
||||||
|
BeforeProcessingInitializeOnLoad (2ms)
|
||||||
|
ProcessInitializeOnLoadAttributes (103ms)
|
||||||
|
ProcessInitializeOnLoadMethodAttributes (30ms)
|
||||||
|
AfterProcessingInitializeOnLoad (0ms)
|
||||||
|
EditorAssembliesLoaded (0ms)
|
||||||
|
ExecutionOrderSort2 (0ms)
|
||||||
|
AwakeInstancesAfterBackupRestoration (0ms)
|
||||||
|
Platform modules already initialized, skipping
|
||||||
|
Registering precompiled user dll's ...
|
||||||
|
Registered in 0.006343 seconds.
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,3 @@
|
||||||
Base path: 'D:/2021.1.24f1/Editor/Data', plugins path 'D:/2021.1.24f1/Editor/Data/PlaybackEngines'
|
Base path: 'D:/2021.1.24f1/Editor/Data', plugins path 'D:/2021.1.24f1/Editor/Data/PlaybackEngines'
|
||||||
Cmd: initializeCompiler
|
Cmd: initializeCompiler
|
||||||
|
|
||||||
Cmd: compileSnippet
|
|
||||||
insize=11820 file=Packages/com.unity.postprocessing/PostProcessing/Shaders/Builtins/Hidden/PostProcessing/Uber pass=<Unnamed Pass> cachingPP=1 ppOnly=0 stripLineD=0 buildPlatform=19 rsLen=0 pKW=UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR uKW=COLOR_GRADING_HDR_3D FINALPASS dKW=DISTORT CHROMATIC_ABERRATION CHROMATIC_ABERRATION_LOW BLOOM BLOOM_LOW VIGNETTE GRAIN COLOR_GRADING_LDR_2D COLOR_GRADING_HDR_2D STEREO_INSTANCING_ENABLED STEREO_DOUBLEWIDE_TARGET UNITY_NO_DXT5nm UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_NO_FULL_STANDARD_SHADER UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_VIRTUAL_TEXTURING UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_ASTC_NORMALMAP_ENCODING SHADER_API_GLES30 flags=0 lang=3 type=Fragment platform=d3d11 reqs=227 mask=6 start=277 ok=1 outsize=1838
|
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,13 @@ EditorUserSettings:
|
||||||
value: 22424703114646680e0b0227036c5b151b18563f22213229
|
value: 22424703114646680e0b0227036c5b151b18563f22213229
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedScenePath-2:
|
RecentlyUsedScenePath-2:
|
||||||
value: 22424703114646680e0b0227036c52151802563f22213229
|
value: 22424703114646680e0b0227036c52111f19276439262f2434
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedScenePath-3:
|
RecentlyUsedScenePath-3:
|
||||||
value: 22424703114646680e0b0227036c4c0417050c6439262f2434
|
value: 22424703114646680e0b0227036c52151802563f22213229
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedScenePath-4:
|
RecentlyUsedScenePath-4:
|
||||||
value: 22424703114646680e0b0227036c52111f19276439262f2434
|
value: 22424703114646680e0b0227036c4c0417050c6439262f2434
|
||||||
flags: 0
|
flags: 0
|
||||||
vcSharedLogLevel:
|
vcSharedLogLevel:
|
||||||
value: 0d5e400f0650
|
value: 0d5e400f0650
|
||||||
|
|
Loading…
Reference in New Issue