Hai,
Anyone please give the Fuzzy Logic example C code. In google there is a lot of theory. But less application code.
Here I want to drive a stepper motor for automotive throttle valve control. It is not linear, so now I am programmed as the throttle position is calculated by PID algorithm. But the control is like fuzzy logic using this PID value in lookup table.
So please help me to check my method is correct or not.
my fuzzy function is like below
int set_pid_range_for_stepper(float PID)
{
pid=PID;
if(pid<(-10) || (pid>10))
{
return 10;
}
else if(( pid>=(-15) && pid<(-9) ) || (pid>9 && pid<=15))
{
return 7;
}
else if((( pid>=(-9)) && ( pid<(-2.5))) || (pid>2.5 && pid<=9))
{
return 5;
}
else if( (pid>=(-2.5) && ( pid<=(-2))) || (pid>=2.5 && pid<=2))
{
return 4;
}
else if((pid>(-2) && pid<=(-1.5) ) || (pid>=1.5 && pid<2))
{
return 3;
}
else if((pid>(-1.5) && pid<=(-1) ) || (pid>=1 && pid<1.5))
{
return 2;
}
else if( (pid>(-1) && pid<0 ) || ((pid>0) && (pid<1)))
{
return 1;
}
else
{
return 0;
}
}
At present Using these code , the working of my setup is not bad.