فهرست منبع

Prepared break sensor implementation on USB Serial

manuel.lehe 3 سال پیش
والد
کامیت
2629252343

+ 4 - 0
Assets/AdvancedAnt/Scripts/USBDevice.cs

@@ -0,0 +1,4 @@
+public class USBDevice  {
+    public string name;
+    public int deviceNumber;
+}

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1083 - 0
Assets/Scenes/TrafficScenes/TrafficBikeScene.unity


+ 127 - 2
Assets/Scenes/TrafficScenes/TrafficLightsTestScene.unity

@@ -33720,6 +33720,36 @@ PrefabInstance:
       propertyPath: m_Materials.Array.data[0]
       value: 
       objectReference: {fileID: 2100000, guid: 62e25ef75a2216f418d06453c9ad15cb, type: 2}
+    - target: {fileID: 67752964417318521, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_Mass
+      value: 100
+      objectReference: {fileID: 0}
+    - target: {fileID: 67752964417318521, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_WheelDampingRate
+      value: 1
+      objectReference: {fileID: 0}
+    - target: {fileID: 67752964417318521, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionDistance
+      value: 0.08
+      objectReference: {fileID: 0}
+    - target: {fileID: 67752964417318521, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.damper
+      value: 9000
+      objectReference: {fileID: 0}
+    - target: {fileID: 67752964417318521, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.spring
+      value: 90000
+      objectReference: {fileID: 0}
+    - target: {fileID: 67752964417318521, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.targetPosition
+      value: 1
+      objectReference: {fileID: 0}
     - target: {fileID: 1266725097120312596, guid: 1c801847369424623a4780d1ecb98545,
         type: 3}
       propertyPath: raySpacing
@@ -33780,6 +33810,66 @@ PrefabInstance:
       propertyPath: steeringSpeedMax
       value: 15
       objectReference: {fileID: 0}
+    - target: {fileID: 5302598447780432506, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_Mass
+      value: 100
+      objectReference: {fileID: 0}
+    - target: {fileID: 5302598447780432506, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_WheelDampingRate
+      value: 1
+      objectReference: {fileID: 0}
+    - target: {fileID: 5302598447780432506, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionDistance
+      value: 0.08
+      objectReference: {fileID: 0}
+    - target: {fileID: 5302598447780432506, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.damper
+      value: 9000
+      objectReference: {fileID: 0}
+    - target: {fileID: 5302598447780432506, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.spring
+      value: 90000
+      objectReference: {fileID: 0}
+    - target: {fileID: 5302598447780432506, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.targetPosition
+      value: 1
+      objectReference: {fileID: 0}
+    - target: {fileID: 6048829483124119303, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_Mass
+      value: 100
+      objectReference: {fileID: 0}
+    - target: {fileID: 6048829483124119303, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_WheelDampingRate
+      value: 1
+      objectReference: {fileID: 0}
+    - target: {fileID: 6048829483124119303, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionDistance
+      value: 0.08
+      objectReference: {fileID: 0}
+    - target: {fileID: 6048829483124119303, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.damper
+      value: 9000
+      objectReference: {fileID: 0}
+    - target: {fileID: 6048829483124119303, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.spring
+      value: 90000
+      objectReference: {fileID: 0}
+    - target: {fileID: 6048829483124119303, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.targetPosition
+      value: 1
+      objectReference: {fileID: 0}
     - target: {fileID: 8485239902145736706, guid: 1c801847369424623a4780d1ecb98545,
         type: 3}
       propertyPath: m_Mass
@@ -33790,6 +33880,36 @@ PrefabInstance:
       propertyPath: m_Interpolate
       value: 1
       objectReference: {fileID: 0}
+    - target: {fileID: 8925702086366402084, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_Mass
+      value: 100
+      objectReference: {fileID: 0}
+    - target: {fileID: 8925702086366402084, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_WheelDampingRate
+      value: 1
+      objectReference: {fileID: 0}
+    - target: {fileID: 8925702086366402084, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionDistance
+      value: 0.08
+      objectReference: {fileID: 0}
+    - target: {fileID: 8925702086366402084, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.damper
+      value: 9000
+      objectReference: {fileID: 0}
+    - target: {fileID: 8925702086366402084, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.spring
+      value: 90000
+      objectReference: {fileID: 0}
+    - target: {fileID: 8925702086366402084, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: m_SuspensionSpring.targetPosition
+      value: 1
+      objectReference: {fileID: 0}
     m_RemovedComponents: []
   m_SourcePrefab: {fileID: 100100000, guid: 1c801847369424623a4780d1ecb98545, type: 3}
 --- !u!4 &276628849 stripped
@@ -113858,7 +113978,7 @@ Transform:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 967480043}
-  m_LocalRotation: {x: 0.3268319, y: 0.35165724, z: -0.13254069, w: 0.86715114}
+  m_LocalRotation: {x: 0.32683188, y: 0.3516572, z: -0.13254067, w: 0.86715114}
   m_LocalPosition: {x: 379.03, y: 6.94, z: -164.24}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children:
@@ -139815,7 +139935,7 @@ Transform:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1210226322}
-  m_LocalRotation: {x: 0.3268319, y: 0.35165724, z: -0.13254069, w: 0.86715114}
+  m_LocalRotation: {x: 0.32683188, y: 0.3516572, z: -0.13254067, w: 0.86715114}
   m_LocalPosition: {x: 379.03, y: 6.94, z: -164.24}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children: []
@@ -205795,6 +205915,11 @@ PrefabInstance:
       propertyPath: trafficSystem
       value: 
       objectReference: {fileID: 553908397}
+    - target: {fileID: 4964375416919538269, guid: 1c801847369424623a4780d1ecb98545,
+        type: 3}
+      propertyPath: downForce
+      value: 700
+      objectReference: {fileID: 0}
     m_RemovedComponents: []
   m_SourcePrefab: {fileID: 100100000, guid: 1c801847369424623a4780d1ecb98545, type: 3}
 --- !u!1001 &1765835619

+ 10 - 11
Assets/Scripts/Controller/Bicycle/RbBicycleController.cs

@@ -41,21 +41,20 @@ namespace Controller.Bicycle
 
         private Vector3 CalculateTargetVelocity()
         {
-            if (adjustSpeedToSlope)
-            {
-                previousSoeedAdjusted = currentSpeedAdjusted;
+            if (adjustSpeedToSlope){
+                previousSpeedAdjusted = currentSpeedAdjusted;
                 var boost = speedBooster.Boost;
                 float nextSpeedAdjusted;
-                if (boost > 1 && CurrentSpeedSensed < 5.55f) //5.55 m/s = 20 km/h
+                if (boost > 1 && CurrentSpeedSensed < 5.55f){ //5.55 m/s = 20 km/h
                     nextSpeedAdjusted = 5.55f * boost;
-                else
-                    nextSpeedAdjusted = CurrentSpeedSensed * speedBooster.Boost;
-
+                }else{
+                    nextSpeedAdjusted = CurrentSpeedSensed * speedBooster.Boost; // boost new speed 
+                }
+                //control that the difference isn´t to high per frame
                 currentSpeedAdjusted = Mathf.Max(Mathf.Max(0,
-                    previousSoeedAdjusted - Time.deltaTime * MAX_DIF_SPEED_ADJUSTED_PER_SECOND), nextSpeedAdjusted);
+                    previousSpeedAdjusted - Time.deltaTime * MAX_DIF_SPEED_ADJUSTED_PER_SECOND), nextSpeedAdjusted); 
             }
-            else
-            {
+            else{
                 currentSpeedAdjusted = CurrentSpeedSensed;
             }
 
@@ -99,7 +98,7 @@ namespace Controller.Bicycle
         private float currentSteerAngle;
         private float currentLeaningAngle;
         private float currentSpeedAdjusted;
-        private float previousSoeedAdjusted;
+        private float previousSpeedAdjusted;
         private const float MAX_DIF_SPEED_ADJUSTED_PER_SECOND = 10f;
         private BikeSpeedBooster speedBooster;
 

+ 12 - 12
Assets/Scripts/Controller/KeyboardBikeController.cs

@@ -17,7 +17,7 @@ namespace Controller
         public float steeringAngleIncreasePerSecond = 2.5f;
         private IBicycleController bicycleController;
 
-        private float sensedSpeed;
+        private float sensedSpeed = 0f;
 
         private void Start()
         {
@@ -28,10 +28,10 @@ namespace Controller
         {
             if (accelerate)
             {
-                if (Input.GetKey(KeyCode.T))
+                if (Input.GetKey(KeyCode.W))
                 {
-                    //sensedSpeed += speedIncreasePerSecond * Time.deltaTime;
-                    bicycleController.CurrentSpeed = 25 / 3.6f;
+                    sensedSpeed += speedIncreasePerSecond * Time.deltaTime;
+                    //bicycleController.CurrentSpeed = 25 / 3.6f;
                 }
                 else if (bicycleController.CurrentSpeed > 0)
                 {
@@ -39,23 +39,23 @@ namespace Controller
                     //    sensedSpeed - speedDecreasePerSecond * Time.deltaTime);
                 }
 
-                if (Input.GetKey(KeyCode.G))
-                    // sensedSpeed = Mathf.Max(0,
-                    //    sensedSpeed - brakeIncreasePerSecond * Time.deltaTime);
-                    bicycleController.CurrentSpeed = 0f;
+                if (Input.GetKey(KeyCode.S))
+                     sensedSpeed = Mathf.Max(0,
+                        sensedSpeed - brakeIncreasePerSecond * Time.deltaTime);
+                    //bicycleController.CurrentSpeed = 0f;
 
-                //bicycleController.CurrentSpeed = sensedSpeed;
+                bicycleController.CurrentSpeed = sensedSpeed;
             }
 
             if (steer)
             {
-                if (Input.GetKey(KeyCode.F))
+                if (Input.GetKey(KeyCode.A))
                     bicycleController.CurrentSteerAngle -= steeringAngleIncreasePerSecond * Time.deltaTime;
 
-                if (Input.GetKey(KeyCode.H))
+                if (Input.GetKey(KeyCode.D))
                     bicycleController.CurrentSteerAngle += steeringAngleIncreasePerSecond * Time.deltaTime;
 
-                if (Input.GetKeyUp(KeyCode.F) || Input.GetKeyUp(KeyCode.H)) bicycleController.CurrentSteerAngle = 0f;
+                if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D)) bicycleController.CurrentSteerAngle = 0f;
             }
 
             if (lean)

+ 15 - 0
Assets/Scripts/Controller/SensorBikeController.cs

@@ -3,6 +3,7 @@ using Controller.Bicycle;
 using Controller.Lean;
 using Sensors;
 using Sensors.ANT;
+using Sensors.USB;
 using Tracking;
 using UnityEngine;
 
@@ -26,10 +27,12 @@ namespace Controller
         public bool steer = true;
         public bool accelerate = true;
         public bool lean = true;
+        public bool breaking = true;
 
         private IBicycleController bicycleController;
         private bool isFrontWheelTrackerNotNull;
         private BikeSensorData sensorData;
+        private float brakeIncreasePerSecond = 2.5f;
 
         private void Start()
         {
@@ -41,9 +44,14 @@ namespace Controller
         private void Update()
         {
             var speedData = sensorData.SpeedData;
+            var breakData = sensorData.BreakData;
 
             if (speedData != null && accelerate) SetSpeed(speedData.Value);
 
+            if(breakData != null && breaking){
+                SetBreaking(breakData.Value);
+            }
+
             if (isFrontWheelTrackerNotNull && steer) SetSteer();
 
             if (lean) SetLeaningAngle();
@@ -64,5 +72,12 @@ namespace Controller
         {
             bicycleController.CurrentSpeed = speedData.Speed;
         }
+        private void SetBreaking(BreakSensorData breakData)
+        {
+            if(breakData.isActive){
+                Debug.Log("Currently breaking");
+                bicycleController.CurrentSpeed = Mathf.Max(0, bicycleController.CurrentSpeed - brakeIncreasePerSecond * Time.deltaTime);
+            }
+        }
     }
 }

+ 5 - 0
Assets/Scripts/Sensors/BikeSensorData.cs

@@ -7,6 +7,7 @@ using JetBrains.Annotations;
 using Sensors.ANT;
 using Sensors.Bluetooth;
 using Sensors.Polar;
+using Sensors.Serial;
 using UniRx;
 using UnityEngine;
 
@@ -20,12 +21,16 @@ namespace Sensors
 
         [CanBeNull] private PowerMeterReceiver powerMeterReceiver;
         [CanBeNull] private SpeedSensorReceiver speedSensorReceiver;
+        [CanBeNull] private BreakSensorReveiver breakSensorReceiver;
 
         private BikeSensorData()
         {
             PolarReceiverAvailable = polarReceiverAvailable.ToTask();
         }
 
+        public BreakSensorData? BreakData => 
+            breakSensorReceiver?.Connected ?? false ? breakSensorReceiver?.SensorData : null;
+
         public SpeedSensorData? SpeedData =>
             speedSensorReceiver?.Connected ?? false ? speedSensorReceiver?.SensorData : null;
 

+ 22 - 0
Assets/Scripts/Sensors/USB/BreakReceiver.cs

@@ -0,0 +1,22 @@
+namespace Sensors.USB
+{
+    public struct BreakSensorData
+    {
+        public bool isActive;
+        public float timeActive;
+    }
+    public class BreakSensorReveiver: AwaitDevice
+    {
+        private BreakSensorData sensorData;
+        public BreakSensorData SensorData => sensorData;
+
+        public override void Connect(USBDevice device)
+        {
+            Debug.Log("Connect not implemented");
+        }
+    }
+    public class BreakReceiver: AwaitDevice
+    {
+
+    }
+}

+ 15 - 0
Assets/Scripts/Sensors/USB/USBDevices.cs

@@ -0,0 +1,15 @@
+namespace Sensors.USB
+{
+    public abstract class AwaitSDevice
+    {
+        public abstract int DeviceId { get; }
+
+        public abstract bool Connected { get; }
+
+        public abstract void Connect(USBDevice device);
+    }
+    public class USBDevices
+    {
+
+    }
+}

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است