Fuzzy controller

Top  Previous  Next

This chapter describes how to realize a Fuzzy motor controller.

 

fuzzy_controller_fis_editorfuzzy_controller_fis_editor_cspeed

 

fuzzy_controller_fis_editor_errfuzzy_controller_fis_editor_errval

 

 

function [ success ] = example_fuzzycontrol

 

ctrl = readfis('example_fuzzycontrol');

 

ea09com_init;

ea09com_bind( 8809 );

 

ea09com_setAddress( '172.26.254.254', 8809 );

 

send_RFV;

 

%set monitoring of motor 0 on

send_SetMMONITOR( 0, 1 );

send_SetMMONITOR( 1, 0 );

send_SetMMONITOR( 2, 0 );

send_SetMMONITOR( 3, 0 );

 

send_SetMCTRL( 0, 2 );

send_SetMCTRL( 1, 1 );

send_SetMCTRL( 2, 1 );

send_SetMCTRL( 3, 1 );

 

numReceived = 0;

i = 0;

e_prev = 0;

 

while( numReceived < 1000 )

   count = ea09com_update;

  while( count < 1 )

       count = ea09com_update;

  end;

   numReceived = numReceived + count;

 

   messageA = last_MessageA(0);

 

   speed_setpoint = messageA(3);

   actual_speed = messageA(4);

 

   e = speed_setpoint - actual_speed;

   errvar = e - e_prev;

   e_prev = e;

 

   u = evalfis( [e, errvar], ctrl )

 

  if( u > 255 )

       u = 255;

  elseif( u < -255 )

       u = -255;

  end;

 

   send_SetControlPoint( u, 0, 0, 0 );

end;

 

%set monitoring of motor 0 off

send_SetMMONITOR( 0, 0 );

 

send_SetMCTRL( 0, 1 );

 

index = 1;

 

messageA = takeFirst_MessageA(0);

 

startTime = messageA(2);

 

while( [num_MessageA(0)] > 0 )

   messageA = takeFirst_MessageA(0);

   ea09time(index) = messageA(2) - startTime;

   speed_setpoint(index) = messageA(3);

   actual_speed(index) = messageA(4);

   current(index) = messageA(5);

   control_point(index) = messageA(6);

   index = index + 1;

end;

 

ea09com_close;

 

title('Motor 0 monitor');

hold;

plot( ea09time, speed_setpoint / 255, 'Color', [1 0 0] );

plot( ea09time, actual_speed / 255, 'Color', [0 1 0]  );

plot( ea09time, current / 4096, 'Color', [0 0 1]  );

plot( ea09time, control_point / 255, 'Color', [1 0 1]  );

legend( 'speed set-point', 'actual speed', 'current', 'control point' );

hold;

 

 

fuzzy_controller