gintoki3452
Posts: 2
Joined: Fri Jun 03, 2016 1:17 pm

help with fuzzy logic for robot sensor

Fri Jun 03, 2016 1:40 pm

hello someone knows a library for raspberry fuzzy logic to apply to a robot that avoids obstacles with hc-SR04 sensor.
a bit of code that I need to apply my fuzzy logic

Code: Select all

from Tkinter import *
import RPi.GPIO as GPIO
import time

#plt.plot(distacex_small,distacex_safe,distacex_big)
#plt.show()
def measure():
 # This function measures a distance
 GPIO.output(GPIO_TRIGGER, True)
 time.sleep(0.00001)
 GPIO.output(GPIO_TRIGGER, False)
 start = time.time()

 while GPIO.input(GPIO_ECHO)==0:
   start = time.time()

 while GPIO.input(GPIO_ECHO)==1:
   stop = time.time()

 elapsed = stop-start
 distance = (elapsed * 34300)/2

 return distance

GPIO.setmode(GPIO.BCM)

# Define GPIO to use on Pi
GPIO_TRIGGER = 20
GPIO_ECHO    = 21

#motor

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18,100)

left_in1_pin = 24
left_in2_pin = 23
right_in1_pin = 22
right_in2_pin = 27
class Motor(object):
    def __init__(self, in1_pin, in2_pin):
        self.in1_pin = in1_pin
        self.in2_pin = in2_pin
                   
        GPIO.setup(self.in1_pin, GPIO.OUT)
        GPIO.setup(self.in2_pin, GPIO.OUT)
	
    def clockwise(self):
        GPIO.output(self.in1_pin, True)    
        GPIO.output(self.in2_pin, False)
    def counter_clockwise(self):
        GPIO.output(self.in1_pin, False)
        GPIO.output(self.in2_pin, True)
                   
    def stop(self):
        GPIO.output(self.in1_pin, False)    
        GPIO.output(self.in2_pin, False)
        
        

               


print "Ultrasonic Measurement"

# Set pins as output and input
GPIO.setup(GPIO_TRIGGER,GPIO.OUT)
# Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN)
# Echo

# Set trigger to False (Low)
GPIO.output(GPIO_TRIGGER, False)
time.sleep(0.01)
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.001)
GPIO.output(GPIO_TRIGGER, False)
begin = time.time()

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: No registered users and 15 guests