tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch while True: 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)
import motor_driver_new as MD import com_distance_sensor_2 as DS import button_script as BS #side = right t_a = 0.2 #time of moving forward/backward to make 1 step t_b = 0.3 #time for turn on 90 degrees 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)
return 1 else: return 0 def button2_status(): curr2 = GPIO.input(10) #print("b2",curr2) 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)
import motor_driver_new as MD #Импортируем код с моторов from time import sleep #Импортируем sleep import serial1 as S #импорт кода дальномеров while 1 MD.all_motor_pwm_forward(30) time.sleep(0.25) dalnomer1 = S.dm_1() dalnomer2 = S.dm_2() print('dalnomer1', dalnomer1) print('dalnomer2', dalnomer2) if dalnomer1 < 10: MD.stop(1) if dalnomer2 > 20: MD.motor_pwm_forw_2(50) 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: