Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified AWSIM vehicle's turning behavior #176

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 53 additions & 48 deletions Assets/AWSIM/Scenes/Main/AutowareSimulation.unity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this scene needs to be changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored the original value for m_IndirectSpecularColor.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 1536.168, g: 1903.334, b: 2519.2246, a: 1}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -520,6 +520,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
meshSource: 2
semanticCategoryDictionaryFile:
--- !u!114 &543989982
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4019,6 +4020,53 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 23c1ce4fb46143f46bc5cb5224c934f6, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Version: 7
m_ObsoleteRenderingPath: 0
m_ObsoleteFrameSettings:
overrides: 0
enableShadow: 0
enableContactShadows: 0
enableShadowMask: 0
enableSSR: 0
enableSSAO: 0
enableSubsurfaceScattering: 0
enableTransmission: 0
enableAtmosphericScattering: 0
enableVolumetrics: 0
enableReprojectionForVolumetrics: 0
enableLightLayers: 0
enableExposureControl: 1
diffuseGlobalDimmer: 0
specularGlobalDimmer: 0
shaderLitMode: 0
enableDepthPrepassWithDeferredRendering: 0
enableTransparentPrepass: 0
enableMotionVectors: 0
enableObjectMotionVectors: 0
enableDecals: 0
enableRoughRefraction: 0
enableTransparentPostpass: 0
enableDistortion: 0
enablePostprocess: 0
enableOpaqueObjects: 0
enableTransparentObjects: 0
enableRealtimePlanarReflection: 0
enableMSAA: 0
enableAsyncCompute: 0
runLightListAsync: 0
runSSRAsync: 0
runSSAOAsync: 0
runContactShadowsAsync: 0
runVolumeVoxelizationAsync: 0
lightLoopSettings:
overrides: 0
enableDeferredTileAndCluster: 0
enableComputeLightEvaluation: 0
enableComputeLightVariants: 0
enableComputeMaterialVariants: 0
enableFptlForForwardOpaque: 0
enableBigTilePrepass: 0
isFptlEnabled: 0
clearColorMode: 0
backgroundColorHDR: {r: 0.025, g: 0.07, b: 0.19, a: 0}
clearDepth: 1
Expand Down Expand Up @@ -4074,53 +4122,6 @@ MonoBehaviour:
data1: 0
data2: 0
defaultFrameSettings: 0
m_Version: 7
m_ObsoleteRenderingPath: 0
m_ObsoleteFrameSettings:
overrides: 0
enableShadow: 0
enableContactShadows: 0
enableShadowMask: 0
enableSSR: 0
enableSSAO: 0
enableSubsurfaceScattering: 0
enableTransmission: 0
enableAtmosphericScattering: 0
enableVolumetrics: 0
enableReprojectionForVolumetrics: 0
enableLightLayers: 0
enableExposureControl: 1
diffuseGlobalDimmer: 0
specularGlobalDimmer: 0
shaderLitMode: 0
enableDepthPrepassWithDeferredRendering: 0
enableTransparentPrepass: 0
enableMotionVectors: 0
enableObjectMotionVectors: 0
enableDecals: 0
enableRoughRefraction: 0
enableTransparentPostpass: 0
enableDistortion: 0
enablePostprocess: 0
enableOpaqueObjects: 0
enableTransparentObjects: 0
enableRealtimePlanarReflection: 0
enableMSAA: 0
enableAsyncCompute: 0
runLightListAsync: 0
runSSRAsync: 0
runSSAOAsync: 0
runContactShadowsAsync: 0
runVolumeVoxelizationAsync: 0
lightLoopSettings:
overrides: 0
enableDeferredTileAndCluster: 0
enableComputeLightEvaluation: 0
enableComputeLightVariants: 0
enableComputeMaterialVariants: 0
enableFptlForForwardOpaque: 0
enableBigTilePrepass: 0
isFptlEnabled: 0
--- !u!81 &2122627085
AudioListener:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4233,6 +4234,10 @@ PrefabInstance:
propertyPath: m_Name
value: Lexus RX450h 2015 Sample Sensor
objectReference: {fileID: 0}
- target: {fileID: 4981081891045692866, guid: 164645b2d105b6b4ab4e3d2e7c65dab2, type: 3}
propertyPath: sleepVelocityThreshold
value: 0.02
objectReference: {fileID: 0}
- target: {fileID: 5650763240072318842, guid: 164645b2d105b6b4ab4e3d2e7c65dab2, type: 3}
propertyPath: m_RootOrder
value: 0
Expand Down
33 changes: 29 additions & 4 deletions Assets/AWSIM/Scripts/Vehicles/Vehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ public class Axle

private float sleepTimer = 0.0f; ///Count the time until CanSleep is switched to true


// Vehicle dynamics parameters used for calculating of front wheel angles.
private float wheelBase = 2.787877f;
private float tread = 1.8199022f;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wheelbase and tread could be calculated automatically from the positions of the front and rear wheels, I believe. Therefore, it is preferable not to provide these variables.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to have wheelbase and tread calculated from the coordinates of each wheel.


// Cache components.
Wheel[] wheels;
Expand Down Expand Up @@ -335,7 +337,7 @@ bool IsEachWheelGrounded()
// Is less than sleepVelocityThreshold ?
bool IsCanSleepVelocity()
{
if (Mathf.Abs(Velocity.z) < sleepVelocityThreshold)
if (Mathf.Abs(LocalVelocity.z) < sleepVelocityThreshold)
return true;
else
return false;
Expand Down Expand Up @@ -424,8 +426,31 @@ void UpdateWheelsForce(float acceleration)
var perWheelAcceleration = acceleration / wheels.Length;

// Update the acceleration output by each wheel.
foreach (var wheel in wheels)
wheel.UpdateWheelForce(perWheelAcceleration);
var dif1 = Mathf.Sin(Mathf.Asin(1 / Mathf.Sqrt(Mathf.Pow((1 / Mathf.Tan(Mathf.Abs(SteerAngle) * Mathf.Deg2Rad) + tread / wheelBase), 2) + 1))) / Mathf.Sin(SteerAngle * Mathf.Deg2Rad);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to leave comments on the calculations and logic of dif1, dif2, dif3, etc. so that other developers can easily understand them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments of dif1, dif2, dif3.

var dif2 = (Mathf.Cos(Mathf.Asin(1 / Mathf.Sqrt(Mathf.Pow((1 / Mathf.Tan(Mathf.Abs(SteerAngle) * Mathf.Deg2Rad) + tread / wheelBase), 2) + 1))) + tread * Mathf.Sin(Mathf.Asin(1 / Mathf.Sqrt(Mathf.Pow((1 / Mathf.Tan(SteerAngle * Mathf.Deg2Rad) + tread / wheelBase), 2) + 1))) / wheelBase);
var dif3 = Mathf.Cos(Mathf.Asin(1 / Mathf.Sqrt(Mathf.Pow((1 / Mathf.Tan(Mathf.Abs(SteerAngle) * Mathf.Deg2Rad) + tread / wheelBase), 2) + 1)));

if (SteerAngle > 0.001)
{
frontAxle.LeftWheel.UpdateWheelForce(perWheelAcceleration);
frontAxle.RightWheel.UpdateWheelForce(perWheelAcceleration * dif1);
rearAxle.LeftWheel.UpdateWheelForce(perWheelAcceleration * dif2);
rearAxle.RightWheel.UpdateWheelForce(perWheelAcceleration * dif3);
}

else if (SteerAngle < -0.001)
{
frontAxle.LeftWheel.UpdateWheelForce(perWheelAcceleration * dif1);
frontAxle.RightWheel.UpdateWheelForce(perWheelAcceleration);
rearAxle.LeftWheel.UpdateWheelForce(perWheelAcceleration * dif3);
rearAxle.RightWheel.UpdateWheelForce(perWheelAcceleration * dif2);
}

else
{
foreach (var wheel in wheels)
wheel.UpdateWheelForce(perWheelAcceleration);
}
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion Assets/AWSIM/Scripts/Vehicles/Wheel.cs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should the Wheel class make changes? I think the Wheel class should just reflect the SteerAngle set from the Vehicle class, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted Wheel.cs to the original version and moved the relevant part to Vehicle.cs.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public class Wheel : MonoBehaviour
// Coefficient for cancelling the skidding while stopping of the tire.
float skiddingCancelRate;

// Vehicle dynamics parameters used for calculating of front wheel angles.
private float wheelBase = 2.787877f;
private float tread = 1.8199022f;

void Reset()
{
// Initializes the value of WheelCollider.
Expand Down Expand Up @@ -106,7 +110,16 @@ public void UpdateWheelSteerAngle(float steerAngle)
steerAngle = 0.00001f;

if (wheelCollider.steerAngle != steerAngle)
wheelCollider.steerAngle = steerAngle;
{
if (steerAngle > 40 && name == "FrontLeftWheel")
wheelCollider.steerAngle = Mathf.Asin(1 / Mathf.Sqrt(Mathf.Pow((1 / Mathf.Tan(Mathf.Abs(steerAngle) * Mathf.Deg2Rad) + tread / wheelBase), 2) + 1)) * Mathf.Rad2Deg;

else if (steerAngle < -40 && name == "FrontRightWheel")
wheelCollider.steerAngle = -Mathf.Asin(1 / Mathf.Sqrt(Mathf.Pow((1 / Mathf.Tan(Mathf.Abs(steerAngle) * Mathf.Deg2Rad) + tread / wheelBase), 2) + 1)) * Mathf.Rad2Deg;

else
wheelCollider.steerAngle = steerAngle;
}
}

/// <summary>
Expand Down