import math sensorW = 23.2 sensorH = 15.4 focal = 16.0 #sensorW = 36.0 #sensorH = 24.0 #focal = 90.0 hStart = 1000 hStop = 1860 vStart = 1200 vStop = 1900 hFov = 2.0*(math.atan((sensorW/2.0) / focal)) vFov = 2.0 *(math.atan((sensorH/2.0) / focal)) numRows = 1 print "H FOV: "+str(round(math.degrees(hFov), 2)) print "V FOV: "+str(round(math.degrees(vFov), 2)) print "" hOverlap = 25.0 vOverlap = 25.0 hRot = hFov * ( 1 - ( hOverlap / 100 ) ) vRot = vFov * ( 1 - ( vOverlap / 100 ) ) def scale(val, src, dst): """ Scale the given value from the scale of src to the scale of dst. """ return ((val - src[0]) / (src[1]-src[0])) * (dst[1]-dst[0]) + dst[0] def mapRange(value, srcRange, dstRange): srcMax = srcRange[1] - srcRange[0] dstMax = dstRange[1] - dstRange[0] adjValue = value - srcRange[0] return round((adjValue * dstMax / srcMax) + dstRange[0], 2) hStep = 360/math.degrees(hRot) #hStepPWM = round((hStart-hStop)/hStep) vStep = 120/math.degrees(vRot) #vStepPWM = round((vStop-vStart)/vStep) if vStep > 2.0: #calculate extra row: numRows = math.trunc(vStep)-1 numPhotos = math.trunc(hStep*vStep)+1 numColumns = math.trunc(hStep) #Do it print "Capturing "+str(numPhotos)+" photos in "+str(numRows)+" rows and "+str(numColumns)+" columns." print "" print "Capturing Zenith" print "servo.set_position(tilt, "+str(vStop)+")" print "" for r in reversed(range(1, numRows+1)): if r == (numRows): waitA = 2 else: waitA = 1 print "Capturing row: "+str(r) vStepPWM = mapRange(r*math.degrees(vRot), [0,120], [vStart, vStop]) print "servo.set_position(tilt, "+str(vStepPWM)+")" print "" print "sleep("+str(waitA)+")" for c in range(1, numColumns+1): print "hrot: "+str(c*math.degrees(hRot)) if c == numColumns: hStepPWM = hStop waitB = 2 elif c == 1: hStepPWM = hStart waitB = 2 else: hStepPWM = math.trunc(mapRange((c*math.degrees(hRot)), [hRot,360], [hStart, hStop])) waitB = 1 print "c:"+str(c)+" r:"+str(r) print "Capturing image "+str(c)+" of row: "+str(r) print "servo.set_position(pan, "+str(hStepPWM)+")" print "" print "sleep("+str(waitB)+")"
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