private CrispInput GenerateInputFromSensors() { CrispInput input; float speed = sensor.Speed; float normalisedSpeed = NormaliseSpeed(speed); float?forwardDistance = sensor.ForwardRayHitDistance; float normalisedForwardDistance = NormaliseDistance(forwardDistance, neutralForwardDistance, largeForwardDistance); float?rightDistance = sensor.RightRayHitDistance; float normalisedRighDistance = NormaliseDistance(rightDistance, neutralRightDistance, largeRightDistance); float?leftDistance = sensor.LeftRayHitDistance; float normalisedLeftDistance = NormaliseDistance(leftDistance, neutralLeftDistance, largeLeftDistance); Vector3?forwardSucfaceNormal = sensor.ForwardRayCollisionNormal; float normalisedForwardSurfaceNormal; normalisedForwardSurfaceNormal = NormaliseSurfaceAngle(forwardSucfaceNormal, forwardMinAngle, forwardMaxAngle); input = new CrispInput(); input[CrispInput.Inputs.Speed] = normalisedSpeed; input[CrispInput.Inputs.ForwardDistance] = normalisedForwardDistance; input[CrispInput.Inputs.RightDistance] = normalisedRighDistance; input[CrispInput.Inputs.LeftDistance] = normalisedLeftDistance; input[CrispInput.Inputs.ForwardSurfaceNormal] = normalisedForwardSurfaceNormal; return(input); }
private void RunFuzzy() { float[] minValues = new float[CrispInput.NumberOfVariables] { Input1Min, Input2Min, -1 }; float[] neutralValues = new float[CrispInput.NumberOfVariables] { 0, 0, 0 }; float[] maxValues = new float[CrispInput.NumberOfVariables] { Input1Max, Input2Max, 1 }; CrispInput crispInput = fuzzySystem.BuildInputNormalisedUneven(new float[] { crispInput1, crispInput2, crispInput3 }, minValues, neutralValues, maxValues); Debug.Log($"In log {crispInput1} -> {crispInput[CrispInput.Inputs.Input1]}"); CrispOutput normalisedCrispOutput = fuzzySystem.FuzzyCompute(crispInput); CrispOutput unNormalisedOutput = fuzzySystem.UnNormaliseOutputUneven(normalisedCrispOutput, minValues, neutralValues, maxValues); Debug.Log($"Out log {normalisedCrispOutput[CrispOutput.Outputs.Output1]} -> {unNormalisedOutput[CrispOutput.Outputs.Output1]}"); }
private void DebugOutLots(CrispInput inputVals, CrispOutput outputVals) { Debug.Log("=====Case====="); foreach (var input in CrispInput.InputEnumvalues) { Debug.Log($"Input: {input.ToString()} -> {inputVals[input]}"); } Debug.Log("=====Ouputs====="); foreach (var output in CrispOutput.OutputEnumvalues) { Debug.Log($"Output: {output.ToString()} -> {outputVals[output]}"); } Debug.Log("=====End-Case====="); }
/// <summary> /// Returns <c>(float, float)</c> tuple representing <see cref="FuzzyCartController.fuzzySystem"/>'s confidence that actions (drive, turn) should be taken, and the polarity of those actions. /// Based off the current values from <see cref="FuzzyCartController.sensor"/> /// </summary> /// <returns>A <c>(float, float)</c> tuple representing the actions (drive, turn)</returns> public (float, float) GetInstructions() { CrispInput input = GenerateInputFromSensors(); CrispOutput output = fuzzySystem.EvaluateFuzzyLogic(input); if (!Input.GetKey(KeyCode.Space)) { DebugOutLight(output); } else if (debug) { DebugOutLots(input, output); } output = ValidateOutput(output); return(output[CrispOutput.Outputs.ForwardBackwards], output[CrispOutput.Outputs.LeftRight]); }