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

12
server.py Normal file → Executable file
View File

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

View File

@ -480,7 +480,7 @@ $('button.all_presets').on({click: function() {
loadData(presets.map(function(preset) { loadData(presets.map(function(preset) {
return { return {
preset: preset.id, 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]); reader.readAsText(this.files[0]);
}}) }})
$('input.import_presets').on({change: function() { $('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]);
}}) }})