This repository has been archived by the owner on Sep 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pyserial==3.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |