From 56b30d9d15bcb5bba24230229c2edc057b35d613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Hodossy?= Date: Thu, 11 Jan 2024 16:09:06 +0000 Subject: [PATCH 1/3] Check the autolimits attribute before assigning default values for joint limitedness --- unity/Runtime/Components/Joints/MjJointSettings.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/unity/Runtime/Components/Joints/MjJointSettings.cs b/unity/Runtime/Components/Joints/MjJointSettings.cs index f2f3d72e..1b9e87e9 100644 --- a/unity/Runtime/Components/Joints/MjJointSettings.cs +++ b/unity/Runtime/Components/Joints/MjJointSettings.cs @@ -164,7 +164,14 @@ namespace Mujoco { RefFriction.FromMjcf(mjcf, "solreffriction"); ImpFriction.FromMjcf(mjcf, "solimpfriction"); FrictionLoss = mjcf.GetFloatAttribute("frictionloss", 0.0f); - Limited = mjcf.GetBoolAttribute("limited", false); + + bool defaultLimited = false; + if (mjcf.OwnerDocument.GetElementsByTagName("compiler")[0] is not XmlElement + compilerElement || !compilerElement.GetBoolAttribute("autolimits").Equals("false")) { + defaultLimited = mjcf.HasAttribute("range"); + } + + Limited = mjcf.GetBoolAttribute("limited", defaultLimited); Margin = mjcf.GetFloatAttribute("margin", defaultValue: 0.0f); } } From 3a00450d00579034e5bfd8b4d042ee3ea07e6966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Hodossy?= Date: Thu, 11 Jan 2024 16:20:13 +0000 Subject: [PATCH 2/3] Rephrase condition for default limited definition so it's more intuitive --- unity/Runtime/Components/Joints/MjJointSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unity/Runtime/Components/Joints/MjJointSettings.cs b/unity/Runtime/Components/Joints/MjJointSettings.cs index 1b9e87e9..c45a6c1c 100644 --- a/unity/Runtime/Components/Joints/MjJointSettings.cs +++ b/unity/Runtime/Components/Joints/MjJointSettings.cs @@ -167,7 +167,7 @@ namespace Mujoco { bool defaultLimited = false; if (mjcf.OwnerDocument.GetElementsByTagName("compiler")[0] is not XmlElement - compilerElement || !compilerElement.GetBoolAttribute("autolimits").Equals("false")) { + compilerElement || compilerElement.GetBoolAttribute("autolimits", true)) { defaultLimited = mjcf.HasAttribute("range"); } From 66a0cd3b0b5249ceb0b0d89aa1994ff39cd11e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Hodossy?= Date: Thu, 11 Jan 2024 16:29:08 +0000 Subject: [PATCH 3/3] Perform autolimit check on actuators --- unity/Runtime/Components/MjActuator.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/unity/Runtime/Components/MjActuator.cs b/unity/Runtime/Components/MjActuator.cs index 4bdffe87..a72ba30c 100644 --- a/unity/Runtime/Components/MjActuator.cs +++ b/unity/Runtime/Components/MjActuator.cs @@ -77,12 +77,17 @@ public class MjActuator : MjComponent { } public void FromMjcf(XmlElement mjcf) { - CtrlLimited = mjcf.GetBoolAttribute("ctrllimited", defaultValue: false); - ForceLimited = mjcf.GetBoolAttribute("forcelimited", defaultValue: false); CtrlRange = mjcf.GetVector2Attribute("ctrlrange", defaultValue: Vector2.zero); ForceRange = mjcf.GetVector2Attribute("forcerange", defaultValue: Vector2.zero); LengthRange = mjcf.GetVector2Attribute("lengthrange", defaultValue: Vector2.zero); Gear = mjcf.GetFloatArrayAttribute("gear", defaultValue: new float[] { 1.0f }).ToList(); + + bool autolimits = mjcf.OwnerDocument.GetElementsByTagName("compiler")[0] is not XmlElement + compilerElement || compilerElement.GetBoolAttribute("autolimits", true); + CtrlLimited = mjcf.GetBoolAttribute("ctrllimited", + defaultValue: autolimits ? CtrlRange != Vector2.zero : false); + ForceLimited = mjcf.GetBoolAttribute("forcelimited", + defaultValue: autolimits ? ForceRange != Vector2.zero : false); } }