کتاب خونه skfuzzy

من ی پروژه کنترلر فازی دارم که با کتابخونه skfuzzy باهاش کار کردم
و یجایی بهم میگه که مشکلی هست
با سرچ هایی ک کردم میگن ک قانون ها کم هست و من قانون هارو زیاد کردم ولی بازم این مشکل پا بر جاست و اذیت کنننده
اروری ک ب من میده این موضوع این هست

ValueError: All antecedents must have input values!

import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
import matplotlib.pyplot as plot
import math

def distance(x_target, y_target, x_robot, y_robot):
x = (x_target - x_robot)
x = math.pow(x, 2)
y = (y_target - y_robot)
y = math.pow(y, 2)

dist = math.sqrt(x + y)

return dist
def theta(x_target, y_target, x_robot, y_robot):
tan = (y_target - y_robot) / (x_target - x_robot)
arctan = (np.arctan(tan) * 180) / np.pi

return arctan
get the size of map for calculating the longest distance
x_map = int(input('Enter width for Map'))
y_map = int(input('Enter height for Map'))

x_robot = int(input('Enter x for Robot'))
y_robot = int(input('Enter y for Robot'))

x_destination = int(input('Enter x for Destination'))
y_destination = int(input('Enter y for Destination'))

longest_distance = distance(x_map, y_map, 0, 0)
print("the longest distance", longest_distance)
robot_destination_distance = distance(x_destination, y_destination, x_robot, y_robot)
print(robot_destination_distance)
robot_destination_theta = theta(x_destination, y_destination, x_robot, y_robot)
print(robot_destination_theta)

universe variables
inputs
x_distance = ctrl.Antecedent(np.arange(0, longest_distance, 1), 'x_distance')
x_theta = ctrl.Antecedent(np.arange(0, 180, 1), 'x_theta')

outputs
speed_l = ctrl.Antecedent(np.arange(0, 100, 1), 'speed_l')

x_distance['Zero'] = fuzz.trimf(x_distance.universe, [0, 0, longest_distance / 4])
x_distance['Near'] = fuzz.trimf(x_distance.universe, [0, longest_distance / 4, longest_distance / 2])
x_distance['Medium'] = fuzz.trimf(x_distance.universe,
[longest_distance / 4, longest_distance / 2, (3 * longest_distance) / 4])
x_distance['Far'] = fuzz.trimf(x_distance.universe,
[longest_distance / 2, (3 * longest_distance) / 4, longest_distance])
x_distance['VeryFar'] = fuzz.trimf(x_distance.universe,
[(3 * longest_distance) / 4, longest_distance, longest_distance])

x_theta['Zero'] = fuzz.trimf(x_theta.universe, [0, 15, 30])
x_theta['Positive'] = fuzz.trimf(x_theta.universe, [0, 90, 180])
x_theta['BigPositive'] = fuzz.trimf(x_theta.universe, [90, 180, 180])

speed_l['VerySlow'] = fuzz.trimf(speed_l.universe, [0, 0, 25])
speed_l['Slow'] = fuzz.trimf(speed_l.universe, [0, 25, 50])
speed_l['Medium'] = fuzz.trimf(speed_l.universe, [25, 50, 75])
speed_l['Fast'] = fuzz.trimf(speed_l.universe, [50, 75, 100])
speed_l['VeryFast'] = fuzz.trimf(speed_l.universe, [75, 100, 100])

Rules for speed_l:
rule3 = ctrl.Rule(x_theta['Zero'], speed_l['VerySlow'])
rule4 = ctrl.Rule(x_theta['Positive'], speed_l['Slow'])
rule5 = ctrl.Rule(x_theta['BigPositive'], speed_l['VerySlow'])

rule6 = ctrl.Rule(x_distance['Near'] & x_theta['Zero'], speed_l['Slow'])
rule14 = ctrl.Rule(x_distance['Near'] & x_theta['Positive'], speed_l['Slow'])
rule15 = ctrl.Rule(x_distance['Near'] & x_theta['BigPositive'], speed_l['Slow'])

rule7 = ctrl.Rule(x_distance['Medium'] & x_theta['Zero'], speed_l['Medium'])
rule16 = ctrl.Rule(x_distance['Medium'] & x_theta['BigPositive'], speed_l['Medium'])
rule17 = ctrl.Rule(x_distance['Medium'] & x_theta['Positive'], speed_l['Medium'])

rule8 = ctrl.Rule(x_distance['Far'] & x_theta['Zero'], speed_l['Fast'])
rule18 = ctrl.Rule(x_distance['Far'] & x_theta['Positive'], speed_l['Fast'])
rule19 = ctrl.Rule(x_distance['Far'] & x_theta['BigPositive'], speed_l['Fast'])

rule9 = ctrl.Rule(x_distance['VeryFar'] & x_theta['Zero'], speed_l['VeryFast'])
rule20 = ctrl.Rule(x_distance['VeryFar'] & x_theta['Positive'], speed_l['VeryFast'])
rule21 = ctrl.Rule(x_distance['VeryFar'] & x_theta['BigPositive'], speed_l['VeryFast'])

rule10 = ctrl.Rule(x_distance['Zero'], speed_l['VerySlow'])
rule11 = ctrl.Rule(x_distance['Zero'] & x_theta['Zero'], speed_l['VerySlow'])
rule12 = ctrl.Rule(x_distance['Zero'] & x_theta['BigPositive'], speed_l['VerySlow'])
rule13 = ctrl.Rule(x_distance['Zero'] & x_theta['Positive'], speed_l['VerySlow'])
rule22 = ctrl.Rule(x_distance['Near'], speed_l['Slow'])
rule23 = ctrl.Rule(x_distance['Medium'], speed_l['Medium'])
rule24 = ctrl.Rule(x_distance['Far'], speed_l['Fast'])
rule25 = ctrl.Rule(x_distance['VeryFar'], speed_l['VeryFast'])

speed_l_ctrl = ctrl.ControlSystem([rule3, rule4, rule5, rule6, rule7, rule8, rule9, rule10, rule11, rule12, rule13, rule14, rule15, rule16, rule17, rule18, rule19, rule20, rule21, rule22, rule23, rule24, rule25])

compute_speed_l = ctrl.ControlSystemSimulation(speed_l_ctrl)

compute_speed_l.input['x_distance'] = robot_destination_distance
compute_speed_l.input['x_theta'] = robot_destination_theta

compute_speed_l.compute()

print(compute_speed_l.output['speed_l'])

درور بر شما دوست عزیز، لطفا عنوان بهتری برای مطلب انتخاب‌کنید و همچنین در مورد مشکلی که براتون بوجود اومده کاملتر توضیح‌ بدین. :relaxed:

1 Likes

من بلد نیستم عنوان رو ویرایش کنم ولی در مورد متن ی مقداری توضیح اضافه کردم

کلا قراره ی کنترلر بنویسم ک با پایتون مسیر ی ربات رو تو ی ماتریس از ی نقطه تا نقطه ی دیگه پیدا کنه و این قضیه رو با کنترلر فازی باید انجام داد

کنار عنوان یک مداد هست، میتونید ویرایش کنید.