报错为not find类,但不理解怎么解决
-
@ugli 写错了,这个是line_calcu.py
-
@kidswong999 这个才是data_pack
import time, pyb, struct C = ord('C') F = ord('F') G = ord('G') B = ord('B') R = ord('R') L = ord('L') D = ord('D') U = ord('U') E = ord('E') S = ord('S') H = ord('H') uart3 = pyb.UART(3, 500000, timeout_char = 1000) green_led = pyb.LED(2) def send_89(direct,velcity): ''' 功能字为0x89,控制前进(后退)、左(右)、上升(下降)速度大小 speed字段必须正 ''' s = 0xAA+0x8C+direct+(int(velcity/256))+(int(velcity%256)) s = int(s % 256) temp_flow = struct.pack("<BBBBBhB", 0x00, 0xAA, 0x89, 03, direct, int(velcity), s) uart3.write(temp_flow) def send_98(direct,velcity): ''' 功能字为0x98,控制顺(逆)时针转动速度大小 speed字段正负一样 ''' s = 0xAA+0x9B+direct+(int(velcity/256))+(int(velcity%256)) s = int(s % 256) temp_flow = struct.pack("<BBBBBhB", 0x00, 0xAA, 0x98, 03, direct, velcity, s) uart3.write(temp_flow) def send_cmd(direct,velcity): if direct == C or direct == F: send_98(direct,velcity) time.sleep(3) else: send_89(direct,velcity) if direct == S: time.sleep(3)
-
@kidswong999 这个是car_calcu.py
import pyb,struct uart = pyb.UART(3,115200, timeout_char = 1000) def car_run(x1,x2): if x1 > 0 : right_value = x1 else : right_value = x1 if x2 > 0 : left_value = x2 else : left_value = x2 send_rpm(right_value,left_value) def send_rpm(right_value,left_value): left_rpm = int(left_value * 27) right_rpm = int(right_value * 27) left_rpm_low = left_rpm & 0x00ff left_rpm_high = left_rpm >> 8 right_rpm_low = right_rpm & 0x00ff right_rpm_high = right_rpm >> 8 xor = 0x6^0x3^0x4^(left_rpm_low)^(left_rpm_high)^(right_rpm_low)^(right_rpm_high) xor = (int(xor%256)) temp_flow = struct.pack("<BBBBBhhB", 0xaa, 0x55, 0x6, 0x3, 0x4, left_rpm, right_rpm, xor) ret = uart.write(temp_flow) print(left_rpm/27, right_rpm/27)
-
@kidswong999 实在抱歉,大佬,是我不熟悉这个论坛的问题,没有注意到插入代码,直接复制到了发言内容里,缩进被直接去掉了。
剩下最后一个包里的key_point.py了,很简短的一句:import sensor, image, time
再次抱歉,浪费了大佬宝贵的时间,但还是恬不知耻的想要请大佬赐教。万胜感激!
-
main.py是哪个啊?
OpenMV硬件的具体型号是什么?
-
@kidswong999 这个是main.py,具体型号为openMV4H7plus
import sensor, image, time, pyb, struct, math import pid, data_pack, t2017_task1, t2017_task2, t2017_task3, t2017_task_plus ######################初始化程序############################## sensor.reset() #对openmv进行复位 sensor.set_pixformat(sensor.GRAYSCALE) #以RGG565的格式读取像素信息 sensor.set_framesize(sensor.QQVGA) #分辨率为QQVGA:160*120 sensor.skip_frames(10) #前10帧数据舍去,避免刚刚启动,数据不稳定造成误判 sensor.set_auto_whitebal(False) #关闭自动白平衡 clock = time.clock() uart = pyb.UART(3, 500000, timeout_char = 1000) #打开串口3 red_threshold_01 = (0,55) #目标色块的灰度值参数范围 flag_x_y = 0 #这是一个标志位,循环调整无人机的x方向和y方向 num_stop = 0 #罚站次数,罚站即不对无人机进行位置调整 time_flag = 0 pid_x = pid.PID(80,0.5,0,0,30) #x轴方向的pid控制,pid参数要自己调 pid_y = pid.PID(60,0.5,0,0,30) #y轴方向的pid控制 task_number = 0 #任务切换 MV_ctrl_flag = 0 Buzzer = pyb.Pin("P6", pyb.Pin.OUT_PP) ##################各个字母所对应的ASCII值###################### R = ord('R') L = ord('L') S = ord('S') B = ord('B') G = ord('G') E = ord('E') H = ord('H') task1 = ord('a') task2 = ord('b') task3 = ord('c') task4 = ord('d') task5 = ord('e') ########################################################### def send_direction_packet(direct,velcity): #与无人机mcu的通信协议,数据打包并发送 s = 0xAA+0x8C+direct+(int(velcity/256))+(int(velcity%256)) #s是校验字节,是数据包里s之前所有数据的和 s = int(s % 256) #因为协议里s是8位的,这里取低八位 temp_flow = struct.pack("<BBBBhB", #数据包的封装格式,B:unsigned char; h:short 0xAA, 0x89, 03, direct, int(velcity), s) uart.write(temp_flow) while(True): times = clock.avg() clock.reset() #用来测量一个循环所用的时间,单位ms,不用的话这里也可以删掉 clock.tick() print("time: %d" %times) #task_number = 4 ###### while(task_number == 0): #获取任务ID task_char = uart.readchar() Buzzer.value(0) if task_char == task1: task_number = 1 elif task_char == task2: task_number = 2 elif task_char == task3: task_number = 3 elif task_char == task4: task_number = 4 elif task_char == task5: task_number = 5 else : task_number =0 print("task_number : %d" %task_number) if task_number != 2: #2 while(MV_ctrl_flag == 0): #判断openMV是否获得控制权 MV_ctrl_char = uart.readchar() if MV_ctrl_char == H: MV_ctrl_flag = 1 print("start work") if task_number == 1: t2017_task1.task_2017_1_1() elif task_number == 2: t2017_task2.task_2017_1_2() elif task_number == 3: t2017_task3.task_2017_1_3() elif (task_number == 4) or (task_number == 5): print("task number : %d" %task_number) t2017_task_plus.task_2017_2() ############################################################################################## ############################################################# ## # ## 此文件实现对黑色动态物体的跟踪 # ## # ############################################################# #import sensor, image, time, pyb, struct, math #import pid, data_pack #from machine import Pin #######################初始化程序############################# #sensor.reset() #对openmv进行复位 #sensor.set_pixformat(sensor.GRAYSCALE) #以RGG565的格式读取像素信息 #sensor.set_framesize(sensor.QQVGA) #分辨率为QQVGA:160*120 #sensor.skip_frames(10) #前10帧数据舍去,避免刚刚启动,数据不稳定造成误判 #sensor.set_auto_whitebal(False) #关闭自动白平衡 #clock = time.clock() #uart = pyb.UART(3, 500000, timeout_char = 1000) #打开串口3 #red_threshold_01 = (0,55) #目标色块的灰度值参数范围 #flag_x_y = 0 #这是一个标志位,循环调整无人机的x方向和y方向 #num_stop = 0 #罚站次数,罚站即不对无人机进行位置调整 #start_MV_flag = 0 #time_flag = 0 #prepare_flag = 0 #pid_x = pid.PID(80,0.3,0,0,30) #x轴方向的pid控制,pid参数要自己调 #pid_y = pid.PID(60,0.3,0,0,30) #y轴方向的pid控制 #Buzzer = pyb.Pin("P6", pyb.Pin.OUT_PP) #none_blob_flag = 0 ###################各个字母所对应的ASCII值###################### #R = ord('R') #L = ord('L') #S = ord('S') #B = ord('B') #G = ord('G') #E = ord('E') #H = ord('H') #task1 = ord('a') #task2 = ord('b') #task3 = ord('c') #task4 = ord('d') #task5 = ord('e') ############################################################ #def send_direction_packet(direct,velcity): #与无人机mcu的通信协议,数据打包并发送 #s = 0xAA+0x8C+direct+(int(velcity/256))+(int(velcity%256)) #s是校验字节,是数据包里s之前所有数据的和 #s = int(s % 256) #因为协议里s是8位的,这里取低八位 #temp_flow = struct.pack("<BBBBhB", #数据包的封装格式,B:unsigned char; h:short #0xAA, #0x89, #03, #direct, #int(velcity), #s) #uart.write(temp_flow) #def compareBlob(blob1, blob2): #比较两个色块大小的函数 #tmp = blob1.pixels() - blob2.pixels() #if tmp == 0: #return 0 #elif tmp > 0: #return 1 #else: #return -1 #while(True): #times = clock.avg() #clock.reset() #用来测量一个循环所用的时间,单位ms,不用的话这里也可以删掉 #clock.tick() #print("time: %d" %times) #img = sensor.snapshot().lens_corr(1.8) #blobs = img.find_blobs([red_threshold_01], #pixels_threshold=100, merge=True) #寻找目标色块,低于150像素的视为噪声 #img.binary([red_threshold_01], invert = True) #二值化处理 ## Buzzer.value(1) #while(start_MV_flag == 0): #value_from_flyctr = uart.readchar() #print("value_from_flyctr : %d" %value_from_flyctr) #if value_from_flyctr == H : #start_MV_flag = 1 #悬停计时开始标志位 #if len(blobs) == 2: #如果识别到目标色块 #print("the number of blobs is %d" %len(blobs)) #if(abs(blobs[0].cx()-80)<5) and \ #(abs(blobs[0].cy()-60)<5): #time_flag = 1 #if flag_x_y == 0 : #调节x与y方向的切换标志 #speed_x = pid_x.IncPIDCalc(blobs[0].cx()) ## print("speed_x: %f" %speed_x) #if speed_x > 0: #说明目标当前x值偏小,无人机偏右,需要向左调整 #send_direction_packet(L,speed_x) #else: #send_direction_packet(R,abs(speed_x)) #flag_x_y = 1 #标志位置1,表示下次循环调整y轴方向 #else : #speed_y = pid_y.IncPIDCalc(blobs[0].cy()) ##print("speed_y: %f" %speed_y) #if speed_y >= 0: #说明目标当前y值偏小,无人机偏后,需要向前调整 #send_direction_packet(G,speed_y) #else: #send_direction_packet(B,abs(speed_y)) #flag_x_y = 0 #标志位置0,表示下次循环调整x轴方向 #elif len(blobs) == 0: #print("the number of blobs is %d" %len(blobs)) #if prepare_flag == 0: #send_direction_packet(E,0) #没有检测到目标色块,这里让无人机原地罚站 #else: #send_direction_packet(G,5) #prepare_flag = 2 #else : #print("the number of blobs is %d" %len(blobs)) #bigBlob = blobs[0] #将第一个色块赋值给最大色块 #for blob_temp in blobs: #此循环找出最大色块,进一步滤除噪声 #if compareBlob(bigBlob, blob_temp) == -1: #bigBlob = blob_temp #if(abs(blobs[0].cx()-80)<5) and \ #(abs(blobs[0].cy()-60)<5) and \ #prepare_flag == 0: #prepare_flag = 1 #if(abs(blobs[0].cx()-80)<5) and \ #(abs(blobs[0].cy()-60)<5) and \ #prepare_flag == 2: #time_flag = 1 #if prepare_flag == 0 or prepare_flag == 2: #if flag_x_y == 0 : #调节x与y方向的切换标志 #speed_x = pid_x.IncPIDCalc(bigBlob.cx()) ## print("speed_x: %f" %speed_x) #if speed_x > 0: #说明目标当前x值偏小,无人机偏右,需要向左调整 #send_direction_packet(L,speed_x) #else: #send_direction_packet(R,abs(speed_x)) #flag_x_y = 1 #标志位置1,表示下次循环调整y轴方向 #else : #speed_y = pid_y.IncPIDCalc(bigBlob.cy()) ##print("speed_y: %f" %speed_y) #if speed_y >= 0: #说明目标当前y值偏小,无人机偏后,需要向前调整 #send_direction_packet(G,speed_y) #else: #send_direction_packet(B,abs(speed_y)) #flag_x_y = 0 #标志位置0,表示下次循环调整x轴方向 #else: #准备就绪,进入8区 #send_direction_packet(G,5) #if time_flag == 1: #num_stop += 1 #if num_stop >= 120 : #100次差不多5秒钟,降落 #send_direction_packet(L,15) #time.sleep(2000) #num_stop = 0 #send_direction_packet(E,0)