导航

    • 登录
    • 搜索
    • 版块
    • 产品
    • 教程
    • 论坛
    • 淘宝
    1. 主页
    2. i56s
    I
    • 举报资料
    • 资料
    • 关注
    • 粉丝
    • 屏蔽
    • 帖子
    • 楼层
    • 最佳
    • 群组

    i56s

    @i56s

    0
    声望
    12
    楼层
    877
    资料浏览
    0
    粉丝
    0
    关注
    注册时间 最后登录

    i56s 关注

    i56s 发布的帖子

    • 外部中断报错RuntimeError:

      想实现如下功能:上电时等待检测信号(亮蓝灯),信号触发中断之后开始检测线段(此时亮绿灯),检测到之后红灯闪一下,又开始等待下一次的检测信号。代码如下:脱机运行正常,但是接IDE调试时外部中断触发两三次就会报错:Uncaught exception in ExtInt interrupt handler line 15 RuntimeError:

      import sensor, image, time,pyb,micropython,utime
      from pyb import Pin, ExtInt
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565) # grayscale is faster
      sensor.set_framesize(sensor.QQVGA)
      sensor.skip_frames(time = 2000)
      clock = time.clock()
      blue = pyb.LED(3)
      green = pyb.LED(2)
      red = pyb.LED(1)
      global start_flag
      start_flag =0  #上电时等待开始检测的信号
      
      def start(line):
          global start_flag
          start_flag = 1
      
      #外部中断P0口 上升沿触发 回调函数为start
      extint = pyb.ExtInt('P0', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_NONE, start)
      
      ok = Pin('P1', Pin.OUT_PP)
      
      while(True):
          clock.tick()
          img = sensor.snapshot()
          if enable_lens_corr:
              img.lens_corr(7.8) # 防畸变
          if start_flag == 1:
              blue.off()
              green.on() #开始检测指示灯
              for l in img.find_line_segments((0,45,160,30),merge_distance = 10, max_theta_diff = 180):
                  if l.length()>30:
                      img.draw_line(l.line(), color = (255, 255, 255))
                      start_flag = 0  #找到理想的线之后置零,不在检测
                      ok.high()
                      red.on()
                      utime.sleep_ms(100)
                      ok.low()
                      red.off()
      
          elif start_flag == 0:#等待信号时为蓝灯  工作时为绿灯  找到焊缝时开始等待
              blue.on()
              green.off()
      #    print('FPS %f' % clock.fps())
      
      发布在 OpenMV Cam
      I
      i56s
    • 外部中断程序单独可以运行,但是加入sensor.snapshot()函数之后就不行了?

      我想用两个中断控制两个颜色的灯,while里输出hello world时程序可以正常运行(即下面代码中注释掉的while)。但是加入sensor.snapshot()输出图像时就会报错,错误类型MemoryError: memory allocation failed, heap is locked

      import sensor, image, time,pyb,utime
      from pyb import Pin, ExtInt
      import micropython
      micropython.alloc_emergency_exception_buf(100)
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      
      clock = time.clock()
      
      a=b=0
      blue = pyb.LED(3)
      green = pyb.LED(2)
      stop_flag = 1
      def start(line):
          stop_flag = 0
          blue.off()
          green.on()
          print('start',)
      
      def stop(line):
          blue.on()
          green.off()
          print('stop')
      
      sta = ExtInt(Pin('P4'),ExtInt.IRQ_RISING,Pin.PULL_NONE, start)
      sto = ExtInt(Pin('P5'),ExtInt.IRQ_RISING,Pin.PULL_NONE, stop)
      
      
      while(True):
          clock.tick()
          img = sensor.snapshot()
      
      '''n=0
      while True:
          utime.sleep_ms(1000)
          n=n+1
          print('hello world',n)'''
      
      
      发布在 OpenMV Cam
      I
      i56s
    • RE: 调用外部中断时出现memory allocation failed, heap is locked?

      这样还是不行呀

      from pyb import Pin, ExtInt
      import sensor, image, time,pyb,micropython
      micropython.alloc_emergency_exception_buf(100)
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      
      clock = time.clock()
      
      def callback(line):
          global ExtInt
          ExtInt.disable()
          print("line =", line)
          ExtInt.enable()
      extint = pyb.ExtInt(Pin('P0'), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)
      while(True):
          clock.tick()
          img = sensor.snapshot()
      
      发布在 OpenMV Cam
      I
      i56s
    • RE: 调用外部中断时出现memory allocation failed, heap is locked?

      @kidswong999 因为之前可能没有消抖措施,所以出现RuntimeError: maximum recursion depth exceeded的错误,然后我在回调函数中加了屏蔽中断和开启中断的指令,再运行就出现上述的效果了。

      发布在 OpenMV Cam
      I
      i56s
    • RE: 我想在库中增加新的方法,请问openmv的库安装在什么地方?

      我知道github上有源码,但问题是我想修改源码啊,我下载下来修改之后能在IDE里面用吗?

      发布在 OpenMV Cam
      I
      i56s
    • 调用外部中断时出现memory allocation failed, heap is locked?

      另麻烦看一下我的代码有什么问题吗?进入回调函数先屏蔽中断再开中断可以吗

      from pyb import Pin, ExtInt
      import sensor, image, time,pyb,micropython
      micropython.alloc_emergency_exception_buf(100)
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      
      clock = time.clock()
      
      def callback(line):
          ExtInt.disable()
          print("line =", line)
          ExtInt.enable()
      extint = pyb.ExtInt(Pin('P0'), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)
      while(True):
          clock.tick()
          img = sensor.snapshot()
      
      发布在 OpenMV Cam
      I
      i56s
    • RE: openmv调用外部中断为什么没有反应?

      @kidswong999 因为之前可能没有消抖措施,所以出现RuntimeError: maximum recursion depth exceeded的错误,然后我在回调函数中加了屏蔽中断和开启中断的指令,再运行就出现上述的效果了。

      from pyb import Pin, ExtInt
      import sensor, image, time,pyb,micropython
      micropython.alloc_emergency_exception_buf(100)
      
      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)
      
      clock = time.clock()
      
      def callback(line):
          ExtInt.disable()
          print("line =", line)
          ExtInt.enable()
      extint = pyb.ExtInt(Pin('P0'), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)
      while(True):
          clock.tick()
          img = sensor.snapshot()
      
      发布在 OpenMV Cam
      I
      i56s
    • RE: openmv调用外部中断为什么没有反应?

      @kidswong999 新代码如下
      from pyb import Pin, ExtInt
      import sensor, image, time,pyb,micropython
      micropython.alloc_emergency_exception_buf(100)

      sensor.reset()
      sensor.set_pixformat(sensor.RGB565)
      sensor.set_framesize(sensor.QVGA)
      sensor.skip_frames(time = 2000)

      clock = time.clock()

      def callback(line):
      ExtInt.disable()
      print("line =", line)
      ExtInt.enable()
      extint = pyb.ExtInt(Pin('P0'), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)
      while(True):
      clock.tick()
      img = sensor.snapshot()

      出现错误MemoryError: memory allocation failed, heap is locked
      您看是什么原因啊?

      发布在 OpenMV Cam
      I
      i56s
    • RE: openmv调用外部中断为什么没有反应?

      @kidswong999 运行例子的效果是一直打印intr,还有不太懂例子中的e是什么意思

      发布在 OpenMV Cam
      I
      i56s
    • RE: openmv调用外部中断为什么没有反应?

      我想实现触发P0的中断时绿灯亮,P1中断触发蓝灯亮,可是运行之后却没有反应?请问这是什么原因?

      发布在 OpenMV Cam
      I
      i56s