Advertisement
Adik28

Sterownik rozmyty / A

Jan 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SterownikRozmyty
  8. {
  9.     public static class SI
  10.     {
  11.         public static List<List<int>> wartosciDlaX = new List<List<int>>();
  12.         public static List<List<int>> wartosciDlaKata = new List<List<int>>();
  13.         public static List<List<int>> wynikiRegul = new List<List<int>>();
  14.  
  15.         public static void inicjuj()
  16.         {
  17.             wartosciDlaX.Add(new List<int> { -100, 55 });
  18.             wartosciDlaX.Add(new List<int> { 0, 20 });
  19.             wartosciDlaX.Add(new List<int> { 100, 55 });
  20.  
  21.             wartosciDlaKata.Add(new List<int> { -180, 50 });
  22.             wartosciDlaKata.Add(new List<int> { -90, 40 });
  23.             wartosciDlaKata.Add(new List<int> { 0, 30 });
  24.             wartosciDlaKata.Add(new List<int> { 90, 40 });
  25.             wartosciDlaKata.Add(new List<int> { 180, 50 });
  26.  
  27.             wynikiRegul.Add(new List<int> { 20, 20, 20, 0, -20 });
  28.             wynikiRegul.Add(new List<int> { 20, 20, 0, -20, -20 });
  29.             wynikiRegul.Add(new List<int> { 20, 0, -20, -20, -20 });
  30.         }
  31.  
  32.         public static void zwroc_odpowiedz(PojazdPolozenie polozenie, out int obrot)
  33.         {
  34.             double licznik = 0;
  35.             double mianowink = 0;
  36.  
  37.             for (int i = 0; i < 3; i++)
  38.             {
  39.                 for (int j = 0; j < 5; j++)
  40.                 {
  41.                     var regula1 = zwroc_z_funkcji(polozenie.x, wartosciDlaX[i][0], wartosciDlaX[i][1]);
  42.                     var regula2 = zwroc_z_funkcji(polozenie.kat, wartosciDlaKata[j][0], wartosciDlaKata[j][1]);
  43.  
  44.                     licznik += regula1 * regula2 * wynikiRegul[i][j];
  45.                     mianowink += regula1 * regula2;
  46.                 }
  47.  
  48.             }
  49.             obrot = Convert.ToInt32(licznik / mianowink);
  50.         }
  51.  
  52.         public static double zwroc_z_funkcji(double x, double max, double sigma)
  53.         {
  54.             return Math.Exp((((x - max) / sigma) * ((x - max) / sigma)) * -1);
  55.         }
  56.  
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement