Skip to content

Commit

Permalink
Merge from 'develop' into 'main' for CLOiSim-4.2.1 (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunseok-yang authored Nov 27, 2023
2 parents c0c4cc8 + 8ea5aee commit 870f7e8
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ MonoBehaviour:
m_PrefilterDBufferMRT1: 1
m_PrefilterDBufferMRT2: 1
m_PrefilterDBufferMRT3: 1
m_PrefilterSoftShadowsQualityLow: 1
m_PrefilterSoftShadowsQualityMedium: 1
m_PrefilterSoftShadowsQualityHigh: 1
m_PrefilterSoftShadows: 0
m_PrefilterScreenCoord: 1
m_PrefilterNativeRenderPass: 1
m_ShaderVariantLogLevel: 0
Expand Down
19 changes: 16 additions & 3 deletions Assets/Scripts/Devices/JointState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,22 @@ void FixedUpdate()
var articulation = item.Item1;
var jointState = item.Item2;

jointState.Effort = articulation.GetEffort();
jointState.Position = articulation.GetJointPosition();
jointState.Velocity = articulation.GetJointVelocity();
var jointVelocity = articulation.GetJointVelocity();
var jointPosition = articulation.GetJointPosition();
var jointForce = articulation.GetForce();

jointState.Effort = (articulation.IsRevoluteType()) ?
DeviceHelper.Convert.CurveOrientation(jointForce) :
(articulation.IsPrismaticType() ?
DeviceHelper.Convert.PrismaticDirection(jointForce, articulation.GetAnchorRotation()) : jointForce);

jointState.Position = (articulation.IsRevoluteType()) ?
DeviceHelper.Convert.CurveOrientation(jointPosition) :
(articulation.IsPrismaticType() ?
DeviceHelper.Convert.PrismaticDirection(jointPosition, articulation.GetAnchorRotation()) : jointPosition);

jointState.Velocity = (articulation.IsRevoluteType()) ?
DeviceHelper.Convert.CurveOrientation(jointVelocity) : jointVelocity;
}
}
}
Expand Down
36 changes: 20 additions & 16 deletions Assets/Scripts/Devices/Modules/Articulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

using UnityEngine;
using System.Collections.Generic;

public class Articulation
{
Expand Down Expand Up @@ -41,6 +42,11 @@ public bool IsRevoluteType()
return (Type == ArticulationJointType.RevoluteJoint || Type == ArticulationJointType.SphericalJoint) ? true : false;
}

public bool IsPrismaticType()
{
return (Type == ArticulationJointType.RevoluteJoint || Type == ArticulationJointType.PrismaticJoint) ? true : false;
}

protected void SetJointVelocity(in float velocity, in int targetDegree = 0)
{
if (_jointBody != null)
Expand All @@ -59,38 +65,37 @@ private int GetValidIndex(in int index)
return (_jointBody == null) ? -1 : ((index >= _jointBody.dofCount) ? (_jointBody.dofCount - 1) : index);
}

public Vector3 GetAnchorRotation()
{
return (_jointBody == null) ? Vector3.zero : _jointBody.anchorRotation.eulerAngles;
}

/// <returns>in radian for angular and in meters for linear</param>
public float GetJointPosition(int index = 0)
{
if (IsRevoluteType())
{
index = GetValidIndex(index);
return (_jointBody == null || index == -1) ? 0 :
DeviceHelper.Convert.CurveOrientation(_jointBody.jointPosition[index]);
return (_jointBody == null || index == -1) ? 0 : _jointBody.jointPosition[index];
}
else
{
if (Type == ArticulationJointType.PrismaticJoint)
{
var anchorRotation = _jointBody.anchorRotation.eulerAngles;
var direction = (Mathf.Approximately(anchorRotation.x, 180) ||
Mathf.Approximately(anchorRotation.y, 180) ||
Mathf.Approximately(anchorRotation.z, 180)) ? -1f : 1f;

if (_jointBody.linearLockX == ArticulationDofLock.LockedMotion &&
_jointBody.linearLockY == ArticulationDofLock.LockedMotion)
{
return direction * _jointBody.transform.localPosition.z;
return _jointBody.transform.localPosition.z;
}
else if (_jointBody.linearLockY == ArticulationDofLock.LockedMotion &&
_jointBody.linearLockZ == ArticulationDofLock.LockedMotion)
{
return direction * _jointBody.transform.localPosition.x;
return _jointBody.transform.localPosition.x;
}
else if (_jointBody.linearLockX == ArticulationDofLock.LockedMotion &&
_jointBody.linearLockZ == ArticulationDofLock.LockedMotion)
{
return direction * _jointBody.transform.localPosition.y;
return _jointBody.transform.localPosition.y;
}
}
}
Expand All @@ -111,16 +116,15 @@ public float GetJointVelocity(int index = 0)
{
index = GetValidIndex(index);
var value = (_jointBody == null || index == -1) ? 0 : _jointBody.jointVelocity[index];
return (IsRevoluteType() ? DeviceHelper.Convert.CurveOrientation(value) : value);
return value;
}

/// <returns>torque for angular and force for linear</param>
public float GetEffort()
public float GetForce(int index = 0)
{
var drive = GetDrive();
var F = drive.stiffness * (GetJointPosition() - drive.target) - drive.damping * (GetJointVelocity() - drive.targetVelocity);
// Debug.Log(_jointBody.name + ": Calculated force = " + F);
return F;
index = GetValidIndex(index);
var value = (_jointBody == null || index == -1) ? 0 : _jointBody.driveForce[index];
return value;
}

/// <param name="target">angular velocity in degrees per second OR target position </param>
Expand Down
7 changes: 7 additions & 0 deletions Assets/Scripts/Devices/Modules/Base/DeviceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ public static float CurveOrientation(in float value)
{
return -value;
}

public static float PrismaticDirection(in float value, in Vector3 rotation)
{
return (Mathf.Approximately(rotation.x, 180) ||
Mathf.Approximately(rotation.y, 180) ||
Mathf.Approximately(rotation.z, 180)) ? -value : value;
}
}

public static Vector3[] SolveConvexHull2D(in Vector3[] points)
Expand Down
12 changes: 5 additions & 7 deletions Assets/Scripts/Devices/Modules/Motor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void Wait()

public class MotorMotionFeedback
{
public float compensatingVelocityIncrease = 0.20f;
public float compensatingVelocityDecrease = 0.60f;
public const float CompensatingVelocityIncrease = 0.10f;
public const float CompensatingVelocityDecrease = 0.50f;

private bool _isRotating = false;
private float _currentTwistAngularVelocity = 0;
Expand Down Expand Up @@ -84,12 +84,12 @@ public float Compensate()
{
if (IsTargetReached() == false)
{
_compensateValue += compensatingVelocityIncrease;
_compensateValue += CompensatingVelocityIncrease;
// Debug.Log("_test: it is low speed, " + _currentTwistAngularVelocity + " < " + _targetTwistAngularVelocity);
}
else
{
_compensateValue -= compensatingVelocityDecrease;
_compensateValue -= CompensatingVelocityDecrease;

if (_compensateValue < 0)
{
Expand Down Expand Up @@ -125,7 +125,7 @@ public Motor(in GameObject gameObject)

public void SetPID(in float pFactor, in float iFactor, in float dFactor)
{
_pidControl = new PID(pFactor, iFactor, dFactor, 50, -50, 300, -300);
_pidControl = new PID(pFactor, iFactor, dFactor, 10, -10, 100, -100);
}

/// <summary>Get Current Joint Velocity</summary>
Expand Down Expand Up @@ -173,8 +173,6 @@ public void Update(in float duration)
}

_currentMotorVelocity = GetMotorVelocity(duration);
// Debug.LogFormat("joint vel({0}) accel({1}) force({2}) friction({3}) pos({4})",
// Body.jointVelocity[0], Body.jointAcceleration[0], Body.jointForce[0], Body.jointFriction, Body.jointPosition[0]);

// do stop motion of motor when motor disabled
if (_enableMotor)
Expand Down
13 changes: 11 additions & 2 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "https://packages.unity.com"
},
"com.unity.burst": {
"version": "1.8.9",
"version": "1.8.10",
"depth": 1,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -58,7 +58,16 @@
"com.unity.mathematics": "1.2.1",
"com.unity.burst": "1.8.9",
"com.unity.render-pipelines.core": "14.0.9",
"com.unity.shadergraph": "14.0.9"
"com.unity.shadergraph": "14.0.9",
"com.unity.render-pipelines.universal-config": "14.0.9"
}
},
"com.unity.render-pipelines.universal-config": {
"version": "14.0.9",
"depth": 1,
"source": "builtin",
"dependencies": {
"com.unity.render-pipelines.core": "14.0.9"
}
},
"com.unity.robotics.vhacd": {
Expand Down
3 changes: 1 addition & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ PlayerSettings:
vulkanEnableLateAcquireNextImage: 0
vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0
bundleVersion: 4.2.0
bundleVersion: 4.2.1
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down Expand Up @@ -385,7 +385,6 @@ PlayerSettings:
switchScreenResolutionBehavior: 2
switchUseCPUProfiler: 0
switchEnableFileSystemTrace: 0
switchUseGOLDLinker: 0
switchLTOSetting: 0
switchApplicationID: 0x01004b9000490000
switchNSODependencies:
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2022.3.12f1
m_EditorVersionWithRevision: 2022.3.12f1 (4fe6e059c7ef)
m_EditorVersion: 2022.3.14f1
m_EditorVersionWithRevision: 2022.3.14f1 (eff2de9070d8)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ if `<name>` element of `<script>` element in `<material>` element contains "tree

### Tested environement (latest)

- Unity Editor Version: *'2022.3.10f1 (LTS)'*.
- Unity Editor Version: *'2022.3.14f1 (LTS)'*.

- Linux Machine
- OS: Ubuntu 22.04.3 LTS
Expand Down Expand Up @@ -200,7 +200,7 @@ or you can execute '***./run.sh***' script in release [binary](https://github.co
#### Debugging log

```shell
tail -f ~/.config/unity3d/lge-arlab/CLOiSim/Player.log
tail -f ~/.config/unity3d/LGE.CTO.AdvancedRoboticsLab/CLOiSim/Player.log
```

#### Control and external UI service
Expand Down

0 comments on commit 870f7e8

Please sign in to comment.