Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Egi testing #5

Merged
merged 15 commits into from
Feb 3, 2021
Prev Previous commit
Next Next commit
Update to include USB GPS
EGI container updated to include:
  - USB-GPS functionality using GPSD
  - Reports Lat, Long, Alt, Time every ~10 seconds
  - Update to Docker-Compose file to support
  - Update to Dockerfile to support

Known issues:
  - If USB GPS is unplugged, container must be restarted - it will not currently fail
  - Environment variables must be set for Lat, Long, Alt, Roll, Pitch, and Yaw.  Failure to do so will result in EGI container failure.
  • Loading branch information
mchadwick-iqt committed Feb 1, 2021
commit 357e4023736d5f9b77ed62a592ee6e7d483a89a5
11 changes: 3 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,9 @@ services:

egi:
build: ./egi
entrypoint: "/app/egi.py -m mqtt"
environment:
- LAT=${LAT}
- LONG=${LONG}
- ALT=${ALT}
- ROLL=${ROLL}
- PITCH=${PITCH}
- YAW=${YAW}
entrypoint: bash -c "gpsd ${GPS_SERIAL} -F /var/run/gpsd.sock && python3 gps_mqtt.py -m mqtt -l ${LAT} -L ${LONG} -a ${ALT} -r ${ROLL} -p ${PITCH} -y ${YAW}"
devices:
- /dev/ttyACM0
depends_on:
- mqtt
restart: unless-stopped
10 changes: 6 additions & 4 deletions egi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM debian

RUN apt update && \
apt install -y python3 python3-pip && \
pip3 install paho-mqtt coloredlogs
apt install -y python3 python3-pip gpsd-clients gpsd

RUN mkdir -p /app/
WORKDIR /app
ADD *.txt /app/
RUN pip3 install -r requirements.txt
ADD *.py /app/

#ENTRYPOINT python3 /tmp/egi.py
ENTRYPOINT sh -c "gpsd /dev/ttyACM0 -F /var/run/gpsd.sock && bash"

#docker run -d --restart unless-stopped --network=host -v /home/pi/:/tmp/ --name lamp docker-registry.iqt.org/mission-capabilities/rpi-stats-reporting/lamp-control
#docker run -it --device=/dev/ttyACM0 skyscan_egi
#python3 egi_mqtt.py -h
54 changes: 31 additions & 23 deletions egi/egi.py → egi/egi_mqtt.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

from gps import *
import paho.mqtt.client as mqtt #import the client1
import time
import random
Expand All @@ -17,43 +18,47 @@
'\033[0;36m%(filename)-18s%(lineno)3d\033[00m '
'%(message)s',
level_styles = styles)
logging.info("Initializing EGI")

#######################################################
## Initialize Variables ##
#######################################################
config = {}
config['Local'] = ["127.0.0.1", "skyscan/egi", "Local MQTT Bus"] # updated based on naming convention here: https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/
timeTrigger = 0
timeTrigger = time.mktime(time.gmtime()) + 10
timeHeartbeat = 0
ID = str(random.randint(1,100001))

LLA = [ os.environ['LAT'], os.environ['LONG'], os.environ['ALT'] ]
RPY = [ os.environ['ROLL'], os.environ['PITCH'], os.environ['YAW'] ]

state = {}
state['lat'] = LLA[0]
state['long'] = LLA[1]
state['alt'] = LLA[2]
state['roll'] = RPY[0]
state['pitch'] = RPY[1]
state['yaw'] = RPY[2]
state=json.dumps(state)
gpsd = gps(mode=WATCH_ENABLE|WATCH_NEWSTYLE)
LLA = [38.9510808,-77.3841834,130.1337]
RPY = [0,0,0]

parser = argparse.ArgumentParser(description='An MQTT based camera controller')

parser.add_argument('-m', '--mqtt-host', help="MQTT broker hostname", default='127.0.0.1')

parser.add_argument('-l', '--latitude', help="Latitude (decimal degrees)", default=LLA[0])
parser.add_argument('-L', '--longitude', help="Longitude (decimal degrees)", default=LLA[1])
parser.add_argument('-a', '--altitude', help="Altitude (meters)", default=LLA[2])
parser.add_argument('-r', '--roll', help="Roll Angle of Camera (degrees)", default=RPY[0])
parser.add_argument('-p', '--pitch', help="Pitch Angle of Camera (degrees)", default=RPY[1])
parser.add_argument('-y', '--yaw', help="Yaw Angle of Camera (degrees from True North)", default=RPY[2])
args = parser.parse_args()

state = {}
state['time'] = time.strftime("%Y-%m-%dT%H:%M:%SZ",time.gmtime())
state['lat'] = float(args.latitude)
state['long'] = float(args.longitude)
state['alt'] = float(args.altitude)
state['roll'] = float(args.roll)
state['pitch'] = float(args.pitch)
state['yaw'] = float(args.yaw)
logging.info("Initial State Array: " + str(state))


#######################################################
## Local MQTT Callback Function ##
#######################################################
def on_message_local(client, userdata, message):
payload = str(message.payload.decode("utf-8"))
logging.info('Message Received: ' + message.topic + ' | ' + payload)
#if message.topic == local_topic+"/OFF":
# logging.info("Turning Lamp OFF")

def on_disconnect(client, userdata, rc):
global Active
Expand All @@ -72,17 +77,20 @@ def on_disconnect(client, userdata, rc):
clientLocal.on_disconnect = on_disconnect
clientLocal.connect(broker_address) #connect to broker
clientLocal.loop_start() #start the loop
#clientLocal.subscribe(local_topic+"/#") #config/#")
clientLocal.publish("skyscan/registration","EGI-"+ID+" Registration")

#############################################
## Main Loop ##
#############################################
while Active:
#if timeHeartbeat < time.mktime(time.gmtime()):
# timeHeartbeat = time.mktime(time.gmtime()) + 10
# clientLocal.publish(local_topic+"Heartbeat","EGI-"+ID+" Heartbeat")
if timeTrigger < time.mktime(time.gmtime()):
timeTrigger = time.mktime(time.gmtime()) + 10
clientLocal.publish(local_topic,state)
time.sleep(0.1)
clientLocal.publish(local_topic,json.dumps(state))

report = gpsd.next() #
if report['class'] == 'TPV':
state['time'] = getattr(report,'time',time.strftime("%Y-%m-%dT%H:%M:%SZ",time.gmtime()))
state['lat'] = getattr(report,'lat',LLA[0])
state['long'] = getattr(report,'lon',LLA[1])
state['alt'] = getattr(report,'alt',LLA[2])
time.sleep(0.01)
3 changes: 3 additions & 0 deletions egi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
paho-mqtt==1.5.0
coloredlogs
gps
3 changes: 2 additions & 1 deletion env-example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ CAMERA_MOVE_SPEED=50 # The speed at which the Axis will move for Pan/Tilt
CAMERA_DELAY=0.5 # How many seconds after issuing a Pan/Tilt command should a picture be taken
CAMERA_ZOOM=9999 # The zoom setting for the camera (0-9999)
CAMERA_LEAD=0.25 # How many seconds ahead of a plane's predicted location should the camera be positioned
RTL_DEV=1 # The device ID for the RTL-SDR - set using the rtl_eeprom program
RTL_DEV=1 # The device ID for the RTL-SDR - set using the rtl_eeprom program
GPS_SERIAL=/dev/ttyACM0 # GPS module serial port