From 8b2a8149f409f774229c42287af0c55dd286ff3a Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Fri, 22 Nov 2024 18:55:11 +0900 Subject: [PATCH] Fix null mowingBlade object in MicomCommand --- Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs | 5 +++++ Assets/Scripts/Devices/MicomCommand.cs | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs b/Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs index 0510c5d9..bed2177d 100644 --- a/Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs +++ b/Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs @@ -332,6 +332,11 @@ private void SetMowing() mowingBlade.HeightMax = GetPluginParameters().GetValue("mowing/blade/height/max", 0.1f); mowingBlade.RevSpeedMax = GetPluginParameters().GetValue("mowing/blade/rev_speed/max", 1000); mowingBlade.Height = 0; + + if (_micomCommand != null) + { + _micomCommand.SetMowingBlade(mowingBlade); + } } } } diff --git a/Assets/Scripts/Devices/MicomCommand.cs b/Assets/Scripts/Devices/MicomCommand.cs index 2f6a1fc6..6b44bc92 100644 --- a/Assets/Scripts/Devices/MicomCommand.cs +++ b/Assets/Scripts/Devices/MicomCommand.cs @@ -37,7 +37,6 @@ protected override void OnAwake() protected override void OnStart() { - _mowingBlade = GetComponentInChildren(); } protected override void OnReset() @@ -50,6 +49,11 @@ public void SetMotorControl(in dynamic motorControl) this._motorControl = motorControl; } + public void SetMowingBlade(in dynamic mowingBlade) + { + this._mowingBlade = mowingBlade; + } + protected override void ProcessDevice() { if (PopDeviceMessage(out var receivedMessage)) @@ -189,7 +193,7 @@ private void ControlJoystick(in cloisim.msgs.Joystick message) private void ControlMowing(in string target, in cloisim.msgs.Any value) { - if (string.Compare(target, "mowing_blade_height") == 0) + if (target.Equals("mowing_blade_height")) { if (_mowingBlade != null && value.Type == messages.Any.ValueType.Double) { @@ -197,7 +201,7 @@ private void ControlMowing(in string target, in cloisim.msgs.Any value) // Debug.Log($"mowing_blade_height {value} -> {_mowingBlade.Height}"); } } - else if (string.Compare(target, "mowing_blade_rev_speed") == 0) + else if (target.Equals("mowing_blade_rev_speed")) { if (_mowingBlade != null && value.Type == messages.Any.ValueType.Int32) {