Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
Started development
Browse files Browse the repository at this point in the history
  • Loading branch information
cgokmen committed Mar 26, 2017
1 parent 7231293 commit 00efeec
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:2.7
MAINTAINER Cem Gokmen <[email protected]>

COPY app /app
WORKDIR /app

RUN install_git.sh
RUN install_rtimulib.sh
RUN pip install -r requirements.txt

VOLUME /data
EXPOSE 9000

CMD twistd -n -l - -y nobelgt.tac
5 changes: 5 additions & 0 deletions install_git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -ex #Fail if any line fails, print everything

apt-get update
apt-get install git
12 changes: 12 additions & 0 deletions install_rtimulib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -ex #Fail if any line fails, print everything

apt-get update
apt-get install python-dev

cd /tmp
git clone https://github.com/VIP-LES/RTIMULib2.git

cd RTIMULib2/Linux/python
python setup.py build
python setup.py install
51 changes: 51 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from sensormodules import IMUModule, GeigerCounterModule
import logging
import signal
import csv


class GracefulKiller:
kill_now = False

def __init__(self):
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)

def exit_gracefully(self, signum, frame):
self.kill_now = True


if __name__ == '__main__':
killer = GracefulKiller()
modules = {}
csvs = {}

logger = logging.getLogger("verne")

modules['imu'] = IMUModule(logger.getChild("imu"))
modules['geiger'] = GeigerCounterModule(logger.getChild("geiger"), "/dev/geigerCounter", 9600)

for m in modules.keys():
f = open('%s.csv' % m, 'wb')
writer = csv.writer(f, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)

csvs[m] = (f, writer)

while True:
for m in modules.keys():
data = modules[m].poll()

if len(data) > 0:
currentTime = None # Todo: get the time here.
writer = csvs[m][0]

for datum in data:
writer.writerow([currentTime] + list(datum))

if killer.kill_now:
break

for c in csvs.values():
c[1].close()

print("Goodbye!")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyserial==3.3
21 changes: 21 additions & 0 deletions sensormodules/GeigerCounterModule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from . import SensorModule
from . import SerialModule


class GeigerCounterModule(SensorModule):
def __init__(self, logger, device, baudRate):
self.sm = SerialModule(logger, device, baudRate)
self.logger = logger

def poll(self):
# The geiger counter's number of ticks is equal to the number of
# characters on the serial output.

data = self.sm.poll()

retval = []

for _ in xrange(data):
retval.append(True)

return retval
45 changes: 45 additions & 0 deletions sensormodules/IMUModule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys

import RTIMU
import os.path
import time
import math

from . import SensorModule

class IMUModule(SensorModule):
SETTINGS_FILE = "RTIMULib"

def __init__(self, logger):
sys.path.append('.')

logger.info("Using settings file " + IMUModule.SETTINGS_FILE + ".ini")
if not os.path.exists(IMUModule.SETTINGS_FILE + ".ini"):
logger.warning("Settings file does not exist, will be created")

s = RTIMU.Settings(IMUModule.SETTINGS_FILE)
imu = RTIMU.RTIMU(s)

logger.info("IMU Name: " + imu.IMUName())

if not imu.IMUInit():
raise ValueError("IMU Init Failed")

imu.setSlerpPower(0.02)
imu.setGyroEnable(True)
imu.setAccelEnable(True)
imu.setCompassEnable(True)

self.imu = imu
self.poll_interval = imu.IMUGetPollInterval()
self.logger = logger

def poll(self):
if self.imu.IMURead():
# x, y, z = imu.getFusionData()
# print("%f %f %f" % (x,y,z))
data = self.imu.getIMUData()
fusionPose = data["fusionPose"]
processedData = [(math.degrees(fusionPose[0]), math.degrees(fusionPose[1]), math.degrees(fusionPose[2]))]

return processedData
12 changes: 12 additions & 0 deletions sensormodules/SensorModule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import abc

class SensorModule:
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def poll(self):
"""
This is our module's polling method which will be called from the main event loop.
This method should not block under any circumstances.
"""
return
15 changes: 15 additions & 0 deletions sensormodules/SerialModule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from . import SensorModule
import serial

class SerialModule(SensorModule):
def __init__(self, logger, device, baudRate):
self.sd = serial.Serial(device, baudRate, timeout=None)

self.logger = logger

def poll(self):
# It's important to realize that this method may produce incomplete data if called
# in the middle of a line and it's up to the main loop to handle that.
if self.sd.in_waiting > 0:
data = self.sd.read(self.sd.in_waiting)
return [data]
4 changes: 4 additions & 0 deletions sensormodules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from SensorModule import SensorModule
from SerialModule import SerialModule
from GeigerCounterModule import GeigerCounterModule
from IMUModule import IMUModule

0 comments on commit 00efeec

Please sign in to comment.