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

Commit

Permalink
Merge pull request #2 from VIP-LES/develop
Browse files Browse the repository at this point in the history
Fixed time recording method and added polling rate for IMU
  • Loading branch information
Skyman authored Mar 29, 2017
2 parents c191160 + 7621fee commit def4319
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
18 changes: 10 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import signal
import csv
import time


# TODO: Improve the time function!
millis = lambda: int(round(time.time() * 1000))
from datetime import datetime

class GracefulKiller:
kill_now = False
Expand All @@ -29,27 +26,32 @@ def exit_gracefully(self, signum, frame):
modules['imu'] = IMUModule(logger.getChild("imu"))
modules['geiger'] = GeigerCounterModule(logger.getChild("geiger"), "/dev/uart", 9600)

missionTime = datetime.now()

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

writer.writerow([missionTime])

csvs[m] = (f, writer)

while True:
missionElapsedTime = int((datetime.now() - missionTime).total_seconds() * 1000)

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

if len(data) > 0:
currentTime = millis()
writer = csvs[m][0]

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

if killer.kill_now:
break

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

print("Goodbye!")
print("The eagle has landed.")
8 changes: 4 additions & 4 deletions sensormodules/GeigerCounterModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ def __init__(self, logger, device, baudRate):
self.sm = SerialModule(logger, device, baudRate)
self.logger = logger

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

data = self.sm.poll()
data = self.sm.poll(dt)

retval = []

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

return retval
13 changes: 7 additions & 6 deletions sensormodules/IMUModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class IMUModule(SensorModule):
SETTINGS_FILE = "RTIMULib"
MILLISECOND_POLLING_INTERVAL = 500

def __init__(self, logger):
sys.path.append('.')
Expand All @@ -31,15 +32,15 @@ def __init__(self, logger):
imu.setCompassEnable(True)

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

def poll(self):
def poll(self, dt):
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]))]
self.data = [(math.degrees(fusionPose[0]), math.degrees(fusionPose[1]), math.degrees(fusionPose[2]))]

return processedData
if (self.data is not None) and (self.lastPoll is None or ((dt - self.lastPoll).total_seconds() * 1000 >= self.pollInterval)):
self.lastPoll = dt
return self.data
2 changes: 1 addition & 1 deletion sensormodules/SensorModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class SensorModule:
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def poll(self):
def poll(self, dt):
"""
This is our module's polling method which will be called from the main event loop.
This method should not block under any circumstances.
Expand Down
2 changes: 1 addition & 1 deletion sensormodules/SerialModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self, logger, device, baudRate):

self.logger = logger

def poll(self):
def poll(self, dt):
# 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:
Expand Down

0 comments on commit def4319

Please sign in to comment.