• OpenMV VSCode 扩展发布了,在插件市场直接搜索OpenMV就可以安装
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 串口通信,openmvide串行终端发送的数据和星瞳助手接收的数据不一样?



    • 0_1720666669494_屏幕截图 2024-07-11 105624.png

      THRESHOLD = (18, 61, 14, 89, -2, 63) # Grayscale threshold for dark things...
      import sensor, image, time,ustruct
      from pyb import UART,LED
      #from pid import PID
      #rho_pid = PID(p=0.4, i=0)
      #theta_pid = PID(p=0.001, i=0)
      import pyb
      LED(1).on()
      LED(2).on()
      LED(3).on()
      sensor.reset()
      #sensor.set_vflip(True)
      #sensor.set_hmirror(True)
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QQQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
      #sensor.set_windowing([0,20,80,40])
      sensor.skip_frames(time = 2000)     # WARNING: If you use QQVGA it may take seconds
      clock = time.clock()                # to process a frame sometimes.
      
      uart = UART(3,115200)   #定义串口3变量
      uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters
      
      #识别区域
      roi1 =     [(0, 17, 15, 25),        #  左  x y w h
                  (65,17,15,25),# 右
                  (30,0,20,15),#上
                  (0,0,80,60)]#停车
      
      
      def outuart(x,a,flag):
          global uart;
          f_x=0
          f_a=0
          if flag==0:
              if x<0:
                  x=-x
                  f_x=1
              if a<0:
                  a=-a
                  f_a=1
      
          if flag==1: #十字
              x,a,f_x,f_a=(0,0,0,1)
          if flag==2: #上左
              x,a,f_x,f_a=(0,0,1,0)
          if flag==3: #上右
              x,a,f_x,f_a=(0,0,1,1)
          if flag==4: #stop
              x,a,f_x,f_a=(1,1,1,2)
      
      
      
          #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B];
          #data = bytearray(frame)
          data = ustruct.pack("<bbhhhhb",      #格式为俩个字符俩个短整型(2字节)
                         0x2C,                      #帧头1
                         0x12,                      #帧头2
                         int(x), # up sample by 4   #数据1
                         int(a), # up sample by 4    #数据2
                         int(f_x), # up sample by 4    #数据1
                         int(f_a), # up sample by 4    #数据2
                         0x5B)
          if flag!=1:
              uart.write(data);  #必须要传入一个字节数组
          else:
      
              for x in range(50):
                  uart.write(data);  #必须要传入一个字节数组
                  time.sleep_ms(1)
      
      
      p9_flag=0 #p9需检测从低变高
      not_stop=0
      while(True):
          clock.tick()
          img = sensor.snapshot().binary([THRESHOLD])
          line = img.get_regression([(100,100)], robust = True)
          left_flag,right_flag,up_flag=(0,0,0)
          for rec in roi1:
                  img.draw_rectangle(rec, color=(255,0,0))#绘制出roi区域
          p = pyb.Pin("P9", pyb.Pin.IN)
          print(p.value())
          if p.value()==0:
              p9_flag=1
          if p.value()==1 and p9_flag==1:
              not_stop=1
              p9_flag=0
      
      
          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_pid直线左右偏移的距离,theta_err角度偏移
                  #rho_output = rho_pid.get_pid(rho_err,1)
                  #theta_output = theta_pid.get_pid(theta_err,1)
                  #output = rho_output+theta_output
                  outdata=[rho_err,theta_err,0]
                  print(outdata)
                  outuart(rho_err,theta_err,0)
                  if img.find_blobs([(96, 100, -13, 5, -11, 18)],roi=roi1[0]):  #left
                      #print('left')
                      left_flag=1
                  if img.find_blobs([(96, 100, -13, 5, -11, 18)],roi=roi1[1]):  #right
                      #print('right')
                      right_flag=1
                  if img.find_blobs([(96, 100, -13, 5, -11, 18)],roi=roi1[2]):  #up
                      #print('up')
                      up_flag=1
                  #if not img.find_blobs([(96, 100, -13, 5, -11, 18)],roi=roi1[3]):  #stop
                      ##print('up')
                      #stop_flag=1
                  if left_flag==1 and right_flag==1:
                      outuart(0,0,1)
                      #time.sleep_ms(5)
                      print('shizi')
                      continue
                  if left_flag==1 and up_flag==1:
                      outuart(0,0,2)
                      print('up-left')
                      continue
                  if right_flag==1 and up_flag==1:
                      outuart(0,0,3)
                      print('up-right')
                      continue
                  #if stop_flag==1:
                      #outuart(0,0,4)
                      #print('stop')
                      #continue
      
      
                  #car.run(50+output, 50-output)
              else:
                  #outuart(0,0,4)
                  ##car.run(0,0)
                  #print('stop')
                  pass
      
          else:
              #car.run(50,-50)
      
              outuart(0,0,4)
              #if  not_stop==1:
                  #time.sleep_ms(1000)
                  #not_stop=0
              print('stop')
          #print(clock.fps())
      
      


    • 星瞳串口助手,选择hex显示,不要选择utf8



    • 为啥不能用utf-8



    • 因为你发的不是utf8编码的字符串。

      如果你OpenMV端用uart.write("你好"),你就可以在串口助手里用utf8看到字符串。