巡线代码,我的代码按照巡线小车实验改的,为什么老是报错?
-
THRESHOLD = (8, 40, -18, 0, -3, 19) import sensor, image, time from pyb import UART from pid import PID import ustruct rho_pid = PID(p=0.17, i=0) theta_pid = PID(p=0.001, i=0) sensor.reset() sensor.set_vflip(True) sensor.set_hmirror(True) sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQQVGA) sensor.skip_frames(time = 2000) clock = time.clock() uart = UART(3, 115200) output=0 while(True): clock.tick() img = sensor.snapshot().binary([THRESHOLD]) line = img.get_regression([(100,100)], robust = True) if (line): rho_err = abs(line.rho())-img.width()/2 if line.theta()>90: theta_err = line.theta()-180 else: theta_err = line.theta() img.draw_line(line.line(), color = 127) print(rho_err,line.magnitude(),rho_err) if line.magnitude()>8: #if -40<b_err<40 and -30<t_err<30: rho_output = rho_pid.get_pid(rho_err,1) theta_output = theta_pid.get_pid(theta_err,1) output = rho_output+theta_output else: output=0.0 else: output=0.0 pass date=bytearray([0x2C,0x12,int(output),0x00,0x00,0x00,0x5B]) uart.write(date)
-
-
报错很明显了,缩进有问题。
解决办法,把所有的tab缩进改为4个空格。
-
可以了把报错的地方一改就行了
-
-
@kidswong999 我没让他打印为什么在打印
-
这几个数据是
什么
-
不同的问题单独发帖子。
-
@p4mo
print,你让他打印了