Skip to content

Commit a26894e

Browse files
author
Tinker Twins
committed
AutoDRIVE Simulator
1 parent 2cc4942 commit a26894e

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Assets/Scenes/AutoDRIVE.unity

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6238,7 +6238,8 @@ MonoBehaviour:
62386238
m_Name:
62396239
m_EditorClassIdentifier:
62406240
Wheel: {fileID: 693784637}
6241-
TicksPerRevolution: 16
6241+
PPR: 16
6242+
GearRatio: 120
62426243
--- !u!1 &157527723 stripped
62436244
GameObject:
62446245
m_CorrespondingSourceObject: {fileID: 100000, guid: c26a14e8dfb5c1b4783950e8573f3bd6,
@@ -52407,7 +52408,8 @@ MonoBehaviour:
5240752408
m_Name:
5240852409
m_EditorClassIdentifier:
5240952410
Wheel: {fileID: 281874620}
52410-
TicksPerRevolution: 16
52411+
PPR: 16
52412+
GearRatio: 120
5241152413
--- !u!1001 &1474921031
5241252414
PrefabInstance:
5241352415
m_ObjectHideFlags: 0

Assets/Scripts/WheelEncoder.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ public class WheelEncoder : MonoBehaviour
66
{
77
/*
88
This script attaches an incrementel encoder to a 'WheelCollider' component.
9-
The property `TicksPerRevolution` sets the encoder resolution and is used to
10-
measure the encoder ticks and the angle turned by the wheel.
9+
The property `PPR` sets the encoder resolution while `GearRatio` sets the
10+
multiplier due to the motor gearbox. The two parameters are used to compute
11+
the encoder ticks and the angle turned by the wheel.
1112
*/
1213

1314
public WheelCollider Wheel;
14-
public int TicksPerRevolution;
15+
public int PPR;
16+
public int GearRatio;
1517

1618
private float TotalRevolutions = 0f;
1719
private int TotalTicks = 0;
@@ -31,8 +33,8 @@ void FixedUpdate()
3133
{
3234
float RPS = Wheel.rpm/60f; // Read the current wheel RPM and convert to RPS
3335
TotalRevolutions += RPS * Time.deltaTime; // Scale by time since the last frame and add to the total revolutions
34-
TotalTicks = (int)(TotalRevolutions*TicksPerRevolution); // Compute ticks of the encoder
35-
TotalAngle = ((TotalTicks*2*Mathf.PI)/TicksPerRevolution); // Angle turned by the wheel (rad)
36+
TotalTicks = (int)(TotalRevolutions*PPR*GearRatio); // Compute ticks of the encoder
37+
TotalAngle = ((TotalTicks*2*Mathf.PI)/(PPR*GearRatio)); // Angle turned by the wheel (rad)
3638
//Debug.Log("Encoder Ticks: "+TotalTicks);
3739
//Debug.Log("Wheel Angle: "+TotalAngle);
3840
}

ProjectSettings/ProjectSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ PlayerSettings:
123123
16:10: 0
124124
16:9: 1
125125
Others: 0
126-
bundleVersion: 0.1.0
126+
bundleVersion: 0.1.1
127127
preloadedAssets: []
128128
metroInputSource: 0
129129
wsaTransparentSwapchain: 0

0 commit comments

Comments
 (0)