print('dm1: ', DS1.dm_1()) print('dm2: ', DS2.dm_2()) time.sleep(0.01) MD.all_motor_pwm_forward(50) dalnomer1 = DS1.dm_1() dalnomer2 = DS2.dm_2() if dalnomer1 < 25: if dalnomer2 > 25: time.sleep(3) MD.stop() MD.motor_pwm_forw_1(50) MD.motor_pwm_reverse_2(0) if dalnomer2 < 25: time.sleep(3) MD.stop() MD.motor_pwm_forw_2(50) MD.motor_pwm_reverse_1(0) else: if dalnomer2 > 25: time.sleep(3) MD.stop() MD.motor_pwm_forw_1(50) MD.motor_pwm_reverse_2(0)
if curr2 == 0: return 1 else: return 0 but_1 = button1_status() while True: MD.all_motor_pwm_forward(p1) time.sleep(1) MD.stop() but_1 = button1_status() dm_1 = DS1.dm_1() if but_1 ==1: MD.all_motor_pwm_reverse(p2) MD.motor_pwm_forw_1(p4) MD.motor_pwm_forw_2(p3) time.sleep(1) MD.stop() dm_1 = DS1.dm_1() if DS1.dm_1() < l: MD.motor_pwm_forw_1(p8) MD.motor_pwm_forw_2(p7) time.sleep(1) MD.stop() dm_1 = DS1.dm_1() if DS1.dm_1() < l: MD.motor_pwm_forw_1(p6) MD.motor_pwm_forw_2(p5) time.sleep(1) MD.stop()
MD.motor_pwm_reverse_1(50) time.sleep(0.33) stop() dalnomer1 = S.dm_1() dalnomer2 = S.dm_2() print('dalnomer1', dalnomer1) print('dalnomer2', dalnomer2) if dalnomer1 > 20: MD.all_motor_pwm_forward(30) dalnomer1 = S.dm_1() if dalnomer1 < 5 MD.stop(1) else: dalnomer2 < 20 MD.motor_pwm_forw_1(50) MD.motor_pwm_reverse_2(50) time.sleep(0.4) MD.stop() dalnomer1 = S.dm_1() dalnomer2 = S.dm_2() print('dalnomer1', dalnomer1) print('dalnomer2', dalnomer2) if dalnomer1 > 20: MD.all_motor_pwm_forward(30) dalnomer1 = S.dm_1() if dalnomer1 < 5 MD.stop(1) dalnomer1 = S.dm_1() dalnomer2 = S.dm_2()
p_s = 90 #power for steps p_t = 60 #power for turns c_a = 25 #dalnomer critical value while 1: but_f1 = BS.button1_status() dm_2 = DS.dm2() if but_f == 0 and dm_2 <= c_a: MD.all_motor_pwm_forward(p_s) sleep(t_a) MD.stop() if but_f == 0 and dm_2 > c_a: MD.all_motor_pwm_forward(p_s) sleep(t_a) MD.stop() MD.motor_pwm_forw_1(p_t) MD.motor_pwm_reverse_2(p_t) sleep(t_b) MD.stop() MD.all_motor_pwm_forward(p_s) sleep(t_a) MD.stop() if but_f == 1 and dm_2 <= c_a: MD.all_motor_pwm_reverse(p_s) sleep(t_a) MD.stop() MD.motor_pwm_forw_2(p_t) MD.motor_pwm_reverse_1(p_t) sleep(t_b) MD.stop() MD.all_motor_pwm_forward(p_s)
init_anykey() counter = 0 while True: print 'Operation: ', counter counter = counter + 1 key = anykey() if key == chr(119): print 'forward!' MD.all_motor_pwm_forward(20) time.sleep(0.2) if key == chr(115): print ('reverse') MD.all_motor_pwm_reverse(20) if key == chr(100): print ('right') MD.motor_pwm_forw_1(20) MD.motor_pwm_reverse_2(20) if key == chr(97): print ('left') MD.motor_pwm_forw_2(20) MD.motor_pwm_reverse_1(20) if key == chr(32): print ('stop') MD.stop()