请问电机保存库函数的问题
-
你好小助手,因为官网的电机驱动库函数是有四个电平口,但是普通电机驱动板不需要那么多电平端所以我改了库函数,但是发现不能驱动,小助手你看看这个库函数改的有问题吗
from pyb import Pin, Timer inverse_left=False #change it to True to inverse left wheel inverse_right=False #change it to True to inverse right wheel ain1 = Pin('P0', Pin.OUT_PP) bin1 = Pin('P2', Pin.OUT_PP) ain1.low() bin1.low() 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) def run(left_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() else: ain1.high() ch1.pulse_width_percent(abs(left_speed)) if right_speed < 0: bin1.low() else: bin1.high() ch2.pulse_width_percent(abs(right_speed))
-
不清楚你什么电机驱动板,你需要照着真值表对照一下。