Skip to content

Commit

Permalink
Fix null mowingBlade object in MicomCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunseok-yang committed Nov 22, 2024
1 parent 79a0ec3 commit 8b2a814
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ private void SetMowing()
mowingBlade.HeightMax = GetPluginParameters().GetValue<float>("mowing/blade/height/max", 0.1f);
mowingBlade.RevSpeedMax = GetPluginParameters().GetValue<UInt16>("mowing/blade/rev_speed/max", 1000);
mowingBlade.Height = 0;

if (_micomCommand != null)
{
_micomCommand.SetMowingBlade(mowingBlade);
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions Assets/Scripts/Devices/MicomCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ protected override void OnAwake()

protected override void OnStart()
{
_mowingBlade = GetComponentInChildren<MowingBlade>();
}

protected override void OnReset()
Expand All @@ -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))
Expand Down Expand Up @@ -189,15 +193,15 @@ 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)
{
_mowingBlade.Height = (float)value.DoubleValue;
// 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)
{
Expand Down

0 comments on commit 8b2a814

Please sign in to comment.