① 我想做一個小車超聲波避障的程序,用SR04模塊,但下載進去後小車怎麼也不能走,求大神幫忙看一下程序呀
但凡超聲測距,都要先看信號如何,然後再測試軟體。如果你只是買個模塊,弄個單片機,網路上考個程序,下載下去,這樣看小車能否動。自己都不知道測距的原理,程序的流程。別人也沒有辦法看的。
② 求基於51單片機的超聲波避障智能小車程序
避障的話,最好能用兩個以上超聲波模塊,這樣做就可以不用步進電機了。
你可以把兩到三個超聲波模塊按一定角度裝到車的前部,這樣就可以根據三個超聲波模塊回收的距離信息來判斷哪個方向有障礙物,從而選擇正確的方向前行。
③ 求助樹莓派避障小車,遇到 python 了
小白第一次上手 python ,用樹莓派,紅外和超聲波感測器做智障小車。 編譯錯誤:
RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(trip,GPIO.OUT)
Traceback (most recent call last):
File "xiaochetest.py", line 82, in <mole>
fwd()
TypeError: fwd() takes exactly 1 argument (0 given)
下面是小車的代碼:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
m1_fwd = 12
m1_rev = 11
m2_fwd = 13
m2_rev = 15
red_left = 07
red_right = 16
trip = 38
echo = 37
def init():
GPIO.setup(m1_fwd,GPIO.OUT)
GPIO.setup(m1_rev,GPIO.OUT)
GPIO.setup(m2_fwd,GPIO.OUT)
GPIO.setup(m2_rev,GPIO.OUT)
def stop(sleep_time):
GPIO.output(m1_fwd,False)
GPIO.output(m1_rev,False)
GPIO.output(m2_fwd,False)
GPIO.output(m2_rev,False)
time.sleep(sleep_time)
GPIO.cleanup()
def fwd(sleep_time):
GPIO.output(m1_fwd,GPIO.HIGH)
GPIO.output(m1_rev,GPIO.LOW)
GPIO.output(m2_fwd,GPIO.HIGH)
GPIO.output(m2_rev,GPIO.LOW)
time.sleep(sleep_time)
GPIO.cleanup()
def rev(sleep_time):
GPIO.output(m1_fwd,GPIO.LOW)
GPIO.output(m1_rev,GPIO.HIGH)
GPIO.output(m2_fwd,GPIO.LOW)
GPIO.output(m2_rev,GPIO.HIGH)
time.sleep(sleep_time)
GPIO.cleanup()
def right(sleep_time):
GPIO.output(m1_fwd,GPIO.HIGH)
GPIO.output(m1_rev,GPIO.LOW)
GPIO.output(m2_fwd,False)
GPIO.output(m2_rev,False)
time.sleep(sleep_time)
GPIO.cleanup()
def left(sleep_time):
GPIO.output(m1_fwd,False)
GPIO.output(m1_rev,False)
GPIO.output(m2_fwd,GPIO.HIGH)
GPIO.output(m2_rev,GPIO.LOW)
time.sleep(sleep_time)
GPIO.cleanup()
def get_distance():
GPIO.setup(trip,GPIO.OUT)
GPIO.setup(echo,GPIO.IN)
GPIO.output(trip,GPIO.HIGH)
time.sleep(0.000015)
GPIO.output(trip,GPIO.LOW)
while not GPIO.input(echo):
pass
t1 = time.time()
while GPIO.input(echo):
pass
t2 = time.time()
return (t2-t1)*34300/2
def turnaround():
GPIO.setup(red_left,GPIO.IN)
GPIO.setup(red_right,GPIO.IN)
while GPIO.input(red_left) and GPIO.input(red_right)==0:
rev()
if GPIO.input(red_left)==1:
left(1)
else:
right(1)
GPIO.cleanup()
while True:
distance = get_distance()
time.sleep(0.5)
if distance > 20:
fwd()
elif distance == 20:
stop()
else:
stop()
turnaround()
def fwd(sleep_time)
if distance > 20:
fwd()
調用 fwd 的時候要傳參數啊,錯誤提示說的比較清楚了。