Fuzzy Logic

Coyoteboy

Senior Member
Has anyone implemented fuzzy logic on a picaxe yet? I was thinking of knocking up a FL fan controller for a system I have but i think the defuzzification calculations may be a bit much for the axe to handle, especially something as small as the 08M?
 

BeanieBots

Moderator
The PICAXE is ideal for fuzzy logic:D
At the end of the day, FL is little more than a collection if/then statements that build up to make a decision based on a few inputs.
The issue is how to "model" those conditions and parameters in integer arithmatic.
At a simple level, something like the Autonomous Hexapod project that I posted in the Robots section is an implementation of fuzzy logic.
"what should the legs do if I get close to an object"?
"What should they do if I get very close"?
"What should they do if what I did wasn't the right thing to do"?

Could it replicate a dedicated programmable fuzzy logic controller chip? Probably not. I've done a few PID implemetations which is the next step up from FL. The biggest issue I found with PID was getting a reasonable update rate but FL maths is much simpler and should execute quickly (tens of Hz) once optimised. For more complex models, there's always the uFPU chip which Rev-Ed supply.

For a fan controller, I'm not sure how complex you could make it.
"It getting a bit hotter" then "make the fan go faster"
"It's getting a lot hotter" then "make the fan go much faster" and vice-versa
Maybe add another sensor for air flow?
"I've made the fan go faster but the air isn't flowing faster" then "fan is at max speed or blocked" call fire brigade!
 
Last edited:

hippy

Technical Support
Staff member
I think I probably agree with BeanieBots, emulating a dedicated Fuzzly Logic Controller Chip would be hard, and probably execute quite slowly.

I'm sure something could be done though, although I've never really grasped Fuzzy Logic; I find the standard 'thermostat' example ( probably relevent here for a fan controller ) to be particularly pointless and revealing little of the power or use of Fuzzy Logic. Maybe I've missed something, I'm sure reading a book which explains it well would help.

Perhaps the trick with a small processor is, decide what you want in Fuzzy Logic terms, then translate that into traditional code.
 

Coyoteboy

Senior Member
I would say that FL is more complex to implement properly, than PID, with full de-fuzzification, weighted functions etc? Sure the basic if-then statements are simple but they arent technically FL until you combine all outputs, defuz with weightings etc etc...? I've implemented PID on an 08M for fan control in the past, that wasn't too interesting (or effective), i was looking for something a tad more fun really:

My system is quite complicated in operation for on 08M, it consists of 3 parts:
Fan - PWM control
Radiator (2 temp sensors, one checking ambient temp air, the other water exit temp)
Heat exchanger (that the rad cools the water for)

The heat exchanger sits atop an engine and tends to heat up while stationary, likewise the rad gets no natural airflow, in this state the water heats rapidly and if not kept cool will rapidly heatsoak the hardware, taking ages to cool the HE back down. However the heat exchanger often heats up small "batches" of passing water in small quantities, these tend to be less important as they mix with cold fairly well to reduce the effect.
Hence I'd like a system that knows if the system is heating up long term (stationary) or just transiently, in which case the fan wont be quite so full-on, to save power.
___
I think the point of FL is that it can work very effectively with vague ideas of control, it doesnt need modelling and it doesnt need precise parameters to be tuned like gains on a PID - it takes care of that, for the most part, without too much interference. I think a specifically tuned PID would be a better solution, in terms of ideal response, but the fuzzy can be implemented without much effort and work to 95% of that of the perfect PID. Also fuzzy extends to multiple inputs without vast increases in the number of functions to be tested? I've not looked in massive detail, but I do have reports of fuzzy working as well to control robot manipulators with guesses at parameters as a fully tuned PID, hence my interest really. I think it might be overkill for a fan controller, but im interested and what else is spare time for?! :) I think FL is also very much parameter independant - the classic example thats quoted is the inverted pendulum test, a FL controller was set up to control an inverted pendulum, the guy then placed a mass on top of the pendulum (which would screw up a PID as the process parameters have changed) and the FL adapted quite happily, keeping the pendulum upright.
 
Last edited:

BeanieBots

Moderator
I accept your points about FL vs PID and the debate could go on forever without an exact problem and solution to prove one way or the other.
For your particular issue, I can see your favour for FL purely because it avoids having to model/define the parameters of the system.
However, in order to implement it on a PICAXE you will need to get a reasonably good model of the problem in order to keep the maths within the bounds of the working limits of word sized integer maths.
I wouldn't have thought that would be too difficult with a little experimentation using yourself as the controller and making very 'human' based calls on what should be done to the control outputs based on observed sensor readings.
Admittedly, the root square solutions of the matrix for de-fuzzyfying are probably beyond a bare PICAXE but not impossible if you can do most of the scaling up front. OK, that does mean you having to do a lot more work in partially solving the probelm but the result should be a good tight control. I guess it really depends if you want a solution to the specific problem or want to build a general fuzzy controller.

Have a look at the 28X1. It supports limited SQR function which is the bulk of the de-fuzzing problem. Also consider the uFPU which would allow much larger mathematical range to be used.

As many here know, I've been trying to implement neural nets with PICAXE for while but so far have been thwarted by the elusive sigmoid function. I've not yet tried with a uFPU due to cost (08M + uFPU) for each node, but one day...
If you do try to take fuzzy any further, please get back and let us know how it goes.
 

Coyoteboy

Senior Member
Good info there, noted. I'll give it a try and see if I can implement a simple fuzzy system, though as you say there are some fundamental limitations that might need workarounds. I'll keep you posted if it gets anywhere worth talking about :)
 

Dippy

Moderator
Very interesting, but I'm confused..
Are we using 'grandiose' terminology for something that can be achieved by normal logic?
And you can always fuzz-up your code to make it more flexible. But this project sounds fairly straight-forward.
Or have have I missed something here? (Apart from my coffee break).
 

gengis

New Member
Fuzzy

We are using 'grandiose' terminology for something that can be achieved by normal analog circuitry in the hands of a talented designer. PID sequencing and anticipating controllers were a lot easier in the old days - breadboard it then spend a few days tweaking it in.

Too much coffee only makes it seem more complex than it really is, IMHO. Beer, on the other hand, makes everything seem really simple.
 

Tom2000

Senior Member
Great find, Beanie. Thanks!

(I've visited that site a number of times before, but somehow missed that presentation.)

I'll confuse the issue some more. We have PID methodology. We have fuzzy logic. They appear to be somewhat related.

Is a Kalman filter related to these two?

Tom
 

BeanieBots

Moderator
I have no idea what a Kalman filter is but a quick google suggests that it is a method of extrapolating data between two measured points to estimate an unknown point that is required for a control algorithm to work.

So, IMHO no. It is a filter applied to a sensor input but I may be wrong.
Then again, technically, PID is only a filter but let's not go there:rolleyes:

That sight I posted covers the basics of most theorems and is a good starting point if you just want an overview.
If you want more information then you should find some doctorate papers on the subject. They can be rather heavy going but all said and done, undertanding control theory IS heavy going. It is a degree subject in its own right.
 

gengis

New Member
Without the hoopla

Fuzzy logic is an attempt at getting a digital machine to emulate an analog one. Digital treats everything (real world variables aren't on off or quantified within 4, 8, 16, 32 bits) as a precise known quantity.

A signal level (real variable) will never (almost never) exactly correspond to a digital variable.

Often enough, ALL the variables aren't fully understood by a designer - analog or digital.

For instance, operating a wood stove for heat - you could easily open the damper to increase the air, rate of burn, and raise the BTU output, but that is an oversimplistic way of looking at the control of wood stoves. An experienced operator would consider how much heat is needed, how warm the stove is, how thick the coal bed is, the species of wood being added as fuel, density of the wood, water content of the fuel, humidity, condition of the chimney, and still wouldn't have a handle on all the variables . . . but would be able to learn quickly and correct on the fly.

Old time pneumatic industrial controls used air as the sole source of power to open/close valves, maintain heating, levels in tanks, and a lot of other things with mechanical controls. They worked very well, but in today's terms, required an enormous amount of maintenance. Air did everything. Logic gates, analog controls, and the motive power for servos was all done with air. No sparks and little or no potential for an explosion, reason why so many pneumatic systems were developed.

They were incredibly sophisticated and could be analyzed just like electronic circuits - in fact maintenance people were usually drawn from electronic tech schools to service pneumatic systems. A resistor was a restriction in an air supply, a capacitor was a reservoir, an amplifier was a bellows controlling a tiny air valve, logic circuits were simple plastic blocks where a jet of air would deflect another jet and channel it into a different circuit.

Fuzzy logic was the first attempts to introduce a little flexibility or "noise" into all digital electronic controls. A good buzz word (obsfucating technical jargon) is never wasted and fuzzy has come to mean a lot of high falutin stuff over time.

Similar to what the "Beam Bot" folks are doing these days by drawing analogies from the spastic behavior of their creations and the snapses of nueral networks. Simple solar panel charging a cap to fire a relaxation oscillator and make a motor twitch- sounds better when you call it a synthetic neural network mobile platform.

My opinion . . . of all this fuzzy logic stuff
 

BeanieBots

Moderator
Jargon

@ Flooby Whilst I agree that a lot of jargon has been used inapropriately by many to describe the mundane to make it sound more interesting, it does have its place.
For example, the simple piston petrol engine is nothing more than squirt, squeeze, bang push applied to a crank. Now go and make one:confused:
You won't get far without a few terms like "top dead center" and an understanging of trigonometry.
I absolutely deplore anyone who refers to a pair of bump sensors as neural synapses but it is pefectly acceptable if you are developing a neural controller and happen to have used a basic robot chassis as the IO to that controller. It all boils down to appropriate use.
 
Top