Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import pigpio
  2. import time
  3. from picamera import PiCamera
  4.  
  5. steeringInputPulseStart = 0
  6. steeringInputDuration = -1
  7.  
  8. throttleInputPulseStart = 0
  9. throttleInputDuration = -1
  10.  
  11. def cbSteering(gpio, level, tick):
  12.     global steeringInputPulseStart
  13.     global steeringInputDuration
  14.     if level:
  15.         steeringInputPulseStart = tick
  16.     else:
  17.         steeringInputDuration = pigpio.tickDiff(steeringInputPulseStart,tick)
  18.         if steeringInputDuration==0 or 500<steeringInputDuration<2500:
  19.             pi.set_servo_pulsewidth(17,steeringInputDuration)
  20.  
  21. def cbThrottle(gpio, level, tick):
  22.     global throttleInputPulseStart
  23.     global throttleInputDuration
  24.     if level:
  25.         throttleInputPulseStart = tick
  26.     else:
  27.         throttleInputDuration = pigpio.tickDiff(steeringInputPulseStart,tick)
  28.         if throttleInputDuration==0 or 500<throttleInputDuration<2500:
  29.             pi.set_servo_pulsewidth(27,throttleInputDuration)
  30.        
  31. pi = pigpio.pi()
  32. steeringInput = pi.callback(4, pigpio.EITHER_EDGE, cbSteering)
  33. throttleInput = pi.callback(14, pigpio.EITHER_EDGE, cbThrottle)
  34.  
  35. camera = PiCamera(resolution='32x32')
  36.  
  37. i = 0
  38. initialTick = pi.get_current_tick()
  39. while i<100:
  40.     i+=1
  41.     currentTick = pi.get_current_tick()
  42.     # comment this out
  43.     currentTick = 1
  44.     fileName = '/home/pi/Desktop/image_' + str(currentTick) + '.yuv'
  45.     camera.capture(fileName, 'yuv', use_video_port=True)
  46.  
  47. # Cancel the input callbacks
  48. steeringInput.cancel()
  49. throttleInput.cancel()
  50.  
  51. print(str(pigpio.tickDiff(initialTick,pi.get_current_tick())/1000000.0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement