Last active
September 29, 2024 13:27
Revisions
-
comoc revised this gist
Mar 24, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ private void CalculateAckermannSteering(float steeringAngle, float tread, float turningRadius = wheelBase / Mathf.Sin(Mathf.Abs(radianSteeringAngle)); // 回転中心位置の計算 float turningCenterX = wheelBase / Mathf.Tan(radianSteeringAngle); turningCenter = new Vector3(turningCenterX, 0, -wheelBase); } } -
comoc revised this gist
Mar 24, 2023 . 1 changed file with 12 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ public class AckermannSteering : MonoBehaviour public float leftWheelAngle { get; private set; } // 左車輪の角度 public float rightWheelAngle { get; private set; } // 右車輪の角度 public float turningRadius { get; private set; } // 回転半径 public Vector3 turningCenter { get; private set; } // 回転中心位置 void Update() { @@ -18,32 +18,20 @@ void Update() private void CalculateAckermannSteering(float steeringAngle, float tread, float wheelBase) { // Ackermann steering geometryの計算 float radianSteeringAngle = Mathf.Deg2Rad * steeringAngle; float innerWheelAngle = Mathf.Rad2Deg * Mathf.Atan(wheelBase / (wheelBase / Mathf.Tan(radianSteeringAngle) - tread / 2)); float outerWheelAngle = Mathf.Rad2Deg * Mathf.Atan(wheelBase / (wheelBase / Mathf.Tan(radianSteeringAngle) + tread / 2)); // 左右の車輪の角度を設定 leftWheelAngle = outerWheelAngle; rightWheelAngle = innerWheelAngle; // 回転半径の計算 turningRadius = wheelBase / Mathf.Sin(Mathf.Abs(radianSteeringAngle)); // 回転中心位置の計算 float turningCenterZ = wheelBase / Mathf.Tan(radianSteeringAngle); turningCenter = new Vector3(turningCenterZ, 0, -wheelBase); } } -
comoc revised this gist
Mar 24, 2023 . 1 changed file with 3 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,14 +31,8 @@ private void CalculateAckermannSteering(float steeringAngle, float tread, float // Ackermann steering geometryの計算 float innerWheelAngle = Mathf.Rad2Deg * Mathf.Atan(wheelBase / (turningRadius + (tread / 2))); float outerWheelAngle = Mathf.Rad2Deg * Mathf.Atan(wheelBase / (turningRadius - (tread / 2))); if (!Mathf.Approximately(steeringAngle, 0)) { leftWheelAngle = innerWheelAngle; rightWheelAngle = outerWheelAngle; @@ -49,6 +43,7 @@ private void CalculateAckermannSteering(float steeringAngle, float tread, float rightWheelAngle = 0; turningRadius = Mathf.Infinity; turningCenter = Vector3.zero; } } } -
comoc revised this gist
Mar 24, 2023 . 1 changed file with 33 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,11 +3,13 @@ public class AckermannSteering : MonoBehaviour { [SerializeField] private float steeringAngle; // ステアリングの切れ角 [SerializeField] private float tread; // 左右の車輪間の距離 (トレッド) [SerializeField] private float wheelBase; // 前後の車輪間の距離 (ホイールベース) public float leftWheelAngle { get; private set; } // 左車輪の角度 public float rightWheelAngle { get; private set; } // 右車輪の角度 public float turningRadius { get; private set; } // 回転半径 public Vector3 turningCenter { get; private set; } // 回転中心 void Update() { @@ -16,14 +18,37 @@ void Update() private void CalculateAckermannSteering(float steeringAngle, float tread, float wheelBase) { float radianSteeringAngle = Mathf.Deg2Rad * steeringAngle; float tanSteeringAngle = Mathf.Tan(radianSteeringAngle); turningRadius = wheelBase / tanSteeringAngle; // 回転半径の計算 // 回転中心の計算 float turningCenterX = transform.position.x + (tread / 2) * Mathf.Cos(radianSteeringAngle); float turningCenterZ = transform.position.z - turningRadius * Mathf.Sin(radianSteeringAngle); turningCenter = new Vector3(turningCenterX, transform.position.y, turningCenterZ); // Ackermann steering geometryの計算 float innerWheelAngle = Mathf.Rad2Deg * Mathf.Atan(wheelBase / (turningRadius + (tread / 2))); float outerWheelAngle = Mathf.Rad2Deg * Mathf.Atan(wheelBase / (turningRadius - (tread / 2))); // 左右の車輪の角度を設定 if (steeringAngle > 0) { leftWheelAngle = outerWheelAngle; rightWheelAngle = innerWheelAngle; } else if (steeringAngle < 0) { leftWheelAngle = innerWheelAngle; rightWheelAngle = outerWheelAngle; } else { leftWheelAngle = 0; rightWheelAngle = 0; turningRadius = Mathf.Infinity; turningCenter = Vector3.zero; } } } -
comoc created this gist
Mar 24, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ using UnityEngine; public class AckermannSteering : MonoBehaviour { [SerializeField] private float steeringAngle; // ステアリングの切れ角 [SerializeField] private float tread; // 左右の車輪間の距離(トレッド) [SerializeField] private float wheelBase; // 前後の車輪間の距離(ホイールベース) public float leftWheelAngle { get; private set; } // 左車輪の角度 public float rightWheelAngle { get; private set; } // 右車輪の角度 void Update() { CalculateAckermannSteering(steeringAngle, tread, wheelBase); } private void CalculateAckermannSteering(float steeringAngle, float tread, float wheelBase) { // Ackermann steering geometryの計算 float radianSteeringAngle = Mathf.Deg2Rad * steeringAngle; float turnRadius = wheelBase / Mathf.Tan(radianSteeringAngle); float leftTurnRadius = turnRadius + (tread / 2); float rightTurnRadius = turnRadius - (tread / 2); // 左右の車輪の角度を設定 leftWheelAngle = Mathf.Rad2Deg * Mathf.Atan(wheelBase / leftTurnRadius); rightWheelAngle = Mathf.Rad2Deg * Mathf.Atan(wheelBase / rightTurnRadius); } }