Skip to content

Commit

Permalink
Updating indexing in ArticulationBody APIs for all joints (#22)
Browse files Browse the repository at this point in the history
* Adding variable names for indexes used in ArticulationnBody APIs

* Setting index value for xAxis
  • Loading branch information
vidurvij-Unity authored Dec 21, 2020
1 parent c72e9ca commit 89e7022
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Runtime/UrdfComponents/UrdfJoints/UrdfJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public enum JointTypes
Planar
}

public int xAxis = 0;

#if UNITY_2020_1_OR_NEWER
protected UnityEngine.ArticulationBody unityJoint;
protected Vector3 axisofMotion;
Expand Down
6 changes: 3 additions & 3 deletions Runtime/UrdfComponents/UrdfJoints/UrdfJointContinuous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override float GetPosition() // Check Units
{

#if UNITY_2020_1_OR_NEWER
return unityJoint.jointPosition[0];
return unityJoint.jointPosition[xAxis];
#else
return -((HingeJoint)unityJoint).angle * Mathf.Deg2Rad;
#endif
Expand All @@ -55,7 +55,7 @@ public override float GetPosition() // Check Units
public override float GetVelocity()
{
#if UNITY_2020_1_OR_NEWER
return unityJoint.velocity[0];
return unityJoint.velocity[xAxis];
#else
return -((HingeJoint)unityJoint).velocity * Mathf.Deg2Rad;
#endif
Expand All @@ -68,7 +68,7 @@ public override float GetVelocity()
public override float GetEffort()
{
#if UNITY_2020_1_OR_NEWER
return unityJoint.jointForce[0];
return unityJoint.jointForce[xAxis];
#else
return -((HingeJoint)unityJoint).motor.force;
#endif
Expand Down
6 changes: 3 additions & 3 deletions Runtime/UrdfComponents/UrdfJoints/UrdfJointPrismatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static UrdfJoint Create(GameObject linkObject)
public override float GetPosition()
{
#if UNITY_2020_1_OR_NEWER
return unityJoint.jointPosition[3];
return unityJoint.jointPosition[xAxis];
#else
return Vector3.Dot(unityJoint.transform.localPosition - unityJoint.connectedAnchor, unityJoint.axis);
#endif
Expand All @@ -73,7 +73,7 @@ public override float GetPosition()
public override float GetVelocity()
{
#if UNITY_2020_1_OR_NEWER
return unityJoint.velocity[3];
return unityJoint.velocity[xAxis];
#else
return float.NaN;
#endif
Expand All @@ -86,7 +86,7 @@ public override float GetVelocity()
public override float GetEffort()
{
#if UNITY_2020_1_OR_NEWER
return unityJoint.jointForce[3];
return unityJoint.jointForce[xAxis];
#else
return float.NaN;
#endif
Expand Down
6 changes: 3 additions & 3 deletions Runtime/UrdfComponents/UrdfJoints/UrdfJointRevolute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static UrdfJoint Create(GameObject linkObject)
public override float GetPosition()
{
#if UNITY_2020_1_OR_NEWER
return ((ArticulationBody)unityJoint).jointPosition[0] * Mathf.Deg2Rad;
return ((ArticulationBody)unityJoint).jointPosition[xAxis] * Mathf.Deg2Rad;
#else
return -((HingeJoint)unityJoint).angle * Mathf.Deg2Rad;
#endif
Expand All @@ -60,7 +60,7 @@ public override float GetPosition()
public override float GetVelocity()
{
#if UNITY_2020_1_OR_NEWER
return ((ArticulationBody)unityJoint).jointVelocity[0] * Mathf.Deg2Rad;
return ((ArticulationBody)unityJoint).jointVelocity[xAxis] * Mathf.Deg2Rad;
#else
return -((HingeJoint)unityJoint).velocity * Mathf.Deg2Rad;
#endif
Expand All @@ -73,7 +73,7 @@ public override float GetVelocity()
public override float GetEffort()
{
#if UNITY_2020_1_OR_NEWER
return unityJoint.jointForce[0];
return unityJoint.jointForce[xAxis];
#else
return -((HingeJoint)unityJoint).motor.force;
#endif
Expand Down

0 comments on commit 89e7022

Please sign in to comment.