# Difference between revisions of "Fuzzy logic"

(Created page with "{{DISPLAYTITLE: Fuzzy Logic}} <yambe:breadcrumb self="Fuzzy Logic">Programming_Tips_Tricks|Programming Tips Tricks</yambe:breadcrumb> <br /> This is...") |
|||

(One intermediate revision by one user not shown) | |||

Line 3: | Line 3: | ||

<br /> | <br /> | ||

− | [[Moving_until_position|This]] is a great topic to talk about, so I'm going to do a related post about keeping an arm at a certain position with a potentiometer. I want to demonstrate the use of "fuzzy logic". I will use a simple mathematical function to prevent jerkiness in movement while keeping the arm at a certain position. If you want to find out more information on fuzzy logic (and I hope you do), look at this website: http://www.societyofrobots.com/ | + | [[Moving_until_position|This]] is a great topic to talk about, so I'm going to do a related post about keeping an arm at a certain position with a potentiometer. I want to demonstrate the use of "fuzzy logic". I will use a simple mathematical function to prevent jerkiness in movement while keeping the arm at a certain position. If you want to find out more information on fuzzy logic (and I hope you do), look at this website: http://www.societyofrobots.com/programming_fuzzy_logic.shtml |

Society of robots is a great site to visit for anything robotics related in general. | Society of robots is a great site to visit for anything robotics related in general. | ||

Anyway, here is an example:<br /> | Anyway, here is an example:<br /> | ||

Line 42: | Line 42: | ||

− | ERR_MTRPWR_RATIO: How much the motor responds to one unit of error. How much the motor power will change for every potentiometer tick away from your expected arm position. | + | '''ERR_MTRPWR_RATIO''': How much the motor responds to one unit of error. How much the motor power will change for every potentiometer tick away from your expected arm position. |

− | MTR_THRESH: Threshold below which the motor will not run. This is to prevent burned out motors and jerkiness. Since you will never exactly stay at the potentiometer value that you want (the ticks are very very small) this is to stop the motor from spasming when the error is very small. | + | '''MTR_THRESH''': Threshold below which the motor will not run. This is to prevent burned out motors and jerkiness. Since you will never exactly stay at the potentiometer value that you want (the ticks are very very small) this is to stop the motor from spasming when the error is very small. |

− | MAX_ARM: The maximum potentiometr value that you want your arm to go to. | + | '''MAX_ARM''': The maximum potentiometr value that you want your arm to go to. |

− | MIN_ARM: The minimum potentiometer value that you want your arm to go to. | + | '''MIN_ARM''': The minimum potentiometer value that you want your arm to go to. |

− | {{tip-from-author|name= | + | {{tip-from-author |

+ | |name=magicode | ||

+ | |link=http://www.vexforum.com/showpost.php?p=222136&postcount=10 | ||

+ | }} |

## Latest revision as of 20:43, 15 May 2012

This is a great topic to talk about, so I'm going to do a related post about keeping an arm at a certain position with a potentiometer. I want to demonstrate the use of "fuzzy logic". I will use a simple mathematical function to prevent jerkiness in movement while keeping the arm at a certain position. If you want to find out more information on fuzzy logic (and I hope you do), look at this website: http://www.societyofrobots.com/programming_fuzzy_logic.shtml
Society of robots is a great site to visit for anything robotics related in general.
Anyway, here is an example:

const double ERR_MTRPWR_RATIO = .05; const int MTR_THRESH = 20 const int MAX_ARM = 3000; const int MIN_ARM = 500; int armPosition = 0; int motorPower = 0; task keepArmInPosition(){ while(true){ motorPower = (armPosition - SensorValue[armPot]) * ERR_MTRPWR_RATIO; motor[arm] = abs(motorPower) > MTR_THRESH ? motorPower : 0; endTimeSlice(); } } task main(){ StartTask(keepArmInPosition); while(true){ //code armPos = 300; endTimeSlice(); } } |

This code keeps the motor power proportional to the error in the potentiometer value (the difference in the potentiometer value of where you want the arm to be, and where the arm is).

Here is a rundown of the constants:

**ERR_MTRPWR_RATIO**: How much the motor responds to one unit of error. How much the motor power will change for every potentiometer tick away from your expected arm position.

**MTR_THRESH**: Threshold below which the motor will not run. This is to prevent burned out motors and jerkiness. Since you will never exactly stay at the potentiometer value that you want (the ticks are very very small) this is to stop the motor from spasming when the error is very small.

**MAX_ARM**: The maximum potentiometr value that you want your arm to go to.

**MIN_ARM**: The minimum potentiometer value that you want your arm to go to.

*This tip was posted by magicode over at http://www.vexforum.com/showpost.php?p=222136&postcount=10.*