Created
June 13, 2017 02:46
-
-
Save senhorinha/31a5f6f3638c3d95734423c892fee789 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FUNCTION_BLOCK driver | |
VAR_INPUT | |
x : REAL; | |
y : REAL; | |
angle : REAL; | |
END_VAR | |
VAR_OUTPUT | |
volante : REAL; | |
END_VAR | |
FUZZIFY x | |
TERM esquerda := (0, 1) (0.35, 0.5) (0.5, 0); | |
TERM centro := TRAPE 0.4 0.45 0.55 0.65; | |
TERM direita := (0.5, 0) (0.65, 0.5) (1, 1); | |
END_FUZZIFY | |
FUZZIFY y | |
TERM longe := TRAPE 0 0.3 0.6 0.8; | |
TERM perto := TRAPE 0.6 0.75 0.85 1; | |
END_FUZZIFY | |
FUZZIFY angle | |
TERM leste := (0, 1) (2.5, 1) (90, 0) (270, 0) (357.5, 1) (360, 1); | |
TERM oeste := TRIAN 90 177.5 270; | |
TERM norte := TRIAN 0 87.5 180; | |
TERM sul := TRIAN 180 267.5 360; | |
TERM nordeste := TRIAN 0 30 90; | |
TERM noroeste := TRIAN 90 120 180; | |
TERM sudeste := TRIAN 270 300 360; | |
TERM sudoeste := TRIAN 180 210 270; | |
END_FUZZIFY | |
DEFUZZIFY volante | |
TERM vira_para_direita := TRIAN -1 -0.8 0; | |
TERM vira_nada := TRIAN -0.5 -0.1 0.5; | |
TERM vira_para_esquerda := TRIAN 0 0.8 1; | |
// In the list of fuzzy methods there is one called centro of area | |
// https://en.wikipedia.org/wiki/Defuzzification | |
METHOD : COA; | |
DEFAULT := 0; | |
END_DEFUZZIFY | |
RULEBLOCK No1 | |
AND : MIN; // Use 'min' for 'and' (also implicit use 'max' for 'or' to fulfill DeMorgan's Law) | |
ACT : MIN; // Use 'min' activation method | |
ACCU : MAX; // Use 'max' accumulation method | |
RULE 1 : IF x IS esquerda AND y IS perto AND angle IS leste THEN volante IS vira_para_direita; | |
RULE 2 : IF x IS esquerda AND y IS perto AND angle IS norte THEN volante IS vira_para_esquerda; | |
RULE 3 : IF x IS esquerda AND y IS perto AND angle IS nordeste THEN volante IS vira_para_direita; | |
RULE 4 : IF x IS esquerda AND angle IS noroeste THEN volante IS vira_nada; | |
RULE 5 : IF x IS esquerda AND angle IS oeste THEN volante IS vira_nada; | |
RULE 6 : IF x IS esquerda AND angle IS sul THEN volante IS vira_para_direita; | |
RULE 7 : IF x IS esquerda AND angle IS sudeste THEN volante IS vira_para_direita; | |
RULE 8 : IF x IS esquerda AND angle IS sudoeste THEN volante IS vira_para_direita; | |
RULE 9 : IF x IS esquerda AND y IS longe AND angle IS leste THEN volante IS vira_para_esquerda; | |
RULE 10 : IF x IS esquerda AND y IS longe AND angle IS norte THEN volante IS vira_para_esquerda; | |
RULE 11 : IF x IS esquerda AND y IS longe AND angle IS nordeste THEN volante IS vira_para_esquerda; | |
RULE 12 : IF x IS centro AND angle IS leste THEN volante IS vira_para_esquerda; | |
RULE 13 : IF x IS centro AND angle IS oeste THEN volante IS vira_para_direita; | |
RULE 14 : IF x IS centro AND angle IS nordeste THEN volante IS vira_para_esquerda; | |
RULE 15 : IF x IS centro AND angle IS noroeste THEN volante IS vira_para_direita; | |
RULE 16 : IF x IS direita AND y IS perto AND angle IS oeste THEN volante IS vira_para_esquerda; | |
RULE 17 : IF x IS direita AND y IS perto AND angle IS norte THEN volante IS vira_para_direita; | |
RULE 18 : IF x IS direita AND y IS perto AND angle IS noroeste THEN volante IS vira_para_esquerda; | |
RULE 19 : IF x IS direita AND angle IS nordeste THEN volante IS vira_nada; | |
RULE 20 : IF x IS direita AND angle IS leste THEN volante IS vira_nada; | |
RULE 21 : IF x IS direita AND angle IS sul THEN volante IS vira_para_esquerda; | |
RULE 22 : IF x IS direita AND angle IS sudeste THEN volante IS vira_para_esquerda; | |
RULE 23 : IF x IS direita AND angle IS sudoeste THEN volante IS vira_para_esquerda; | |
RULE 24 : IF x IS direita AND y IS longe AND angle IS oeste THEN volante IS vira_para_direita; | |
RULE 25 : IF x IS direita AND y IS longe AND angle IS norte THEN volante IS vira_para_direita; | |
RULE 26 : IF x IS direita AND y IS longe AND angle IS noroeste THEN volante IS vira_para_direita; | |
RULE 27 : IF x IS centro OR x IS direita AND angle IS sudeste THEN volante IS vira_para_esquerda; | |
RULE 28 : IF x IS centro OR x IS direita AND angle IS sudoeste THEN volante IS vira_para_esquerda; | |
RULE 29 : IF x IS centro OR x IS esquerda AND angle IS sudoeste THEN volante IS vira_para_direita; | |
RULE 30 : IF x IS centro OR x IS esquerda AND angle IS sudeste THEN volante IS vira_para_direita; | |
END_RULEBLOCK | |
END_FUNCTION_BLOCK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment