ラズベリーパイでカメラとLEDをほぼ同時に動作させようとしてるのですが、以下のプログラムから
wait_sec = 0.0002 until = perf_counter() + wait_sec while perf_counter()<until: pass
を除いたプログラムで時間差を測ったところ200μsほどずれてしまっています。
上記を挿入すればその時間差が縮まると思ったのですが結果は変わりませんでした。
200μsを気にするなと言われればそれまでなのですが、遅らせることでプログラムの動作を合わせるのは難しいのでしょうか?
python3.7
1import time 2import picamera 3import threading 4import RPi.GPIO as GPIO 5from time import perf_counter 6 7GPIO.setmode(GPIO.BOARD) 8GPIO.setup(11,GPIO.OUT) 9event = threading.Event() 10starttime = time.perf_counter_ns() 11 12def camera(): 13 global ctime 14 with picamera.PiCamera() as camera: 15 camera.resolution = (640,480) 16 event.wait() 17 cameratime = time.perf_counter_ns() 18 ctime = cameratime - starttime 19 print("CAM = {:}ns" .format(ctime)) 20 camera.capture('/home/pi/cameradata/image.jpg') 21 cameratime2 = time.perf_counter_ns() 22 ctime2 = cameratime2 - starttime 23 print("CAM2 = {:}ns" .format(ctime2)) 24 camera.stop_preview() 25 26def LED(): 27 global Ltime 28 time.sleep(1) 29 GPIO.output(11,GPIO.LOW) 30 event.set() 31 32 wait_sec = 0.0002 33 until = perf_counter() + wait_sec 34 while perf_counter()<until: 35 pass 36 37 38 GPIO.output(11,GPIO.HIGH) 39 LEDtime = time.perf_counter_ns() 40 Ltime = LEDtime - starttime 41 print("LED = {:}ns" .format(Ltime)) 42 time.sleep(0.01) 43 GPIO.output(11,GPIO.LOW) 44 time.sleep(0.1) 45 46 GPIO.cleanup() 47 48 49p1 = threading.Thread(target = camera) 50p2 = threading.Thread(target = LED) 51 52p1.start() 53p2.start() 54p1.join() 55p2.join() 56global ctimeLtime 57ctimeLtime = ctime - Ltime 58print("ctime-Ltime = {:}ns" .format(ctimeLtime)) 59 60
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/18 08:06
2019/01/18 08:12
2019/01/18 08:14
2019/01/18 08:18
2019/01/18 08:22
2019/01/18 08:33