def measure_test(trig, echo, target): stime = time.time() dis = np.zeros(400) for i in range(400): dis[i] = togikai_ultrasonic.Mesure(GPIO, time, trig, echo) etime = time.time() ave_dis = np.mean(dis) if abs(ave_dis - target) < target / 10: print('ooo --- OK!, result = {0:.1f} cm'.format(ave_dis)) print('Sampling time = {0:.4f} s'.format((etime - stime) / 200)) else: print('xxx --- NG!, result = {0:.1f} cm'.format(ave_dis))
t_list=[15,13,35,32,36] GPIO.setup(t_list,GPIO.OUT,initial=GPIO.LOW) e_list=[26,24,37,31,38] GPIO.setup(e_list,GPIO.IN) #データ記録用配列作成 d = np.zeros(2) # print('Input test name') # test = input() # print('Input No.') # testno = input() # filename = '/home/pi/code/record_data/'+str(test)+str(testno)+'.csv' start_time = time.time() if __name__ == "__main__": try: for i in range(100): dis = togikai_ultrasonic.Mesure(GPIO,time,35,37) #距離データを配列に記録 d = np.vstack([d,[time.time()-start_time, dis]]) print('{0:.2f}'.format(dis)) time.sleep(0.1) GPIO.cleanup() # np.savetxt(filename, d, fmt='%.3e') print('average = ', np.mean(d[:,1])) except KeyboardInterrupt: # np.savetxt(filename, d, fmt='%.3e') print('stop!') GPIO.cleanup()
t_list = [15, 13, 35, 32, 36] GPIO.setup(t_list, GPIO.OUT, initial=GPIO.LOW) e_list = [26, 24, 37, 31, 38] GPIO.setup(e_list, GPIO.IN) #データ記録用配列作成 d = np.zeros(2) print('Input test name') test = input() print('Input No.') testno = input() filename = '/home/pi/code/record_data/' + str(test) + str(testno) + '.csv' start_time = time.time() if __name__ == "__main__": try: for i in range(100): dis = togikai_ultrasonic.Mesure(GPIO, time, 32, 31) #距離データを配列に記録 d = np.vstack([d, [time.time() - start_time, dis]]) print('{0:.2f}'.format(dis)) time.sleep(0.05) GPIO.cleanup() np.savetxt(filename, d, fmt='%.3e') print('average = ', np.mean(d[:, 1])) except KeyboardInterrupt: np.savetxt(filename, d, fmt='%.3e') print('stop!') GPIO.cleanup()
t_list = [15, 13, 35, 32, 36] GPIO.setup(t_list, GPIO.OUT, initial=GPIO.LOW) e_list = [26, 24, 37, 31, 38] GPIO.setup(e_list, GPIO.IN) #データ記録用配列作成 d = np.zeros(2) # print('Input test name') # test = input() # print('Input No.') # testno = input() # filename = '/home/pi/code/record_data/'+str(test)+str(testno)+'.csv' start_time = time.time() if __name__ == "__main__": try: for i in range(100): dis = togikai_ultrasonic.Mesure(GPIO, time, 36, 38) #距離データを配列に記録 d = np.vstack([d, [time.time() - start_time, dis]]) print('{0:.2f}'.format(dis)) time.sleep(0.1) GPIO.cleanup() # np.savetxt(filename, d, fmt='%.3e') print('average = ', np.mean(d[:, 1])) except KeyboardInterrupt: # np.savetxt(filename, d, fmt='%.3e') print('stop!') GPIO.cleanup()
togikai_drive.Steer(PWM_PARAM, pwm, time, 150 * direction) def back(): #direction 1Right -1left #Steer150 min radius 50cm #if FRdis >= CAR_MIN_R*1.05: togikai_drive.Accel(PWM_PARAM, pwm, time, -40) togikai_drive.Steer(PWM_PARAM, pwm, time, 0) #ここから走行用プログラム try: while True: #Frセンサ距離 FRdis = togikai_ultrasonic.Mesure(GPIO, time, 15, 26) #FrLHセンサ距離 LHdis = togikai_ultrasonic.Mesure(GPIO, time, 13, 24) # #FrRHセンサ距離 RHdis = togikai_ultrasonic.Mesure(GPIO, time, 32, 31) #togikai_drive.Accel(PWM_PARAM,pwm,time,40) #togikai_drive.Steer(PWM_PARAM,pwm,time,0) in_key = input() if in_key == 'k': turn90(FRdis, -1) elif in_key == 'l': turn90(FRdis, 1) elif in_key == ',': back()
t_list = [15, 13, 35, 32, 36] GPIO.setup(t_list, GPIO.OUT, initial=GPIO.LOW) e_list = [26, 24, 37, 31, 38] GPIO.setup(e_list, GPIO.IN) #データ記録用配列作成 d = np.zeros(2) # print('Input test name') # test = input() # print('Input No.') # testno = input() # filename = '/home/pi/code/record_data/'+str(test)+str(testno)+'.csv' start_time = time.time() if __name__ == "__main__": try: for i in range(100): dis = togikai_ultrasonic.Mesure(GPIO, time, 15, 26) #距離データを配列に記録 d = np.vstack([d, [time.time() - start_time, dis]]) print('{0:.2f}'.format(dis)) time.sleep(0.1) GPIO.cleanup() # np.savetxt(filename, d, fmt='%.3e') print('average = ', np.mean(d[:, 1])) except KeyboardInterrupt: # np.savetxt(filename, d, fmt='%.3e') print('stop!') GPIO.cleanup()
t_list=[15,13,35,32,36] GPIO.setup(t_list,GPIO.OUT,initial=GPIO.LOW) e_list=[26,24,37,31,38] GPIO.setup(e_list,GPIO.IN) #データ記録用配列作成 d = np.zeros(2) print('Input test name') test = input() print('Input No.') testno = input() filename = '/home/pi/code/record_data/'+str(test)+str(testno)+'.csv' start_time = time.time() if __name__ == "__main__": try: for i in range(100): dis = togikai_ultrasonic.Mesure(GPIO,time,13,24) #距離データを配列に記録 d = np.vstack([d,[time.time()-start_time, dis]]) print('{0:.2f}'.format(dis)) time.sleep(0.05) GPIO.cleanup() np.savetxt(filename, d, fmt='%.3e') print('average = ', np.mean(d[:,1])) except KeyboardInterrupt: np.savetxt(filename, d, fmt='%.3e') print('stop!') GPIO.cleanup()