Presentation is loading. Please wait.

Presentation is loading. Please wait.

Example 20 Fuzzy Control Lecture L10.2. Fuzzy Control Design of a Fuzzy Controller Fuzzification of inputs –MEM and fill_weights() Processing the Rules.

Similar presentations


Presentation on theme: "Example 20 Fuzzy Control Lecture L10.2. Fuzzy Control Design of a Fuzzy Controller Fuzzification of inputs –MEM and fill_weights() Processing the Rules."— 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 Control Map to Fuzzy Sets Fuzzy Rules IF A AND B THEN L * * Defuzzification Inputs Output get_inputs(); fire_rules(); find_output();

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

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_1 point_2

12 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,255 // pos_far }; static int maxsize = 20; get_slopes(ball_position,memb_pos,maxsize); unsigned char memb_pos[20];

13 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,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]); if(diff == 0) memb[j+3] = 0; else 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, // 1 neg_close 0, // 2 zero_pos 0, // 3 pos_close 0, // 4 pos_far 0, // weight_speed[] 5 neg_fast 0, // 6 neg_slow 0, // 7 zero_speed 0, // 8 pos_slow 0, // 9 pos_fast 0, // out[] 10 neg_high 0, // 11 neg_low 0, // 12 zero_motor 0, // 13 pos_low 0, // 14 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 unsigned char* ptr_cent; unsigned char y;// output y ptr_cent = cent; // output membership functions unsigned char cent[] = { 5,65,128,175,22 };

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. Fuzzy Control Design of a Fuzzy Controller Fuzzification of inputs –MEM and fill_weights() Processing the Rules."

Similar presentations


Ads by Google