|
||
Search Here
MISC
SKILLS
HARDWARE
SCIENCE |
Fuzzy Logic Background
If robots are to ever out-perform humans, they need this ability too.
Disadvantages of Binary Logic
case based example:
sensor value bounces between 127 and 128 (middle of range) 10 is a made up tweak constant
case based pseudocode: (note: On an 8 bit analog-to-digital converter, 127.5 is not possible) Case-baseed oscillation is very bad for your robot - jerky motions can quickly wear and break mechanical parts, and will waste huge amounts of energy in acceleration/deceleration. You could perhaps write a long cased-based list of sensor to speed conversions, but that would be painfully long, and will waste memory space and processing time.
This is where fuzzy logic comes in, as fuzzy control allows very smooth transitions between actions with less code.*See Below fuzzy logic example:
sensor value bounces between 127 and 128 (middle of range)
fuzzy based pseudocode: so on a scale of 0mph to 30mph: if say your sensor = 127, speed = 12.7 mph
(Note: So this above example isnt exactly fuzzy logic, but an oversimplified equation so that you can have a basis of understanding the later equations in this tutorial. This equation can be considered fuzzy logic if all added arbitrary weighted values equal 1, as explained later.) Not only is there a smooth transition between speeds, but the fuzzy program was much shorter and easier to write too! There are many other advantages.
Advantages of Fuzzy Logic
New sensors can easily be incorporated into the system simply by generating appropriate governing equations. Often you can combine these equations into one. Any number of inputs can be processed and outputs generated. Fuzzy logic is not limited to a few feedback inputs and one or two control outputs, nor is it necessary to measure or compute rate-of-change parameters in order for it to be implemented. Any sensor data that provides some indication of a system's actions and reactions is sufficient. This allows the sensors to be inexpensive and imprecise thus keeping the overall system cost and complexity low. Fuzzy logic can control nonlinear systems that would be difficult or impossible to model as case-based. Fuzzy controllers are far simpler than knowledge-based systems. You do not need to be a controls expert, or fully understand the physics of your robot, to design a fuzzy logic control system. Just like in PID control, fuzzy logic can be "tweaked" once the system is operating in order to optimize performance. Generally, fuzzy logic is so forgiving that the system will probably work the first time without any tweaking. Fuzzy logic in most cases takes up significantly fewer lines of code in programming. Having memory issues? This may be your solution. A disadvantage . . . There are exceptions to where case based programming is simpler to implement than fuzzy logic, such as when your mechanism can only work at a set of fixed outputs. Two examples would be gear changers, and navigating to fixed locations of objects centered around a robot arm. The following algorithms would still be possible, just highly complex and therefore not recommended. You can also use both methods, just mix and match to take only advantages of both.
Defining Fuzzy Logic With a Microcontroller
You would then put that number into another equation (usually just multiplied or divided by some user defined tweak constant) to be applied to the robot actuators. As shown in the fuzzy logic example above, this process is fairly simple.
Example of Fuzzy Logic
This conceptual robot has two photoresistors plugged into two ADC:
read right_sensor;
left_motor_speed = right_sensor * arbitrary_constant;
So basically, the more light a sensor gets, the faster the opposite side motor goes - making the bot turn into the light. Just 4 lines long! If/then statements are typically many more, and dont work so well. The above example has a flaw though, in that if the robot is in a dark area neither motor will work. Another better example:
read right_sensor;
left_motor_speed = (left_sensor - right_sensor) * arbitrary_constant;
Still, only four lines of code, yet the robot can track any light at any brightness level. The above equation still has an oscillation problem when both sensors bounce near zero, and the robot wont move if both sensors are zero, but fiddling with the arbitrary constant and adding additional parts to the equation will solve all of that. One last example, but one of many solutions:
right_motor_speed = (right_sensor - left_sensor) + arbitrary_constant/(left_sensor+1)^2;
Mixing Digital and Analog Sensors
right_motor_speed = (right_bumper*(-100)) + (right_sensor - left_sensor) * arbitrary_constant; Now if the bumper doesnt detect a wall (bumper = 0), then the algorithm acts like normal because the first term is zero. But if bumper=1 (wall collision), that first term becomes -100, meaning the motor will suddenly back up and away from the wall. You can also add a time delay in the code so the bot will back up for X amount of time, but for simplicity Id just add a resistor/capacitor on the sensor with X time constant. As you can see, no additional lines of code were added (other than read the new sensors). Its also no longer pure analog, but now has digital components too. Hows that for sensor fusion? ;) Note that you could use other digital sensors, such as sonar or encoders, in a similar way. You only limitation is how mathematically clever you are . . .
Negative Values in Fuzzy Logic
negative conversion example:
sensor_value=-255/2; //shifts everything into the negative, where 127 is 0 There are many other ways to do this that I wont get in to, but you get the idea. For further reading check out the programming variables tutorial. What if your sensor returns positive AND negative voltage values? Then set your microcontroller ground to 0V and your sensor ground to 2.5V (by using a voltage regulator). This way anything below 2.5V represents a negative value, and anything above it represents a positive voltage. Make sure your sensor output values are between 0V to 5V or you may damage the ADC. To do this, carefully scale a non-inverting amplifier with the right resistor values and place between your sensor output and the ADC input.
*Addendum on the Definition of Fuzzy Logic
**Addendum on Analog Computers
***Addendum on the Forum
|
|
Has this site helped you with your robot? Give us credit -
link back, and help others in the forums! Society of Robots copyright 2005-2014 |