Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Mobile robot

1. Introduction

Robots are widely used for many purposes to serve the "lazy" economy. Therefore, its most
basic function should be to develop and avoid obstacles in the process of moving for
vacuuming, and mopping, .. Before the obstacles the robot detects, it has to decide how to
overcome that obstacle. Fuzzy logic is a decision-support tool widely applied in management,
engineering, and several related professions. It is widely deployed in traffic lights, robots,
washing machines, fruit sorting, etc.

2. methodology

Data is collected by controlling and manipulating variables. If there are no obstacles, the robot
will go straight by default. The input signal here is 3 obstacles: left, right, and center (in the
direction of robot movement). The output signal is the direction in the robot needs to turn to
avoid obstacles. Here, the robot moves in the direction of 2 wheels. The basic fuzzy rules are
built on the user's experience of moving and controlling.

3. Model of fuzzy logic


4. implementation
pip install scikit-fuzzy

import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl
SR = ctrl.Antecedent(np.arange(0,100,1),'SR')
SL= ctrl.Antecedent(np.arange(0,100,1),'SL')
SC = ctrl.Antecedent(np.arange(0,100,1),'SC')
DIR = ctrl.Consequent(np.arange(-100,100,1),'DIR')
SR['N'] = fuzz.trimf(SR.universe,[0,0,20])
SR['M'] = fuzz.trimf(SR.universe,[0,20,100])
SR['F'] = fuzz.trimf(SR.universe,[20,100,100])
SL['N'] = fuzz.trimf(SL.universe,[0,0,20])
SL['M'] = fuzz.trimf(SL.universe,[0,20,100])
SL['F'] = fuzz.trimf(SL.universe,[20,100,100])
SC['N'] = fuzz.trimf(SC.universe,[0,0,20])
SC['M'] = fuzz.trimf(SC.universe,[0,20,100])
SC['F'] = fuzz.trimf(SC.universe,[20,100,100])
DIR['thang'] = fuzz.trapmf(DIR.universe,[-100,0,0,100])
DIR['dung yen'] = fuzz.trapmf(DIR.universe,[0,0,0,0])
DIR['trai'] = fuzz.trapmf(DIR.universe,[-100,-100,0,0])
DIR['phai'] = fuzz.trapmf(DIR.universe,[0,0,100,100])
SR.view()
SL.view()
SC.view()
DIR.view()
rule1=ctrl.Rule((SC['N']&SR['N']&SL['N']),DIR['dung yen'])
rule2=ctrl.Rule((SC['M']&SR['N']&SL['N'])|(SC['M']&SR['M']&SL['N'])|
(SC['M']&SR['N']&SL['M'])|(SC['M']&SR['M']&SL['M'])|
(SC['F']&SR['N']&SL['N'])|(SC['F']&SR['M']&SL['N'])|
(SC['F']&SR['F']&SL['N'])|(SC['F']&SR['N']&SL['M'])|
(SC['F']&SR['M']&SL['M'])|(SC['F']&SR['F']&SL['M'])|
(SC['F']&SR['N']&SL['F'])|(SC['F']&SR['M']&SL['F'])|
(SC['F']&SR['F']&SL['F']),DIR['thang'])
rule3=ctrl.Rule((SC['N']&SR['N']&SL['M'])|(SC['N']&SR['N']&SL['F'])|
(SC['N']&SR['M']&SL['F'])|(SC['M']&SR['N']&SL['F'])|
(SC['M']&SR['M']&SL['F']),DIR['trai'])
rule4=ctrl.Rule((SC['N']&SR['F']&SL['N'])|(SC['N']&SR['M']&SL['M'])|
(SC['N']&SR['F']&SL['M'])|(SC['N']&SR['F']&SL['F'])|
(SC['M']&SR['F']&SL['N'])|(SC['M']&SR['F']&SL['M'])|
(SC['M']&SR['F']&SL['F']),DIR['phai'])
DIRing_ctrl = ctrl.ControlSystem([rule1,rule2,rule3,rule4])
DIRing = ctrl.ControlSystemSimulation(DIRing_ctrl)
DIRing.input['SR']=28
DIRing.input['SL']=81
DIRing.input['SC']=50
DIRing.compute()
print(DIRing.output['DIR'])
DIR.view(sim=DIRing)

5. result
Datasheet

5.1 input
5.2 output
6. Conclusion
Thanks to fuzzy logic, it becomes simpler and easier to avoid obstacles in the process of
moving to perform tasks. Because it is based on user experience. Here the variables sense and
give input values. Then the inputs are taken and different rules are used to give output values
(direction) that are more suitable and human-friendly.

You might also like