0 Members and 1 Guest are viewing this topic.

#### rita

• Beginner
• Posts: 1
« on: January 08, 2010, 09:46:32 PM »
Iam Rita Dyana. I am Brawijaya University Indonesia's student and post graduate in Management Construction.. I get the task of fuzzy logic in operations research courses. Can you help me about everything on fuzzy logic, and fuzzy logic is used for what?
thanks

#### z.s.tar.gz

• Supreme Robot
• Posts: 540
• Linux Guru
« Reply #1 on: January 09, 2010, 04:41:08 PM »
http://www.societyofrobots.com/programming_fuzzy_logic.shtml

Basically, instead of "if greater than this do that" you make an algorithm that gradually adjusts things.
Save yourself the typing. Just call me Zach.

#### donggyu

• Jr. Member
• Posts: 28
« Reply #2 on: September 18, 2010, 04:10:53 PM »
Sorry for the bump. I have a question about fuzzy logic and I did not think a whole new topic was needed. The guide on SoR and many other people define fuzzy logic as a "If...then..." code. But what about "behaviors" such as Mr.Tidy (if you are familiar with him) going to sulk in the corner randomly? How do you make them do behaviors using fuzzy logic?

#### voyager2

• Supreme Robot
• Posts: 459
• Behold! The Impossible Triangle of robotics!
« Reply #3 on: September 18, 2010, 05:51:14 PM »
You would take a multitude of fuzzy inputs, and then use them to generate a unique behavior, or a mood.
Each fuzzy input is stored as a temporary variable, each variable is then used for pre determined things...

Like this:

This uses fuzzy logic, and multiple inputs to decide what to do when the battery is low.
Fuzzy logic can be anything in between 1 and 0, but remember your robot will see fuzzy logic as an analog input
And Admin said "Let there be robots!"
And it was good.

#### donggyu

• Jr. Member
• Posts: 28
« Reply #4 on: September 19, 2010, 09:06:04 AM »
Oh ok, thanks for the help. But since my robot does not have a battery monitor, does it mean it cannot do behaviors or moods? And could you give another example, please?

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #5 on: September 19, 2010, 09:15:15 AM »
You would take a multitude of fuzzy inputs, and then use them to generate a unique behavior, or a mood.
Each fuzzy input is stored as a temporary variable, each variable is then used for pre determined things...

Like this:

This uses fuzzy logic, and multiple inputs to decide what to do when the battery is low.
Fuzzy logic can be anything in between 1 and 0, but remember your robot will see fuzzy logic as an analog input

What?

Fuzzy Logic is the act of using unrelated inputs to determine behaviors of your robot. Having your robot charge when battery is low is not fuzzy logic, it's a state machine based behavior and a good practice.

Having your robot move in a certain way based on the reading of an unconnected ADC pin is fuzzy logic.

Humans can be spontaneous and unpredictable. Robots are very predictable, they behave exactly how we program them. Fuzzy logic tries to add some spontaneity by making decisions by seemingly random input. Thus, the 'logic' the robot follows is hard to understand, or is somewhat 'fuzzy'. Hence fuzzy logic.

#### donggyu

• Jr. Member
• Posts: 28
« Reply #6 on: September 19, 2010, 11:20:10 AM »
Thank you madsci. But how would the programming look like? How would you program unpredictable or random actions?

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #7 on: September 19, 2010, 11:28:18 AM »
depends what you are trying to make 'fuzzy'.

for example

//dance to the left
//dance to the right
else
//sulk in the corner

This is a very simplistic example, as you may find unconnected ADC pins will 'tend' to hover around some value. Some other things you could do is have it dance a certain way based off the light level in the room, or the temperature; or some odd equation based on both.

What Fuzzy logic does is make it seem to the outside observer that your robot is being spontaneous and random. There are many ways to do that, no one real answer. It's up to your creativity on how you do it.

#### donggyu

• Jr. Member
• Posts: 28
« Reply #8 on: September 19, 2010, 11:48:19 AM »
Thanks a bunch. Time to get to programming my robot.

Cheers!

#### knossos

• Robot Overlord
• Posts: 272
« Reply #9 on: September 19, 2010, 12:49:36 PM »
Fuzzy Logic is the act of using unrelated inputs to determine behaviors of your robot. Having your robot charge when battery is low is not fuzzy logic, it's a state machine based behavior and a good practice.

Having your robot move in a certain way based on the reading of an unconnected ADC pin is fuzzy logic.

Humans can be spontaneous and unpredictable. Robots are very predictable, they behave exactly how we program them. Fuzzy logic tries to add some spontaneity by making decisions by seemingly random input. Thus, the 'logic' the robot follows is hard to understand, or is somewhat 'fuzzy'. Hence fuzzy logic.

Actually what you describe is including randomization in your program.  Fuzzy logic is not randomness.  Its using an undefined value instead of a discrete value.  For those who don't know what a discrete value is, it is an absolute number, for example the glass is 75% full.  A fuzzy value is closer to how we use language.  We don't look at a glass and say its 75% full, we think "The glass is full" or "The glass is mostly full".  Those are effective descriptions that don't give exact values. What this usually means in programming is instead of using boolean logic (yes and no, or binary 0 and 1) we use a continuous scale that includes all real values from 0 to 1 to represent the answer.  For example if about 40% of people would answer "yes" to the question "Is the glass full?" then the fuzzy logic answer would 0.4.  The boolean answer would always be "no".

http://www.societyofrobots.com/programming_fuzzy_logic.shtml

Basically, instead of "if greater than this do that" you make an algorithm that gradually adjusts things.

Also, most fuzzy logic systems use adaptive fuzzy logic that allows the dynamic adjustment of values which is what z.s.tar.gz described here:

Basically, instead of "if greater than this do that" you make an algorithm that gradually adjusts things.
"Never regret thy fall,
O Icarus of the fearless flight
For the greatest tragedy of them all
Is never to feel the burning light."

— Oscar Wilde

#### knossos

• Robot Overlord
• Posts: 272
« Reply #10 on: September 19, 2010, 12:54:05 PM »
I know most people hate wikipedia, but I find the wikipedia description of fuzzy logic fairly accurate:

Quote
Fuzzy logic is a form of multi-valued logic derived from fuzzy set theory to deal with reasoning that is approximate rather than precise. In contrast with "crisp logic", where binary sets have binary logic, fuzzy logic variables may have a truth value that ranges between 0 and 1 and is not constrained to the two truth values of classic propositional logic.[1] Furthermore, when linguistic variables are used, these degrees may be managed by specific functions.

Basically boolean logic can be seen as a subset of fuzzy logic that only deals with the extreme truth values as 0 and 1 and ignores the gray (fuzzy) area in between.
"Never regret thy fall,
O Icarus of the fearless flight
For the greatest tragedy of them all
Is never to feel the burning light."

— Oscar Wilde

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #11 on: September 19, 2010, 01:53:24 PM »
Fuzzy logic is not randomness.

Hmm, I seem to be thinking of something else.

Looking through the Admin's tutorial, it seems I don't grasp how you can say one system uses fuzzy logic.

I know most people hate wikipedia, but I find the wikipedia description of fuzzy logic fairly accurate:

Quote
Fuzzy logic is a form of multi-valued logic derived from fuzzy set theory to deal with reasoning that is approximate rather than precise. In contrast with "crisp logic", where binary sets have binary logic, fuzzy logic variables may have a truth value that ranges between 0 and 1 and is not constrained to the two truth values of classic propositional logic.[1] Furthermore, when linguistic variables are used, these degrees may be managed by specific functions.

Basically boolean logic can be seen as a subset of fuzzy logic that only deals with the extreme truth values as 0 and 1 and ignores the gray (fuzzy) area in between.

Ok, so couldn't you say my PID motor controller is 'fuzzy logic' because it's not binary 1 or 0, (stop or full forward) but some value in between?

All the examples Admin uses are practical control systems, with names other then 'fuzzy'.

Quote

I guess i'm confused because:

Quote
Fuzzy logic was never developed or intended for use on robots. Its use was for describing things that didnt fit a binary description.

so really, is anything a robot can do ever truly 'fuzzy' then? or just some close approximation?

« Last Edit: September 19, 2010, 01:57:47 PM by madsci1016 »

#### paulstreats

• Supreme Robot
• Posts: 1,381
« Reply #12 on: September 19, 2010, 02:24:38 PM »
when I was learning fuzzy logic, I was introduced to "fuzzy tables" which help visualise how fuzzy logic works.

Imagine that we have a robot with a battery level monitor, a solar panel, and a light level monitor. The robot also has the ability to return to a base station for recharging (but is also charged by the solar panel).

Now normal computer decision making will be :-

is the battery low?
- yes - goto charging station
- no - carry on doing what im doing

is it a sunny day?
yes - never goto the recharging station
no - stay by the recharging station

so you can see that regular computer thinking generally involves asking a question and doing something depending on a "pre coded context" usually with just a yes/no question.

fuzzy logic gives the computer more of a choice then just 1 question or just a yes/no question.

Here is a table to illustrate the above robot:

SHOULD I RECHARGE?

As you can see, there is an answer derived from more than 1 source of information or the equivalent of asking 2 different questions about the given situation and deriving the best course of action depending upon their answers.

Also by making the fuzzy table intelligent, You can get it to alter its own answers depending upon its past experience. So if the  battery is at 40% and the light level is at 100% then the current answer would be "no dont recharge", but then if the next time it asks, the battery is at 20% then maybe it should alter the previous answer (time dependant of course so if it had been going for longer than 20 minutes before the battery got from 40% to 20% then dont alter the answer), which by using time and battery level on another fuzzy table, you can make the original fuzzy become changed or conditioned by a new fuzzy table.

So yes, robots can be fuzzy too

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #13 on: September 19, 2010, 02:53:25 PM »
So yes, robots can be fuzzy too

I was quoting Admin from the tutorial.

What you described is what I would call a multi-variable state machine or control system. The state transitions governed by two different sources of information. Both those sources are measurable, discrete values. Not truly 'fuzzy'.

I think i understand what fuzzy logic really is, and know why Admin said it was never meant for robots.

A human can look out a window and say 'it looks like rain' and that's using fuzzy logic. He/she came to that conclusion using many different things, feel of the air, look of clouds in the sky, etc. Nothing that can really be quantitatively measured, nor the logic behind the conclusion ever really understood.

But a robot can never do that. It can measure the humidity, temperature, light level, cloud coverage, etc. All are quantitative, discrete measurements. Then you could use lookup tables like above to fuse your sensor data together in an attempt to 'approximate' the fuzziness a human being has. But really, it's just discrete sensor fusion, and I imagine it has to be fairly well tuned to match what us human beings do with our fuzziness.

So I don't think a robot can ever be truly fuzzy, at least not tell true AI is developed. Or am I still not getting this?

Man I feel bad for Data now.

#### Razor Concepts

• Supreme Robot
• Posts: 1,856
« Reply #14 on: September 19, 2010, 03:30:33 PM »
Well, the robot could go to the internet and check the online weather in it region, and that could be fuzzy, since the meteorologists used fuzzy logic to predict the weather?

#### paulstreats

• Supreme Robot
• Posts: 1,381
« Reply #15 on: September 19, 2010, 03:50:53 PM »

So using fuzzy tables of available sensor data can also answer the weather question easily.
Humans can do the same, just check the visual colours and temperatures to produce an answer, if the answer is different than the outcome then we chooses the alternative answer next time.

Humans also put their own "emotions" into their thoughts so if you are in a bad mood then you might assume that its going to rain whereas if you are happy then you might look on the positive side and decide that its not.

Presumably you are wanting to know some way to make an additional layer to just sensor data.

An easy example is to just use a mood variable.

int mood;

decide what will alter the mood variable:
is it light or dark?
is it too noisy?
is there someone or something in your personal space?
what is the battery level?

Data like this can be put into a fuzzy table or a set of fuzzy tables to determine a mood reading.

The mood reading can form part of a fuzzy table including sensor data to produce higher level outcomes. where the outcome is also affected by the robots mood and not just that particular set of sensor data.

Its easy to see how layers can be built to produce fuzzier and fuzzier outcomes but are microcontrollers capable of the processing for really complex fuzzy operations? Not really, I did try but you can get away with some low level fuzzy logic like just a few mood type variables.

Also you can adapt this, you dont just need 1 mood variable you can have aggressiveness, happiness, shyness etc..

Entire behaviours can be built from these pseudo variables, so if your robot is in a shy state, non aggressive and not too happy then it can seek a quiet dark place to hang about in. if its happy, not aggressive and not shy then it could sing or whistle while it walks about.

You could also add stress. How much is there left to do? I have a map that I need to complete and things keep getting in the way (stress and aggressiveness increases. shyness decreases as it becomes more assertive to get the task done)

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #16 on: September 19, 2010, 03:53:23 PM »
Well, the robot could go to the internet and check the online weather in it region, and that could be fuzzy, since the meteorologists used fuzzy logic to predict the weather?

Hehe, i knew someone would say this. but really, it's just inheriting fuzziness from the human telling it what's going to happen. And i think meteorologists are definitely more fuzzy then logical.

I'm going to go ask a few PhDs at work if they can explain this to me better to see if i'm on the right track.

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #17 on: September 19, 2010, 04:19:35 PM »
So using fuzzy tables of available sensor data can also answer the weather question easily.
Humans can do the same, just check the visual colours and temperatures to produce an answer, if the answer is different than the outcome then we chooses the alternative answer next time.

The difference is humans don't measure discreet temperatures. They 'feel' hot or cold, and this is a fuzzy variable. So when they walk outside and predict it's going to rain by the fuzzy logic they apply to the fuzzy inputs they have.

These fuzzy tables aren't really fuzzy, at least according to the wiki definition. The 'reasoning' for determining the outcome is very precise, because you are comparing discrete sensor data with discrete tables row and column values.

Adding the mood variable to shift table values would make it more approximate, and i could see calling that 'fuzzy', but this mood variable itself is something random, be it off the light in the room, or noise. That's what I thought 'fuzzy logic' was initially but knossos says differently.

#### donggyu

• Jr. Member
• Posts: 28
« Reply #18 on: September 19, 2010, 04:40:46 PM »
I want to add fuzzy logic to the program here: http://letsmakerobots.com/start
Not the one in the attachment, the one further down in the tutorial. I want to add "sulk" and I've been working at it all day but I just can't do it.
This is what I had for sulk:

sulk:
servo 0, 150
high 7 : low 5 : low 6 : high 4 'turn around 180
pause 1200
high 5 : high 7 : low 4 : low 6 'start going away
wait 3
low 4 : low 5 : low 6 : low 7 'stop
wait 10
goto main

I just can't seem to add it into the program without a problem. Help please!!
« Last Edit: September 19, 2010, 05:02:32 PM by donggyu »

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #19 on: September 19, 2010, 04:49:16 PM »
donggyu, turns out i was a little off in my description of fuzzy logic. I was describing something more akin to 'fuzzy behaviors'.

Fuzzy logic seems to be sensor fusion for determining states. Are you trying to implement random behaviors, or fuzzy logic for sensor fusion?

#### donggyu

• Jr. Member
• Posts: 28
« Reply #20 on: September 19, 2010, 04:51:22 PM »
"Sulk"  so I guess that would be based on sensors. Or it could also be a random behavior I guess.

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #21 on: September 19, 2010, 05:35:06 PM »
I'm not familiar with the robot you linked.

Are you programming this in C? Some other language?

What exactly are you trying to add? What do you want it to do, and based off what inputs?

#### donggyu

• Jr. Member
• Posts: 28
« Reply #22 on: September 19, 2010, 05:40:48 PM »
Programming with picaxe. I am going to base it off of readings from the ir sensor. I wish to add a "sulk" behavior and a "breakfree" behavior. I am just focusing on "sulk" right now before I move onto the "breakfree" behavior.
« Last Edit: September 19, 2010, 05:43:02 PM by donggyu »

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #23 on: September 19, 2010, 05:42:35 PM »
base what? dance moves? behaviors?

Is the picaxe programmed in C or something else? (I'm not a PIC person. I use AVRs)

#### donggyu

• Jr. Member
• Posts: 28
« Reply #24 on: September 19, 2010, 05:44:05 PM »
Behaviors. I believe it is in BASIC programming language.

• Contest Winner
• Supreme Robot
• Posts: 1,450
« Reply #25 on: September 19, 2010, 05:47:38 PM »
You might have to wait for someone to take over, i'm not familiar with PICs and haven't done basic in long time.

But it would help us if you give us more of what you want to do.

IE, based of the IR reading, turn left, turn right, dance, etc.

#### donggyu

• Jr. Member
• Posts: 28
« Reply #26 on: September 19, 2010, 05:53:42 PM »
like you said in the example:

if b1>(number) then
gosub turnleft

else

if b2>(number) then
gosub turnleft

else

sulk

or something like that. I tried that already but it didnt work.
« Last Edit: September 19, 2010, 06:33:47 PM by donggyu »

#### knossos

• Robot Overlord
• Posts: 272
« Reply #27 on: September 20, 2010, 08:12:53 AM »
Fuzzy logic can be used in robotics as well as any electronics application.  It can be confusing to implement because it can seem counterintuitive at times but it is very similar to the way we think.

For example using conventional (boolean) logic here is a series of questions.  Think how you would answer them with using only a yes or no :

Is a dining room chair a chair?
Is a couch a chair?
Is a stool a chair?
Is a large rock a chair?
Is the ground a chair?

Here is a table showing an example of boolean values for the same questions:

 Statement Answer Is a dining room chair a chair? Yes Is a couch a chair? Yes Is a stool a chair? Yes Is a large rock a chair? No Is the ground a chair? No

In fuzzy logic the answer is both yes and no to all of the questions.  Confused? Well with fuzzy logic its more a matter of how chair-like is the object.  So those same questions might yeild answers like this:

 Statement Yes No Is a dining room chair a chair? 100 0 Is a couch a chair? 90 10 Is a stool a chair? 88 22 Is a large rock a chair? 10 90 Is the ground a chair? 0 100

Now how is this an improvement over conventional logic?

For example, if in a room with just a dining room chair, if you were told to find a chair and take a seat, with conventional logic you would walk over to the dining room chair and have a seat.  All well and good.  Fuzzy logic would give the same response because the dining room chair is 100% chair.

What happens with the couch?  Well depending on whether you answered yes or no would determine your response, above I answered yes, so you would have a seat on the couch.  Fuzzy logic would see the couch as 80% chair and have a seat on the couch.

Both are still even so far, but what happens when all that is in the room is a large rock or even nothing?  With conventional logic you wouldn't know what to do since there is no chair in the room.  Fuzzy logic would decide the rock is close enough and have a seat, or if no rock would have a seat on the ground.  Fuzzy logic wins this round.

What would you do if there is a dining room chair, a couch, a stool, and a rock all in the same room?  Which would be chosen?  With conventional logic it may be any of the answers.  With fuzzy logic the dining room chair would be preferred over the couch which would be preferred over the stool etc. Leaving the following solution:

Dining Room Chair > Couch > Stool > Large Rock > Ground.

This gives the fuzzy system much more flexibility.  Advantage fuzzy logic.

To summarize, conventional logic seeks to polarize everything into blacks and whites, where fuzzy logic tends to see the world as shades of gray.
"Never regret thy fall,
O Icarus of the fearless flight
For the greatest tragedy of them all
Is never to feel the burning light."

— Oscar Wilde

#### knossos

• Robot Overlord
• Posts: 272
« Reply #28 on: September 20, 2010, 09:42:54 AM »
@PaulStreats the table you describe sounds more like an expert system.  In an expert system a knowledgeable person defines the rules to follow to determine an appropriate answer.  Although tables like the one you describe are often used to plot the output of a fuzzy systems responses, the table itself does not accurately represent the fuzziness of the system nor the values in question.  Even the previous example I gave in my last post generalized the fuzzy system into a more boolean state for ease of understanding.  For example my questions only yielded a possible yes or no answer and all fuzzy states added up to a neat 100% figure (yes percentage + no percentage) which is not necessary in fuzzy logic and not even common.  Fuzzy answers are better modeled by a series of overlapping functions.  Each individual function is usually constrained to a maximum of 100% but all functions added together may, and commonly do, exceed 100% when summed.  I know this might sound confusing this picture somewhat shows the overlap I'm talking about.  When I get a chance I'll post a clearer example.
"Never regret thy fall,
O Icarus of the fearless flight
For the greatest tragedy of them all
Is never to feel the burning light."

— Oscar Wilde

• Supreme Robot
• Posts: 11,632
« Reply #29 on: September 29, 2010, 03:25:18 PM »
depends what you are trying to make 'fuzzy'.

for example

//dance to the left
//dance to the right
else
//sulk in the corner
This is actually case-based logic (only three possible actions), and not fuzzy logic. Boolean logic isn't a good term because it has only two options, whereas case-based can have many.

PID controllers are used when you fully understand the system, and you can properly model it. Robots are very complex machines, and you may not have the time/skills to write the differential equations needed to model it. A fuzzy algorithm is a type of 'fudged' PID controller, where it works 'good enough'. I'd say fuzzy logic is a sub-class of PID.

Here is an oversimplified example of case-based/boolean logic. Robot either moves forward or stops:

if(light_sensor_value>threshold)
move_forward();
else
stop;

And an oversimplified fuzzy logic equivalent. If no light, it will stop, a little light and will move slowly, or a lot of light and full speed:

robot_speed(light_sensor_value);