Presentation is loading. Please wait.

Presentation is loading. Please wait.

Example 20 Fuzzy Control Lecture L10.2.

Similar presentations


Presentation on theme: "Example 20 Fuzzy Control Lecture L10.2."— Presentation transcript:

1 Example 20 Fuzzy Control Lecture L10.2

2 Fuzzy Control Design of a Fuzzy Controller Fuzzification of inputs
MEM and fill_weights() Processing the Rules REV and fire_rules(…) Output Defuzzification WAV and calc_output(…)

3 Fuzzy Rules IF A AND B THEN L * *
Fuzzy Control Inputs Map to Fuzzy Sets get_inputs(); Fuzzy Rules IF A AND B THEN L * * fire_rules(); Defuzzification find_output(); Output

4 Plexiglas tube Ping-pong ball Problem: Maintain ping-pong ball floating at a specified height Ultrasonic transducer Muffin fan

5 Input membership functions for floating ping-pong ball

6 Output membership functions for floating ping-pong ball

7 Fuzzy K-map for floating ping-pong ball

8

9 Fuzzy Control Design of a Fuzzy Controller Fuzzification of inputs
MEM and fill_weights() Processing the Rules REV and fire_rules(…) Output Defuzzification WAV and calc_output(…)

10 A membership function is defined in terms of u1, u2, u3, and u4

11 Data structure used by the HCS12 MEM instruction
point_2 point_1

12 unsigned char memb_pos[20];
static int maxsize = 20; void main(void) { // input membership functions const unsigned char ball_position[] = { 0, 0, 30, 60, // neg_far 40, 60, 80,110, // neg_close 90,120,135,165, // zero_pos 150,175,185,220, // pos_close 200,220,255, // pos_far }; unsigned char memb_pos[20]; get_slopes(ball_position,memb_pos,maxsize);

13 unsigned char memb_speed[20];
const unsigned char ball_speed[] = { 0, 0, 20, 60, // neg_fast 35, 60, 80,110, // neg_slow 80,130,130,180, // zero_speed 155,175,185,215, // pos_slow 195,220,255, // pos_fast }; unsigned char memb_speed[20]; get_slopes(ball_speed,memb_speed,maxsize);

14 void get_slopes(const unsigned char ball[],unsigned char memb[],
int maxsize) { int j; unsigned char diff; for(j = 0; j < maxsize; j=j+4){ memb[j] = ball[j]; // point_1 memb[j+1] = ball[j+3]; // point_2 diff = (ball[j+1] - ball[j]); if(diff == 0) memb[j+2] = 0; else memb[j+2] = 255/diff; // slope_1 diff = (ball[j+3] - ball[j+2]); memb[j+3] = 0; memb[j+3] = 255/diff; // slope_2 }

15 // The fuzzy controller
while(1) { // x1 = get_position(); // (user defined) x1 = 100; // test case -- remove fill_weights(ptr_weight_pos,ptr_memb_pos,num_memb_pos,x1); // x2 = get_speed(); // (user defined) x2 = 150; // test case -- remove fill_weights(ptr_weight_speed,ptr_memb_speed,num_memb_speed,x2);

16 Fuzzy Control Design of a Fuzzy Controller Fuzzification of inputs
MEM and fill_weights() Processing the Rules REV and fire_rules(…) Output Defuzzification WAV and calc_output(…)

17 Pseudocode for fire_rules()

18 The HCS12 REV Instruction
if x1 is neg_far and x2 is neg_fast then y is pos_high

19 Fuzzy K-map inout_array[] indicies

20 unsigned char inout_array[] = {
0, // weight_pos[] 0 neg_far 0, // neg_close 0, // zero_pos 0, // pos_close 0, // pos_far 0, // weight_speed[] 5 neg_fast 0, // neg_slow 0, // zero_speed 0, // pos_slow 0, // pos_fast 0, // out[] neg_high 0, // neg_low 0, // zero_motor 0, // pos_low 0, // pos_high };

21 unsigned char rules[] = {
0,5,0xFE,14,0xFE, // if x1 is neg_far && x2 is neg_fast then y is pos_high 0,6,0xFE,14,0xFE, 0,7,0xFE,14,0xFE, 0,8,0xFE,13,0xFE, 0,9,0xFE,12,0xFE, 1,5,0xFE,14,0xFE, // if x1 is neg_close && x2 is neg_fast then y is pos_high 1,6,0xFE,14,0xFE, 1,7,0xFE,13,0xFE, 1,8,0xFE,12,0xFE, 1,9,0xFE,11,0xFE, 2,5,0xFE,14,0xFE, // if x1 is zero_pos && x2 is neg_fast then y is pos_high 2,6,0xFE,13,0xFE, 2,7,0xFE,12,0xFE, 2,8,0xFE,11,0xFE, 2,9,0xFE,10,0xFE, 3,5,0xFE,13,0xFE, // if x1 is pos_close && x2 is neg_fast then y is pos_low 3,6,0xFE,12,0xFE, 3,7,0xFE,11,0xFE, 3,8,0xFE,10,0xFE, 3,9,0xFE,10,0xFE, 4,5,0xFE,12,0xFE, // if x1 is pos_far && x2 is neg_fast then y is zero_motor 4,6,0xFE,11,0xFE, 4,7,0xFE,10,0xFE, 4,8,0xFE,10,0xFE, 4,9,0xFE,10,0xFF };

22 unsigned char* ptr_memb_pos;
unsigned char* ptr_memb_speed; unsigned char* ptr_weight_pos; unsigned char* ptr_weight_speed; unsigned char* ptr_inout_array; unsigned char* ptr_out; unsigned char* ptr_rules; unsigned char x1; // input x1 unsigned char x2; // input x2 unsigned char y; // output y ptr_memb_pos = memb_pos; ptr_memb_speed = memb_speed; ptr_weight_pos = inout_array; ptr_weight_speed = inout_array+num_memb_pos; ptr_inout_array = inout_array; ptr_out = inout_array+num_memb_pos+num_memb_speed; ptr_rules = rules;

23 // The fuzzy controller
while(1) { // x1 = get_position(); // (user defined) x1 = 100; // test case -- remove fill_weights(ptr_weight_pos,ptr_memb_pos,num_memb_pos,x1); // x2 = get_speed(); // (user defined) x2 = 150; // test case -- remove fill_weights(ptr_weight_speed,ptr_memb_speed,num_memb_speed,x2); fire_rules(ptr_inout_array,ptr_rules,ptr_out,num_memb_motor);

24 Fuzzy Control Design of a Fuzzy Controller Fuzzification of inputs
MEM and fill_weights() Processing the Rules REV and fire_rules(…) Output Defuzzification WAV and calc_output(…)

25 Pseudocode for find_output(…)
HCS12 WAV instruction computes numer and denom

26 // output membership functions unsigned char cent[] = {
5,65,128,175,22 }; unsigned char* ptr_cent; unsigned char y; // output y ptr_cent = cent;

27 // The fuzzy controller
while(1) { // x1 = get_position(); // (user defined) x1 = 100; // test case -- remove fill_weights(ptr_weight_pos,ptr_memb_pos,num_memb_pos,x1); // x2 = get_speed(); // (user defined) x2 = 150; // test case -- remove fill_weights(ptr_weight_speed,ptr_memb_speed,num_memb_speed,x2); fire_rules(ptr_inout_array,ptr_rules,ptr_out,num_memb_motor); y = calc_output(ptr_out,ptr_cent,num_memb_motor); // adjust_motor(y): // (user defined) }


Download ppt "Example 20 Fuzzy Control Lecture L10.2."

Similar presentations


Ads by Google