Skip to content

Commit

Permalink
Merge pull request IQTLabs#42 from mchadwick-iqt/main
Browse files Browse the repository at this point in the history
Add In Position and Orientation Configs
  • Loading branch information
mchadwick-iqt authored Feb 9, 2023
2 parents 53d41bf + c1a8d7a commit 73a4429
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 34 deletions.
56 changes: 47 additions & 9 deletions axis-ptz/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
angularVelocityVertical = 0 # in meters
planeTrack = 0 # This is the direction that the plane is moving in

camera_roll = 0
camera_pitch = 0
camera_yaw = 0

currentPlane = None

camera_latitude = None
Expand Down Expand Up @@ -528,16 +532,15 @@ def moveCamera(ip, username, password):
E_XYZ_to_ENz, e_E_XYZ, e_N_XYZ, e_z_XYZ = utils.compute_E(t_lambda, t_varphi)
r_XYZ_t = utils.compute_r_XYZ(t_lambda, t_varphi, t_h)

# Compute the rotations from the XYZ coordinate system to the uvw
# (camera housing fixed) coordinate system
alpha = 0.0 # [deg]
beta = 0.0 # [deg]
gamma = 0.0 # [deg]
q_alpha, q_beta, q_gamma, E_XYZ_to_uvw, _, _, _ = compute_rotations(
e_E_XYZ, e_N_XYZ, e_z_XYZ, alpha, beta, gamma, 0.0, 0.0
)

while True:
# Compute the rotations from the XYZ coordinate system to the uvw
# (camera housing fixed) coordinate system
alpha = camera_yaw # [deg]
beta = camera_pitch # [deg]
gamma = camera_roll # [deg]
q_alpha, q_beta, q_gamma, E_XYZ_to_uvw, _, _, _ = compute_rotations(
e_E_XYZ, e_N_XYZ, e_z_XYZ, alpha, beta, gamma, 0.0, 0.0
)
if active:
if not "icao24" in currentPlane:
logging.info(" 🚨 Active but Current Plane is not set")
Expand Down Expand Up @@ -596,10 +599,15 @@ def update_config(config):
global cameraDelay
global cameraPan
global camera_lead
global camera_longitude
global camera_latitude
global camera_altitude
global cameraBearingCorrection
global inhibitPhotos
global capturePeriod
global camera_roll
global camera_pitch
global camera_yaw

if "cameraZoom" in config:
cameraZoom = int(config["cameraZoom"])
Expand All @@ -616,6 +624,12 @@ def update_config(config):
if "cameraAltitude" in config:
camera_altitude = float(config["cameraAltitude"])
logging.info("Setting Camera Altitude to: {}".format(camera_altitude))
if "cameraLatitude" in config:
camera_latitude = float(config["cameraLatitude"])
logging.info("Setting Camera Latitude to: {}".format(camera_latitude))
if "cameraLongitude" in config:
camera_longitude = float(config["cameraLongitude"])
logging.info("Setting Camera Longitude to: {}".format(camera_longitude))
if "cameraBearingCorrection" in config:
cameraBearingCorrection = float(config["cameraBearingCorrection"])
logging.info(
Expand All @@ -630,6 +644,15 @@ def update_config(config):
if "capturePeriod" in config:
capturePeriod = float(config["capturePeriod"])
logging.info("Setting Camera Capture Period (sec) to: {}".format(capturePeriod))
if "cameraRoll" in config:
camera_roll = float(config["cameraRoll"])
logging.info("Setting Camera Roll Angle to: {}".format(camera_roll))
if "cameraPitch" in config:
camera_pitch = float(config["cameraPitch"])
logging.info("Setting Camera Pitch Angle to: {}".format(camera_pitch))
if "cameraYaw" in config:
camera_yaw = float(config["cameraYaw"])
logging.info("Setting Camera Yaw Angle to: {}".format(camera_yaw))


#############################################
Expand All @@ -650,6 +673,9 @@ def on_message_impl(client, userdata, message):
global camera_longitude
global camera_latitude
global camera_altitude
global camera_roll
global camera_pitch
global camera_yaw

global active

Expand Down Expand Up @@ -704,6 +730,9 @@ def on_message_impl(client, userdata, message):
camera_longitude = float(update["long"])
camera_latitude = float(update["lat"])
camera_altitude = float(update["alt"])
camera_roll = float(update["roll"])
camera_pitch = float(update["pitch"])
camera_yaw = float(update["yaw"])
else:
logging.info(
"Message: {} Object: {} Flight: {}".format(
Expand All @@ -729,6 +758,9 @@ def main():
global camera_altitude
global camera_latitude
global camera_longitude
global camera_roll
global camera_pitch
global camera_yaw
global camera_lead
global cameraConfig
global flight_topic
Expand All @@ -738,6 +770,9 @@ def main():
parser = argparse.ArgumentParser(description="An MQTT based camera controller")
parser.add_argument("--lat", type=float, help="Latitude of camera")
parser.add_argument("--lon", type=float, help="Longitude of camera")
parser.add_argument("--roll", type=float, help="Roll angle of camera", default=0.0)
parser.add_argument("--pitch", type=float, help="Pitch angle of camera", default=0.0)
parser.add_argument("--yaw", type=float, help="Yaw angle of camera", default=0.0)
parser.add_argument(
"--alt", type=float, help="altitude of camera in METERS!", default=0
)
Expand Down Expand Up @@ -847,6 +882,9 @@ def main():
camera_longitude = args.lon
camera_latitude = args.lat
camera_altitude = args.alt # Altitude is in METERS
camera_roll = args.roll
camera_pitch = args.pitch
camera_yaw = args.yaw # Altitude is in METERS
camera_lead = args.camera_lead
# cameraConfig = vapix_config.CameraConfiguration(args.axis_ip, args.axis_username, args.axis_password)

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:

axis-ptz:
image: iqtlabs/skyscan-axis-ptz
command: "./camera.py -m mqtt -t skyscan/flight/json -u ${AXIS_USERNAME} -p ${AXIS_PASSWORD} -a ${AXIS_IP} -z ${CAMERA_ZOOM} -s ${CAMERA_MOVE_SPEED} -d ${CAMERA_DELAY} --lat ${LAT} --lon ${LONG} --alt ${ALT}"
command: "./camera.py -m mqtt -t skyscan/flight/json -u ${AXIS_USERNAME} -p ${AXIS_PASSWORD} -a ${AXIS_IP} -z ${CAMERA_ZOOM} -s ${CAMERA_MOVE_SPEED} -d ${CAMERA_DELAY} --lat ${LAT} --lon ${LONG} --alt ${ALT} --roll ${ROLL} --pitch ${PITCH} --yaw ${YAW}"
volumes:
- /flash/raw:/app/capture
depends_on:
Expand Down
228 changes: 204 additions & 24 deletions notebook-server/Config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,6 @@
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"source": [
"## Camera Altitude"
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraAltitude'] = -2 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -331,10 +311,11 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Time Between Saving Photosa\n",
"## Time Between Saving Photos\n",
"Sets the time between photo saves - IN MILLISECONDS. This is defaulted to 1000"
]
},
Expand All @@ -350,13 +331,212 @@
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set Roll Angle of Camera"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraRoll'] = 0 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set Pitch Angle of Camera"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraPitch'] = 0 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set Yaw Angle of Camera"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraYaw'] = 0 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set Latitude of Camera"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraLatitude'] = 38.890022390623265 # Latitude of the camera\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set Longitude of Camera"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraLongitude'] = -77.03513244930217 # Longitude of the camera\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set Altitude of Camera"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraAltitude'] = 170 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set Position of Camera"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraLatitude'] = 38.890022390623265 # Latitude of the camera\n",
"data['cameraLongitude'] = -77.03513244930217 # Longitude of the camera\n",
"data['cameraAltitude'] = 170 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set Orientation of Camera"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"data = {}\n",
"data['cameraYaw'] = 0 # Update this Value\n",
"data['cameraPitch'] = 0 # Update this Value\n",
"data['cameraRoll'] = 0 # Update this Value\n",
"json_data = json.dumps(data)\n",
"client.publish(\"skyscan/config/json\",json_data)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Send Example EGI Message"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"client.connect(broker)\n",
"state = {}\n",
"state['time'] = time.strftime(\"%Y-%m-%dT%H:%M:%SZ\",time.gmtime())\n",
"state['lat'] = 38.890022390623265\n",
"state['long'] = -77.03513244930217\n",
"state['alt'] = 170\n",
"state['roll'] = 0\n",
"state['pitch'] = 0\n",
"state['yaw'] = 0\n",
"state['fix'] = 0\n",
"json_data = json.dumps(state)\n",
"client.publish(\"skyscan/egi\",json_data)\n"
]
}

],
"metadata": {
"kernelspec": {
"name": "python385jvsc74a57bd064065cc917a2354f02e26dd1b65d7c93af3dc848180e46cdb05a49f40c8c24c8",
"display_name": "Python 3.8.5 64-bit ('tinyml': conda)"
"display_name": "Python 3.8.5 64-bit ('tinyml': conda)",
"name": "python385jvsc74a57bd064065cc917a2354f02e26dd1b65d7c93af3dc848180e46cdb05a49f40c8c24c8"
},
"language_info": {
"codemirror_mode": {
Expand Down

0 comments on commit 73a4429

Please sign in to comment.