Skip to content

Commit

Permalink
Merge pull request #14 from IQTLabs/mono
Browse files Browse the repository at this point in the history
Mono

Former-commit-id: 9b4d59b
  • Loading branch information
luke-iqt committed Apr 19, 2021
2 parents 848ef9b + 813161a commit 3c4a439
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 71 deletions.
284 changes: 284 additions & 0 deletions Config.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# SkyScan Config\n",
"Make temporary changes to a running SkyScan instance. It will revert back to the values in the environment file when restart."
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"broker=\"192.168.1.47\" # update with the IP for the Raspberry PI"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: paho-mqtt in /Users/lberndt/opt/anaconda3/lib/python3.8/site-packages (1.5.0)\r\n"
]
}
],
"source": [
"!pip install paho-mqtt"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"import paho.mqtt.client as mqtt\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"client = mqtt.Client(\"notebook-config\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Camera Zoom\n",
"This is how much the camera is zoomed in. It is an Int number between 0-9999 (max)"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<paho.mqtt.client.MQTTMessageInfo at 0x7f8d01045a90>"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraZoom'] = 9999 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Camera Delay\n",
"Float value for the number of seconds to wait after sending the camera move API command, before sending the take picture API command."
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<paho.mqtt.client.MQTTMessageInfo at 0x7f8d0104a270>"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraDelay'] = 0.25 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Camera Move Speed\n",
"This is how fast the camea will move. It is an Int number between 0-99 (max)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<paho.mqtt.client.MQTTMessageInfo at 0x7f8d0104a220>"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraMoveSpeed'] = 99 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Camera Lead\n",
"This is how far the tracker should move the center point in front of the currently tracked plane. It is a float, and is measured in seconds, example: 0.25 . It is based on the planes current heading and how fast it is going. "
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<paho.mqtt.client.MQTTMessageInfo at 0x7f8d01054680>"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraLead'] = 0.45 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Camera Bearing\n",
"This is a float to correct the cameras heading to help it better align with True North. It can be from -180 to 180. "
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<paho.mqtt.client.MQTTMessageInfo at 0x7f8d01048a90>"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraBearing'] = -2 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Minimum Elevation\n",
"The minimum elevation above the horizon which the Tracker will follow an airplane. Int value between 0-90 degrees."
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<paho.mqtt.client.MQTTMessageInfo at 0x7f8d01052ef0>"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['minElevation'] = 45 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
42 changes: 34 additions & 8 deletions axis-ptz/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
cameraZoom = None
cameraMoveSpeed = None
cameraDelay = None
cameraBearing = 0
object_topic = None
flight_topic = None
config_topic = "skyscan/config/json"
pan = 0
tilt = 0
actualPan = 0
Expand Down Expand Up @@ -75,14 +77,13 @@ def setXY(x,y):

def setPan(bearing):
global pan
camera_bearing = args.bearing
diff_heading = getHeadingDiff(bearing, camera_bearing)
#diff_heading = getHeadingDiff(bearing, cameraBearing)


if pan != bearing: #abs(pan - diff_heading) > 2: #only update the pan if there has been a big change
#logging.info("Heading Diff %d for Bearing %d & Camera Bearing: %d"% (diff_heading, bearing, camera_bearing))
if pan != bearing: #bearing #abs(pan - diff_heading) > 2: #only update the pan if there has been a big change
#logging.info("Heading Diff %d for Bearing %d & Camera Bearing: %d"% (diff_heading, bearing, cameraBearing))

pan = bearing #diff_heading
pan = bearing
#logging.info("Setting Pan to: %d"%pan)

return True
Expand Down Expand Up @@ -124,7 +125,7 @@ def get_jpeg_request(): # 5.2.4.1
"""
payload = {
'resolution': "1920x1080",
'compression': 5,
'compression': 0,
'camera': 1,
}
url = 'http:https://' + args.axis_ip + '/axis-cgi/jpg/image.cgi'
Expand Down Expand Up @@ -233,6 +234,25 @@ def moveCamera():
# Sleep for a bit so we're not hammering the camera withupdates
time.sleep(0.005)


def update_config(config):
global cameraZoom
global cameraMoveSpeed
global cameraDelay
global cameraBearing

if "cameraZoom" in config:
cameraZoom = int(config["cameraZoom"])
logging.info("Setting Camera Zoom to: {}".format(cameraZoom))
if "cameraDelay" in config:
cameraDelay = float(config["cameraDelay"])
logging.info("Setting Camera Delay to: {}".format(cameraDelay))
if "cameraMoveSpeed" in config:
cameraMoveSpeed = int(config["cameraMoveSpeed"])
logging.info("Setting Camera Move Speed to: {}".format(cameraMoveSpeed))
if "cameraBearing" in config:
cameraBearing = float(config["cameraBearing"])
logging.info("Setting Bearing Correction to: {}".format(cameraBearing))
#############################################
## MQTT Callback Function ##
#############################################
Expand Down Expand Up @@ -265,6 +285,9 @@ def on_message(client, userdata, message):
bearingGood = setPan(update["bearing"])
setTilt(update["elevation"])
currentPlane = update
elif message.topic == config_topic:
update_config(update)
logging.info("Config Message: {}".format(update))
else:
logging.info("Message: {} Object: {} Flight: {}".format(message.topic, object_topic, flight_topic))

Expand All @@ -277,6 +300,7 @@ def main():
global cameraDelay
global cameraMoveSpeed
global cameraZoom
global cameraBearing
global cameraConfig
global flight_topic
global object_topic
Expand Down Expand Up @@ -319,6 +343,7 @@ def main():
cameraDelay = args.camera_delay
cameraMoveSpeed = args.camera_move_speed
cameraZoom = args.camera_zoom
cameraBearing = args.bearing
cameraConfig = vapix_config.CameraConfiguration(args.axis_ip, args.axis_username, args.axis_password)

threading.Thread(target = moveCamera, daemon = True).start()
Expand All @@ -333,8 +358,9 @@ def main():

client.connect(args.mqtt_host) #connect to broker
client.loop_start() #start the loop
client.subscribe(flight_topic+"/#")
client.subscribe(object_topic+"/#")
client.subscribe(flight_topic)
client.subscribe(object_topic)
client.subscribe(config_topic)
client.publish("skyscan/registration", "skyscan-axis-ptz-camera-"+ID+" Registration", 0, False)

#############################################
Expand Down
Loading

0 comments on commit 3c4a439

Please sign in to comment.