代码是这样的
# 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'