这个程序有什么问题吗?
-
# Edge Impulse - OpenMV Image Classification Example from pyb import Servo import sensor, image, time, os, tf sensor.reset() # Reset and initialize the sensor. sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE) sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240) sensor.set_windowing((240, 240)) # Set 240x240 window. sensor.skip_frames(time=2000) # Let the camera adjust. net = "trained.tflite" labels = [line.rstrip('\n') for line in open("labels.txt")] clock = time.clock() while(True): clock.tick() img = sensor.snapshot() # default settings just do one detection... change them to search the image... for obj in tf.classify(net, img, min_scale=1.0, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5): print("**********\nPredictions at [x=%d,y=%d,w=%d,h=%d]" % obj.rect()) img.draw_rectangle(obj.rect()) # This combines the labels and confidence values into a list of tuples predictions_list = list(zip(labels, obj.output())) for i in range(len(predictions_list)): print("%s = %f"% (predictions_list[i][0], predictions_list[i][1])) print(clock.fps(), "fps") a = obj.output() maxx = max(a) print(maxx) maxxx = a.index(max(a)) print(maxxx) s1 = Servo(1) s2 = Servo(2) tim = pyb.Timer(4) #选一个时钟即可 #初始化这个时钟 tim.init(freq = 200) #假设每秒想判断舵机状态 200 次 #设定中断执行的内容为函数 `timCallback` tim.callback(timCallback) #设定状态标识与舵机转动一次最长时间 #参数意义: # - isDetect:是否检测到有垃圾 # - isInTask:舵机是否在转动 # - servoAngle:舵机应该去的角度 # - threadCount:计数器,用于计算时间 # - whereIsServo: 舵机到达的位置:0 为原位,1 为转到的目的 trash_thread = {'isDetect': True, 'isInTask': False ,'servoAngle': 0, 'threadCount': 0, 'whereIsServo': 0} servoTimeLim = 400 #例如 400ms,应该需要实验 while(1): #推断balabala #中断在不断进行,把全局变量的值赋给目标即可 s1.angle(trash_thread['servoAngle']) def timCallback #判断转动任务是否执行中,如果没有: if (trash_thread['isInTask'] == False): #判定是否有垃圾,有就根据最大概率设定舵机目标角度 #判断语句,判定后赋值给 trash_thread['isDetect'] True 或 False #随后就是有的话判断舵机该去的角度 if (trash_thread['isDetect']): #设定为任务执行状态中 trash_thread['isInTask'] = True if (maxxx == 0): trash_thread['servoAngle'] = 22 elif (maxxx == 1): trash_thread['servoAngle'] = 45 elif (maxxx == 2): trash_thread['servoAngle'] = 67 elif (maxxx == 3): trash_thread['servoAngle'] = 90 #状态归位 trash_thread['isDetect'] = False trash_thread['threadCount'] = 0 trash_thread['whereIsServo'] = 0 else: #无检测则保持原位 trash_thread['servoAngle'] = 0 #判断转动任务是否执行中,如果是: else: #开始转动后,每次中断计数器加一;随后计算开始旋转后的时间,若超出限制则认为到达位置 trash_thread['threadCount'] += 1 if (trash_thread['threadCount'] * 50 >= servoTimeLim): #到达后改变记录的舵机位置 trash_thread['whereIsServo'] += 1 #如果此次目标是回归原位 if (trash_thread['whereIsServo'] == 2): trash_thread['whereIsServo'] = 0 trash_thread['isInTask'] = False trash_thread['threadCount'] = 0 #如果此次目标是转到目标位置 elif (trash_thread['whereIsServo'] == 1): trash_thread['servoAngle'] = 0 else : pass
-
def那一行后面没有冒号。
-
@kidswong999 加了冒号还是这个问题啊
-
还没加括号,你得先学学语法吧。
-
而且这个函数定义还在死循环后面,永远运行不到的。