logo

追小球的小车,car.py中的问题。

2019-04-19 15:31
E
qohd

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()

ain2.high()

else:

ain1.high()

ain2.low()

ch1.pulse_width_percent(abs(left_speed))

if right_speed < 0:

bin1.low()

bin2.high()

else:

bin1.high()

bin2.low()

ch2.pulse_width_percent(abs(right_speed))

按照真值表,if left_speed < 0的时候电机反转,为什么是ain1.low() ain2.high();而不是 ain1.high(),ain2.low()

b885fd49-f95e-4e7f-9a5c-c3abd1c3b5fc.png
2019-04-20 09:37
I
网红小智智 星瞳科技

正反是自己确定的。

正反和电机的摆放有关,和连线有关,和电源的方向有关。