import math from RPIO import PWM servo = PWM.Servo(0, 20000, 1) #PWM.set_loglevel(PWM.LOG_LEVEL_DEBUG) PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS) pan = 16 tilt = 20 cover = 21 sensorW = 23.2 sensorH = 15.4 focal = 16.0 minPan = 900 maxPan = 1860 minTilt = 1100 maxTilt = 1800 hFov = 2.0*(math.atan((sensorW/2.0) / focal)) vFov = 2.0 *(math.atan((sensorH/2.0) / focal)) hOverlap = 25.0 vOverlap = 25.0 hRot = hFov * ( 1 - ( hOverlap / 100 ) ) vRot = vFov * ( 1 - ( vOverlap / 100 ) ) hStep = 360/math.degrees(hRot) vStep = 120/math.degrees(vRot) if vStep > 2.0: #calculate extra row: rows = math.trunc(vStep)-1 else: rows = 1 numPhotos = math.trunc(hStep*vStep)+1 cols = math.ceil(hStep) print "cols: "+str(cols) panStep = round((maxPan-minPan)/cols, 1) tiltStep = round((maxTilt-minTilt)/rows, 1) def moveTilt(pos): if pos > maxTilt: servo.set_position(tilt, maxTilt) elif (pos < minTilt): servo.set_position(tilt, minTilt) else: servo.set_position(tilt, pos) def movePan(pos): if pos > maxPan: servo.set_position(pan, maxPan) elif (pos < minPan): servo.set_position(pan, minPan) else: servo.set_position(pan, pos) def step_range(start, end, step, rev=False): if rev == True: while end > start: yield math.trunc(end) end -= step else: while start < end: yield math.trunc(start) start += step def shootPano(): try: rev = False i = 1 for t in step_range(minTilt, maxTilt, tiltStep, False): moveTilt(t) if i%2==0: rev = True i += 1 x = 1 for p in step_range(minPan, maxPan, panStep, rev): movePan(p) print "Capturing image "+str(x)+" of row: "+str(i-1) x += 1 print "click" except: return False return True if shootPano() == True: print "All Done!" else: print "Error shooting Panorama!"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question