public async Task ANFIS_OutputFromFuzzy() { IRobotArm robotArm = new RobotArm1(10, 7, 0, 1.57, 0, 3.1); robotArm.IsDataSetCalculated.ShouldBeFalse(); await robotArm.CalculateWholeDataSet(0.1); await robotArm.TrainANFIS(25, 150, false); robotArm.IsDataSetCalculated.ShouldBeTrue(); var point1 = new Point { X = 1.10413546487088, Y = 2.81104319371924 }; var point2 = new Point { X = 2.31665592712393, Y = 1.9375717475909 }; var point3 = new Point { X = 2.88944142930409, Y = 16.7526454098038 }; var output1 = await robotArm.CalculateAngelsUsingANFIS(point1); // 1.1 var output2 = await robotArm.CalculateAngelsUsingANFIS(point2); // 0.6 var output3 = await robotArm.CalculateAngelsUsingANFIS(point3); // 1.4 }
/// <summary> /// Calculate Arm Angels for given end position using trained ANFIS. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public async Task <JsonResult> CalculateAngelsUsingANFIS(double x, double y) { try { if (_robotArm == null) { throw new NullReferenceException("Robot Arm is not Initialized"); } var result = await _robotArm.CalculateAngelsUsingANFIS(new Point() { X = x, Y = y, Z = 0 }); if (double.IsNaN(result.Theta1) || double.IsNaN(result.Theta2)) { throw new Exception("Some of the coordinates is NaN."); } return(Json(new { Success = true, Outcome = result })); } catch (Exception e) { Console.WriteLine(e); return(Json(new { Success = false, e.Message })); } }