• 免费好用的星瞳AI云服务上线!简单标注,云端训练,支持OpenMV H7和OpenMV H7 Plus。可以替代edge impulse。 https://forum.singtown.com/topic/9519
  • 我们只解决官方正版的OpenMV的问题(STM32),其他的分支有很多兼容问题,我们无法解决。
  • 如果有产品硬件故障问题,比如无法开机,论坛很难解决。可以直接找售后维修
  • 发帖子之前,请确认看过所有的视频教程,https://singtown.com/learn/ 和所有的上手教程http://book.openmv.cc/
  • 每一个新的提问,单独发一个新帖子
  • 帖子需要目的,你要做什么?
  • 如果涉及代码,需要报错提示全部代码文本,请注意不要贴代码图片
  • 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。
  • 机器帧率就为0卡死了。详细描述如下



    • 0_1690191755432_mv.png

      Untitled - By: xiongM - 周日 7月 23 2023

      如下,这段代码中,如果我同时使用了这些io和pwm和lcd,那么运行时帧率就为0,如果我把io和pwm去了或者把屏幕刷新去了那么就能正常工作了!!

      THRESHOLD = (2, 100, -29, 17, -14, 38) # Grayscale threshold for dark things...
      GRAY = (0, 16)
      
      import sensor, image, time, lcd
      from pyb import LED
      from pyb import Pin, Timer
      from pid import PID
      #import car
      
      sensor.reset()
      sensor.set_vflip(True)
      sensor.set_hmirror(True)
      sensor.set_pixformat(sensor.RGB565) #这里色彩模式可以设置为RGB565或者GRAYSCALE
      sensor.set_framesize(sensor.QQQVGA) #如果下面robust = True那么这里的分辨率越小越好,大了花费时间较多
      sensor.set_auto_gain(False)
      sensor.set_auto_whitebal(False)
      sensor.skip_frames(time = 2000)     # WARNING: If you use QQVGA it may take seconds
      clock = time.clock()                # to process a frame sometimes.
      lcd.init()
      
      
      inverse_left=True  #change it to True to inverse left wheel
      inverse_right=True #change it to True to inverse right wheel
      
      ain1 =  Pin('P0', Pin.OUT_PP)
      ain2 =  Pin('P1', Pin.OUT_PP)
      bin1 =  Pin('P2', Pin.OUT_PP)
      bin2 =  Pin('P3', Pin.OUT_PP)
      ain1.low()
      ain2.low()
      bin1.low()
      bin2.low()
      
      pwma = Pin('P7')
      pwmb = Pin('P8')
      tim = Timer(4, freq=1000)  #实例化定时器4,并初始化频率为1000hz
      ch1 = tim.channel(1, Timer.PWM, pin=pwma)
      ch2 = tim.channel(2, Timer.PWM, pin=pwmb)
      ch1.pulse_width_percent(0)
      ch2.pulse_width_percent(0)
      
      current_left_speed  = 0
      current_right_speed = 0
      
      def run(left_speed, right_speed):
          if abs(left_speed) >= 30 or abs(right_speed) >= 30:
              return
      
          #print(left_speed, right_speed)
      
          global current_left_speed
          global current_right_speed
      
          current_left_speed  = left_speed
          current_right_speed = right_speed
      
          if inverse_left==True:
              left_speed=(-left_speed)
          if inverse_right==True:
              right_speed=(-right_speed)
      
          if left_speed < 0:
              ain1.low()
              ain2.high()
          else:
              ain1.high()
              ain2.low()
          ch1.pulse_width_percent(int(abs(left_speed)))
      
          if right_speed < 0:
              bin1.low()
              bin2.high()
          else:
              bin1.high()
              bin2.low()
          ch2.pulse_width_percent(int(abs(right_speed)))
      
      def stop():
          speed_left = current_left_speed
          speed_right = current_right_speed
          run(speed_left * 0.5, speed_right * 0.5)
          time.sleep_ms(100)
          run(speed_left * 0.5, speed_right * 0.5)
          time.sleep_ms(100)
          run(speed_left * 0.5, speed_right * 0.5)
          time.sleep_ms(100)
          run(speed_left * 0.5, speed_right * 0.5)
          time.sleep_ms(100)
          run(0,0)
          ain1.low()
          ain2.low()
          bin1.low()
          bin2.low()
      
      def car_test():
          run(50, 50)
          time.sleep_ms(1000)
          stop()
      
      #run(10,10)
      
      rho_pid = PID(p=0.4, i=0)
      theta_pid = PID(p=0.001, i=0)
      
      while(True):
          img = sensor.snapshot().binary([THRESHOLD], invert=True)
          img.erode(1)
          line = img.get_regression([(100,100)], robust = True)
      
          if(line):
      
              img.draw_line(line.line(), color = 127)
              if line.theta()>90:
                  theta_err = line.theta()-180
              else:
                  theta_err = line.theta()
              rho_err = abs(line.rho())-img.width()/2
      
              #print(theta_err, line.magnitude(), line.rho())
      
              if line.magnitude()>8:  #这里理解为回归置信度,数字越大越好
                  rho_output = rho_pid.get_pid(rho_err, 1)
                  theta_output = theta_pid.get_pid(theta_err, 1)
      
                  output = rho_output+theta_output
                  run(20+output, 20-output)
                  #print(output)
      
              else:
                  #car.run(0,0)
                  pass
          lcd.display(img)
      


    • LCD和你的电机控制的io引脚冲突,不能一起使用。



    • 请问一下在哪儿看lcd需要用到那些引脚呢?