camera is off by one with elevation above 0

This commit is contained in:
j 2018-12-04 14:55:00 +01:00
parent 66174deb98
commit 46b59ff91a
3 changed files with 39 additions and 14 deletions

View File

@ -66,6 +66,12 @@ def etree_to_dict(t):
d['text'] = t.text
return d
def is_close_enough(a, b):
return abs(a['elevation'] - b['elevation']) < 2 \
and abs(a['absoluteZoom'] - b['absoluteZoom']) < 2 \
and abs(a['azimuth'] - b['azimuth']) < 2
class Camera:
STOP = {'pan': 0, 'tilt': 0, 'zoom': 0}
LEFT = {'pan': -1, 'tilt': 0, 'zoom': 0}
@ -144,9 +150,10 @@ class Camera:
for preset in presets:
self.absolute(**preset['position'])
time.sleep(5)
self.absolute(**preset['position'])
time.sleep(5)
self.goto(**preset['position'])
self.set_preset(preset['id'], preset['name'])
time.sleep(1)
print('presets loaded')
def sequence(self, steps=[], speed=12, goto_first=True):
self.sequence_start = 0
@ -183,10 +190,10 @@ class Camera:
if 'zoom_last' in step:
kwargs['zoom_last'] = step['zoom_last']
self.goto_preset(step['preset'], **kwargs)
if 'sleep' in step:
if self.abort:
return
time.sleep(float(step['sleep']))
if 'sleep' in step:
if self.abort:
return
time.sleep(float(step['sleep']))
else:
self.goto_preset(step, pan=speed, tilt=speed)
@ -202,11 +209,6 @@ class Camera:
preset = self.get_preset(id)['position']
last = self.status()
def is_close_enough(a, b):
return abs(a['elevation'] - b['elevation']) < 2 \
and abs(a['absoluteZoom'] - b['absoluteZoom']) < 2 \
and abs(a['azimuth'] - b['azimuth']) < 2
while not is_close_enough(last, preset):
time.sleep(0.1)
last = self.status()
@ -228,6 +230,9 @@ class Camera:
i = preset['position']
#info = etree_to_dict(xml.etree.ElementTree.fromstring(self.get('presets/%s' % id)))
#i = info['PTZPreset']['AbsoluteHigh']
if i['elevation'] < 0:
i['elevation'] -= 1
i['azimuth'] += 1
print('goto preset', id, i['elevation'], i['azimuth'], i['absoluteZoom'])
return self.goto(i['elevation'], i['azimuth'], i['absoluteZoom'], pan=pan, tilt=tilt, zoom=zoom, zoom_last=zoom_last)
@ -350,7 +355,6 @@ class Camera:
'absoluteZoom': absoluteZoom
}
}
print('!!', cmd)
r = self.put('absolute', cmd)
if '<statusCode>1</statusCode>' not in r:
print(r)

12
server.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/python3
from functools import wraps
from urllib.parse import unquote
import json
@ -25,6 +26,7 @@ logger = logging.getLogger(__name__)
STATIC_PATH = 'static'
PORT = 8000
ADDRESS = '127.0.0.1'
ADDRESS = '0.0.0.0'
with open('camera.json') as fd:
CAMERA = json.load(fd)
@ -75,6 +77,8 @@ class ControlQueue:
self._worker.start()
def put(self, filename):
if self.q.empty():
self.camera.abort = False
self.q.put(filename)
def join(self):
@ -97,6 +101,12 @@ class API(object):
result['presets'] = ctl.camera.get_presets(True)
return result
def setPresets(self, **data):
result = {}
ctl.camera.set_presets(data['presets'])
result['presets'] = ctl.camera.get_presets(True)
return result
def camera(self, **data):
result = {}
for key, value in data.items():
@ -106,6 +116,8 @@ class API(object):
def run(self, **data):
result = {}
ctl.put(data)
with open('last_run.json', 'w') as fd:
json.dump(data, fd, indent=4)
return result
def stop(self, **data):

View File

@ -480,7 +480,7 @@ $('button.all_presets').on({click: function() {
loadData(presets.map(function(preset) {
return {
preset: preset.id,
speed: 20
speed: parseInt($('input.default_speed').val(), 10)
}
}))
}})
@ -494,5 +494,14 @@ $('input.import_sequence').on({change: function() {
reader.readAsText(this.files[0]);
}})
$('input.import_presets').on({change: function() {
console.log('import', this)
var reader = new FileReader()
reader.onload = function(event) {
var data = JSON.parse(reader.result)
api('setPresets', {
'presets': presets
}, function(response) {
presets = response.result.presets
})
}
reader.readAsText(this.files[0]);
}})