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



    • 代码是这样的

      # Select an area in the Framebuffer to copy the color settings.
      #from machine import I2C
      #from vl53l1x import VL53L1X
      import time
      
      from pid import PID
      from pyb import UART
      import math
      import json
      clock = time.clock() # Tracks FPS.
      
      # For color tracking to work really well you should ideally be in a very, very,
      # very, controlled enviroment where the lighting is constant...
      
      
      #i2c = I2C(2)
      #distance = VL53L1X(i2c)
      x_pid = PID(p=0.05, i=0.05, imax=100)
      d_pid = PID(p=0.05, i=0.1, imax=50)
      
      #uart1 = UART(3, 9600,timeout=1000)
      uart1=UART(3, 9600)
      uart1.init(9600, bits=8, parity=None, stop=1)
      uart2=UART(1, 9600)
      uart2.init(9600, bits=8, parity=None, stop=1)
      
      List=list()
      while(True):
      #    clock.tick() # Track elapsed milliseconds between snapshots().
          List=[1]
          if uart1.any():
      #        x_error =uart1.readline().decode()
              x_error = int(uart1.read().decode())
              print(x_error)
              SET=600
      
      
      #        x_output=x_pid.get_pid(x_error,1)
      #        print(x_output)
              if(x_error>=9999):
                  a=len(List)
                  D_24=0
                  D_13=0
                  List.append=("1")
                  a=len(List)
                  if(a>=3):
                      FH = bytearray([57,168])
                      uart2.write(FH)
      
                      data = bytearray([27,27,27,27,60,5,60,5])   ###
                      uart2.write(data)
                      print(int(D_13),int(D_24))
              else:
                  List=[0,]
                  if(abs(x_error)>SET):
      
                      x_output=d_pid.get_pid(x_error,1)
      
      
                      D_24=-x_output   ###
                      D_13=x_output  ###
                      if((D_13)>=0):
                          a=5
                      else:
                          a=60
                      if((D_24)>=0):
                          b=5
                      else:
                              b=60
      
      #               FH = bytearray([168,168])
      #               uart2.write(FH)
                      D_13=abs(D_13)
                      D_24=abs(D_24)
                      if((D_13)>35):
                          D_13=35
                      if((D_24)>35):
                          D_24=35
      
                      FH = bytearray([57,168])
                      uart2.write(FH)
                      data = bytearray([int(D_13),int(D_24),int(D_13),int(D_24),a,b,a,b])   ###
                      uart2.write(data)
      
      
      #                print(int(D_13),int(D_24),a,b,a,b)
      
      
                  else:
      #               x_output=x_pid.get_pid(x_error,1)
      #               print(x_output)
                      theta_default=0.5*math.pi            #  0.5*3.14
      #               l_threshold=100                     #####
                      delta_theta_max=0.785
                      a=delta_theta_max/SET
      #               print(a)
      #               x_output=x_pid.get_pid(x_error,1)
                      delta_theta=a*x_error
      #               d = distance.read()
      #               print(d)
      
                      k=30   ####
                      D_14=k*(math.cos(theta_default+delta_theta)+math.sin(theta_default+delta_theta))
                      D_23=k*(math.sin(theta_default+delta_theta)-math.cos(theta_default+delta_theta))
      #                print(D_14,D_23)
                      FH = bytearray([57,168])
                      uart2.write(FH)
                      data = bytearray([int(D_14),int(D_23),int(D_23),int(D_14),5,5,5,5])
                      uart2.write(data)
                      print(int(D_14),int(D_23),int(D_23),int(D_14),5,5,5,5)
      
      
      会报错:AttributeError: 'NoneType' object has no attribute 'append'


    • 你的数组的列表操作都是错的。建议重新学一下语法:https://www.runoob.com/python3/python3-list.html

      44行,List.append=("1"),append是函数,应该是List.append("1"),而且为啥是字符串,应该改为List.append(1)。