Skip to content
Snippets Groups Projects
Commit 03b45091 authored by Chair on Fire's avatar Chair on Fire
Browse files

Convert speed to byte variable.

parent 82f56e8a
No related branches found
No related tags found
1 merge request!1Added SAVED integration.
......@@ -124,23 +124,31 @@ class Control(object):
sys.stdout.flush()
def accelerationToByte(self, a):
a /= self.accG # convert back to g-force
a *= 16384.0 # convert back to raw 16-bit word
a /= self.accG # convert back to g-force
a *= 16384.0 # convert back to raw 16-bit word
a += (2**15) # shift value to nonnegative range
a = int(a / (2**8)) # truncate to byte
a = min(max(a, 0), 2**8-1) # enforce range
return a
def speedToByte(self, s):
s *= 25 # stretch to reasonable range
s = int(s) # truncate to byte
s = min(max(s, 0), 2**8-1) # enforce range
return s
def savedloop(self, human=False):
t = time.time()
while True:
self.refreshSensors()
a = self.accY.read(t)
s = self.hallSpeed.read(t)
d = 0.75 # TODO
b = max(0, min(254, int(254 * d)))
if human:
print 'accY = {v}'.format(v=self.accelerationToByte(a))
print 'duty = {d}'.format(d=b)
print 'accY = {v}'.format(v=self.accelerationToByte(a))
print 'speed = {s}'.format(s=self.speedToByte(s))
print 'duty = {d}'.format(d=b)
else:
dutycmd = array.array('B', [b])
self.logDuty(dutycmd)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment