Skip to content

Commit

Permalink
Modify MowingPlugin
Browse files Browse the repository at this point in the history
- Support MowingBlade

Modify MicomCommand
- interface for mowing blade control

Add new module for MowingPlugin
- MowingBlade
   on/off, adjustable blade height

Modify TextureUtil
- Add Filling texture options

Modify GeometryGrass shader
- apply ratio by visibility for  blade max height
  • Loading branch information
hyunseok-yang committed Sep 11, 2024
1 parent 7a6bd55 commit 0b82ab1
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 131 deletions.
4 changes: 2 additions & 2 deletions Assets/Resources/Shader/GeometryGrass.shader
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ Shader "Custom/GeometryGrass"
#endif

float width = lerp(_BladeWidthMin, _BladeWidthMax, rand(pos.xzy) * falloff);
float height = lerp(_BladeHeightMin, _BladeHeightMax, rand(pos.zyx) * falloff);
float forward = rand(pos.yyz) * _BladeBendDistance;
float height = lerp(_BladeHeightMin, _BladeHeightMax * grassVisibility, rand(pos.zyx) * falloff);
float forward = rand(pos.yyz) * _BladeBendDistance * grassVisibility;

#ifdef DRY_GRASS_ON
float dryRate = tex2Dlod(_DryGrassMap, float4(-input[0].uv, 0, 0)).r;
Expand Down
26 changes: 26 additions & 0 deletions Assets/Scripts/CLOiSimPlugins/MicomPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System;
using Any = cloisim.msgs.Any;
using UnityEngine;

Expand Down Expand Up @@ -88,6 +89,11 @@ private void SetupMicom()
SetWheel();
}

if (GetPluginParameters().IsValidNode("mowing"))
{
SetMowing();
}

if (GetPluginParameters().IsValidNode("battery"))
{
SetBattery();
Expand Down Expand Up @@ -170,6 +176,26 @@ private void SetWheelPID()
_motorControl.SetPID(P, I, D, iMin, iMax, outputMin, outputMax);
}

private void SetMowing()
{
var targetBladeName = GetPluginParameters().GetAttributeInPath<string>("mowing/blade", "target");
if (!string.IsNullOrEmpty(targetBladeName))
{
var linkHelpers = GetComponentsInChildren<SDF.Helper.Link>();
var targetBlade = linkHelpers.FirstOrDefault(x => x.name == targetBladeName);

if (targetBlade != null)
{
var mowingBlade = targetBlade.gameObject.AddComponent<MowingBlade>();

mowingBlade.HeightMin = GetPluginParameters().GetValue<float>("mowing/blade/height/min", 0f);
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;
}
}
}

private void SetBattery()
{
if (GetPluginParameters().GetValues<string>("battery/voltage", out var batteryList))
Expand Down
Loading

0 comments on commit 0b82ab1

Please sign in to comment.