为什么我同时用I2C驱动IMU扩展版和P7,P8引脚驱动电机会报错,但是单独使用就不会。程序附上
-
from pyb import Pin, Timer
from machine import I2C
from bno055 import BNO055, AXIS_P7
from pid import PID
import timey_pid = PID(p=0.5)#, i=0, imax=1)
#x_pid = PID(p=0.001, i=1)i2c = I2C(2)
imu = BNO055(i2c)ain1 = Pin('P0', Pin.OUT_PP)
bin1 = Pin('P1', Pin.OUT_PP)pwma = Pin('P7')
pwmb = Pin('P8')
tim = Timer(4, freq=1000)
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)#x, y, z = imu.accelerometer() #print('Accelerometer (m/s^2) 三轴加速度:', x, y, z)
while(True):
z, y, x = imu.euler()
print('y,x',y,x)
if abs(-4.8) - abs(y)>0:
ain1.low()
elif abs(-4.8) - abs(y)<0:
ain1.high()
y_err = abs(abs(-4.8) - abs(y))
ch1.pulse_width_percent(y_pid.get_pid(y_err,1))
-
-
你检查一下OpenMV的磁盘里有没有
bno055.py
和pid.py
-
-
你格式化磁盘,然后重新复制进去,等红灯灭了,然后重启OpenMV