以下为模糊算法源程序:
#include "reg52.h"
//------------------------------------------------------------------------------------
// 定义差距输入常量
#define GAP_ZERO
#define GAP_VSMALL
#define GAP_SMALL
#define GAP_MEDIUM
#define GAP_BIG
// 定义控制输出常量
#define TURN_ZERO
#define TURN_VSMALL
#define TURN_SMALL
#define TURN_MEDIUM
#define TURN_BIG
//-------------定义常量----------------------------------------------------------------
#define MU_MAX 0XFF
#define RULE_TOT 10
#define MF_TOT 5
#define IO_NUM 0x07
#define LABEL_NUM 0x70
#define DEFAULT_VALUE 0x00
//----------------定义数据库-----------------------------------------------------------
unsigned char code output_memf[MF_TOT]={0, 15, 35, 60, 102};// OUTPUT TURNING NUMBER:
unsigned char code input_memf[MF_TOT][4]={
// 输入功能函数以点斜式方式存储. 第一维成员函数标号第二维是点斜式数据
//距离功能函数
{ 0x00, 0x00, 0x00, 0x0d }, // VSLOW
{ 0x00, 0x0d, 0x14, 0x0d }, // SLOW
{ 0x1e, 0x0d, 0x32, 0x0d }, // MEDIUM
{ 0x3C, 0x0d, 0x50, 0x0d }, // FAST
{ 0x50, 0x09, 0x6e, 0x00 }
//-----------定义模糊系统规则-----------------------------------------------------------
unsigned char code rules[RULE_TOT]={
// if...
GAP_ZERO,TURN_ZERO,
GAP_VSMALL,TURN_VSMALL,
GAP_SMALL,TURN_SMALL,
GAP_MEDIUM,TURN_MEDIUM,
GAP_BIG,TURN_BIG
//-----------定义各变量-----------------------------------------------------------------
unsigned char outputs[MF_TOT],fuzzy_out;
//-----------子程序函数头申明-----------------------------------------------------------
void fuzzy_engine(uchar);
uchar compute_memval(uchar,uchar);
void defuzzify(void);
uchar compute_memval(uchar input,uchar label)
void defuzzify(void)
2.控制算法的总流程图,对应模糊控制算法的程序流程图