Initial tutorial project
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using CartActivator;
|
||||
|
||||
namespace DiffWheelM;
|
||||
|
||||
[UseManualController(manualController = typeof(Remote))]
|
||||
[UseLadderLogic(logic = typeof(MotorRoutine), scanInterval = 50)]
|
||||
public class CartDefinition : CartActivator.CartDefinition
|
||||
{
|
||||
[AsUpperIO(desc = "左轮下发速度", timeOutReset = true)]
|
||||
[Sandbox]
|
||||
public float SpeedLeft;
|
||||
|
||||
[AsUpperIO(desc = "右轮下发速度", timeOutReset = true)]
|
||||
[Sandbox]
|
||||
public float SpeedRight;
|
||||
|
||||
[AsLowerIO(desc = "左轮实际速度")]
|
||||
[Sandbox]
|
||||
public float ActualSpeedLeft;
|
||||
|
||||
[AsLowerIO(desc = "右轮实际速度")]
|
||||
[Sandbox]
|
||||
public float ActualSpeedRight;
|
||||
|
||||
[AsInitParam(desc = "手动最大轮速(m/s)")]
|
||||
public float MaxManualSpeed = 0.3f;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
Console.WriteLine("[DiffWheelM] Minimal Medulla cart initialized.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<OutputPath>..\build\Medulla\plugins\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="CartActivator">
|
||||
<HintPath>D:\MDCS\Dependencies\Medulla\RefCartActivator.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="MedullaCore">
|
||||
<HintPath>D:\MDCS\Dependencies\Medulla\RefMedullaCore.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Medulla">
|
||||
<HintPath>D:\MDCS\Dependencies\Medulla\RefMedulla2.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="FundamentalLib">
|
||||
<HintPath>D:\MDCS\Dependencies\deps\RefFundamentalLib.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,11 @@
|
||||
using CartActivator;
|
||||
|
||||
namespace DiffWheelM;
|
||||
|
||||
public class MotorRoutine : LadderLogic<CartDefinition>
|
||||
{
|
||||
public override void Operation(int iteration)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using CartActivator;
|
||||
|
||||
namespace DiffWheelM;
|
||||
|
||||
public class Remote : ManualController<CartDefinition>
|
||||
{
|
||||
[AsControlItem(name = "速度摇杆", keyboard = "Up,Down,Left,Right", joystick = "Axis0,Axis1")]
|
||||
public Stick Direction;
|
||||
|
||||
[AsControlItem(name = "速度比例", keyboard = "Q,W")]
|
||||
public Throttle SpeedRatio;
|
||||
|
||||
public override void Operation()
|
||||
{
|
||||
var maxSpeed = Math.Max(0, cart.MaxManualSpeed);
|
||||
var speedRatio = Math.Clamp(SpeedRatio.val, 0, 1);
|
||||
|
||||
var left = Direction.y - Direction.x;
|
||||
var right = Direction.y + Direction.x;
|
||||
var wheelScale = Math.Max(1, Math.Max(Math.Abs(left), Math.Abs(right)));
|
||||
|
||||
left = left / wheelScale * maxSpeed * speedRatio;
|
||||
right = right / wheelScale * maxSpeed * speedRatio;
|
||||
|
||||
cart.SpeedLeft = Math.Clamp(left, -maxSpeed, maxSpeed);
|
||||
cart.SpeedRight = Math.Clamp(right, -maxSpeed, maxSpeed);
|
||||
|
||||
statusText = $"L={cart.SpeedLeft:0.000}m/s, R={cart.SpeedRight:0.000}m/s";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user