logo

大佬们帮忙康康我的这个,感觉逻辑上行得通,就是舵机没办法正常转(转的幅度不大,而且感觉并不是和检测到的偏离很一致)

2020-09-06 16:52
U
t3p5
THRESHOLD = (0, 30, -10, 10, -20, 10)
import sensor, image, time
from pyb import Servo
import car
s1 = Servo(1) # servo on position 1 (P7)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
while(True):
    clock.tick()
    img = sensor.snapshot().binary([THRESHOLD])
    line = img.get_regression([(100,100,0,0,0,0)], robust = True)
    if (line):
        print('角度:',line.theta())
        if(line.theta()<10 or 170<line.theta()):
            s1.angle(0)
            print("中间")
        elif(90<line.theta()<170):
            s1.angle(180 - line.theta())
            print("偏左")
        else
        :
            s1.angle(line.theta())
            print("偏右")

    else:
        car.run(50,-50)
        pass
2020-09-07 13:50
I
网红小智智 星瞳科技

你把180 - line.theta()的值打印出来看看。

2020-09-07 17:42
U
t3p5
67de7a4f-f4e0-436e-8b75-c9e234a1ee7d.png
2020-09-08 18:53
I
网红小智智 星瞳科技

所以有什么问题。。。

I
网红小智智 星瞳科技

你要发送实际的结构图,和目的。