Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzy Logic Rules Producing Unexpected Results #85

Open
TheBariumOxide opened this issue Jan 28, 2025 · 1 comment
Open

Fuzzy Logic Rules Producing Unexpected Results #85

TheBariumOxide opened this issue Jan 28, 2025 · 1 comment
Assignees
Labels

Comments

@TheBariumOxide
Copy link

I used this library to control a simulated robot with obstacle avoidance. Fuzzy logic is used to calculate the turn radius based on 2 distance sensors.

For example, with the fuzzy system set up as:

# inputs
leftObstacleSensor.veryStrong = S(0, 25)
leftObstacleSensor.strong = trapezoid(0, 25, 25, 50)
leftObstacleSensor.medium = trapezoid(25, 50, 50, 75)
leftObstacleSensor.weak = trapezoid(50, 75, 75, 100)
leftObstacleSensor.veryWeak = R(75, 100)

rightObstacleSensor.veryStrong = S(0, 25)
rightObstacleSensor.strong = trapezoid(0, 25, 25, 50)
rightObstacleSensor.medium = trapezoid(25, 50, 50, 75)
rightObstacleSensor.weak = trapezoid(50, 75, 75, 100)
rightObstacleSensor.veryWeak = R(75, 100)

#output
turningRadius = Domain("Theta", -50.5, 50.5, res = 0.1)
turningRadius.mediumRight = triangular(-50.5, -49.5)
turningRadius.smallRight = triangular(-25.5, -24.5)
turningRadius.noTurn = triangular(-0.5, 0.5)
turningRadius.smallLeft = triangular(24.5, 25.5)
turningRadius.mediumLeft = triangular(49.5, 50.5)

when executing this rule:
R25 = Rule({(leftObstacleSensor.veryWeak, rightObstacleSensor.veryWeak) : turningRadius.noTurn})

the output is "-50.5" opposed to the expected "0"

My simulated robot project can be found here

@amogorkon amogorkon self-assigned this Jan 29, 2025
@amogorkon amogorkon added the bug label Jan 29, 2025
@amogorkon
Copy link
Collaborator

I completely revamped the defuzzification part and cleaned things up. Rule is now responsible for collecting and preparing the conditions while all the logic is in defuzz.py. By doing so, I figured that I re-scaled an already valid result. Removing this redundant step it's now producing 0.0 as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants