Repository URL to install this package:
Version:
1.3.1 ▾
|
using Fluctio.FluctioSim.Common.Configuration;
using Unity.MLAgents.Actuators;
using UnityEngine;
namespace Fluctio.FluctioSim.Core.Components.MachineLearning.Actuating
{
[AddComponentMenu(Config.PrefixedName+"/Machine Learning/Actuating/Differential Drive", Config.ComponentMenuOrder + 510)]
public class DifferentialDrive : Control
{
[SerializeField] public Control forward;
[SerializeField] public Control turn;
[SerializeField] public WheelSide wheelSide = WheelSide.Left;
public override ActionBuffers GetActions()
{
var invertedFactor = wheelSide == WheelSide.Left ? -1 : 1;
var turnFactor = wheelSide == WheelSide.Left ? 1 : -1;
var forwardAction = forward.GetActions().GetOneContinuous();
var turnAction = turn.GetActions().GetOneContinuous();
var resultAction = invertedFactor * (forwardAction + turnFactor * turnAction) / 2;
return ActionBuffersExtensions.FromOneContinuous(resultAction);
}
}
public enum WheelSide { Left, Right }
}