logo

关于巡线小车的疑问

2018-08-08 12:57
S
openmv萌新
from pyb import Pin, Timer
inverse_left=False  #change it to True to inverse left wheel
inverse_right=False #change it to True to inverse right wheel

ain1 =  Pin('P0', Pin.OUT_PP)
ain2 =  Pin('P1', Pin.OUT_PP)
bin1 =  Pin('P2', Pin.OUT_PP)
bin2 =  Pin('P3', Pin.OUT_PP)
ain1.low()
ain2.low()
bin1.low()
bin2.low()

pwma = Pin('P7')
pwmb = Pin('P8')
tim = Timer(4, freq=1000)
ch1 = tim.channel(1, Timer.PWM, pin=pwma)
ch2 = tim.channel(2, Timer.PWM, pin=pwmb)
ch1.pulse_width_percent(0)
ch2.pulse_width_percent(0)

def run(left_speed, right_speed):
    if inverse_left==True:
        left_speed=(-left_speed)
    if inverse_right==True:
        right_speed=(-right_speed)

    if left_speed < 0:
        ain1.low()
        ain2.high()
    else:
        ain1.high()
        ain2.low()
    ch1.pulse_width_percent(abs(left_speed))

    if right_speed < 0:
        bin1.low()
        bin2.high()
    else:
        bin1.high()
        bin2.low()
    ch2.pulse_width_percent(abs(right_speed))

请问这个程序是指直线处于屏幕中央时小车才前进吗?

如果我想识别双竖线而不识别单竖线的话应该咋办?

2018-08-08 15:24
X
Yuan

这段car.py只是控制电机运动的,完全不需要更改。你需要看main.py代码,这是巡线小车的主代码。是通过返回直线的角度来控制电机运动的。

双线识别和单线识别一致,get_regression()线性回归函数进行的巡线算法,完全不需要更改。

巡线小车 (http://book.openmv.cc/project/follow-lines.html)

2018-08-09 16:55
S
openmv萌新

@yuan 您好,那请问如果我想要识别双线而不是单线该怎样修改程序呢?是通过摄像头修改类似色域的设定吗?

X
Yuan

完全不需要修改代码

2018-08-10 13:31
S
openmv萌新

@yuan 您好,那如果我不修改代码的话,如何才能保证只识别双线而不识别单线呢?