nrf5/examples: Fixing overlapping function names and variable names inside the object. Also removing some print statements. Tuning max angle from -7/7 to -25/25.

This commit is contained in:
Glenn Ruben Bakke 2017-05-15 21:20:52 +02:00 committed by glennrub
parent acce3a59d5
commit e6b49af27e

View File

@ -62,7 +62,6 @@ def find_device_by_name(name):
scan_res = s.scan(500) scan_res = s.scan(500)
device_names = get_device_names(scan_res) device_names = get_device_names(scan_res)
# print(device_names)
for dev in device_names: for dev in device_names:
if name == dev[1]: if name == dev[1]:
return dev[0] return dev[0]
@ -71,10 +70,10 @@ class PowerUp3:
def __init__(self): def __init__(self):
self.x_adc = ADC(1) self.x_adc = ADC(1)
self.button_speed_up = Pin("A13", mode=Pin.IN, pull=Pin.PULL_UP) self.btn_speed_up = Pin("A13", mode=Pin.IN, pull=Pin.PULL_UP)
self.button_speed_down = Pin("A15", mode=Pin.IN, pull=Pin.PULL_UP) self.btn_speed_down = Pin("A15", mode=Pin.IN, pull=Pin.PULL_UP)
self.button_speed_full = Pin("A14", mode=Pin.IN, pull=Pin.PULL_UP) self.btn_speed_full = Pin("A14", mode=Pin.IN, pull=Pin.PULL_UP)
self.button_speed_off = Pin("A16", mode=Pin.IN, pull=Pin.PULL_UP) self.btn_speed_off = Pin("A16", mode=Pin.IN, pull=Pin.PULL_UP)
self.x_mid = 0 self.x_mid = 0
@ -86,16 +85,16 @@ class PowerUp3:
return self.x_adc.value() return self.x_adc.value()
def button_speed_up(self): def button_speed_up(self):
return bool(self.button_speed_up.value()) return not bool(self.btn_speed_up.value())
def button_speed_down(self): def button_speed_down(self):
return bool(self.button_speed_down.value()) return not bool(self.btn_speed_down.value())
def button_speed_full(self): def button_speed_full(self):
return bool(self.button_speed_full.value()) return not bool(self.btn_speed_full.value())
def button_speed_off(self): def button_speed_off(self):
return bool(self.button_speed_off.value()) return not bool(self.btn_speed_off.value())
def calibrate(self): def calibrate(self):
self.x_mid = self.read_stick_x() self.x_mid = self.read_stick_x()
@ -135,7 +134,6 @@ class PowerUp3:
while not dev: while not dev:
dev = find_device_by_name("TailorToys PowerUp") dev = find_device_by_name("TailorToys PowerUp")
if dev: if dev:
# print(dev.addr())
self.p = Peripheral() self.p = Peripheral()
self.p.connect(dev.addr()) self.p.connect(dev.addr())
@ -149,7 +147,7 @@ class PowerUp3:
def rudder_left(self, angle): def rudder_left(self, angle):
steps = (angle // self.interval_size_left) steps = (angle // self.interval_size_left)
new_angle = 7 - steps new_angle = 25 - steps
if self.old_angle != new_angle: if self.old_angle != new_angle:
self.angle(new_angle) self.angle(new_angle)
@ -178,8 +176,8 @@ class PowerUp3:
right_threshold = self.x_mid + adc_threshold right_threshold = self.x_mid + adc_threshold
left_threshold = self.x_mid - adc_threshold left_threshold = self.x_mid - adc_threshold
self.interval_size_left = self.x_mid // 7 self.interval_size_left = self.x_mid // 25
self.interval_size_right = (255 - self.x_mid) // 7 self.interval_size_right = (255 - self.x_mid) // 25
self.old_angle = 0 self.old_angle = 0
self.old_speed = 0 self.old_speed = 0
@ -201,14 +199,13 @@ class PowerUp3:
# read out new speed # read out new speed
new_speed = self.old_speed new_speed = self.old_speed
# TODO: bool return not working correctly, so test negated for now. if self.button_speed_up():
if not self.button_speed_up():
new_speed += 25 new_speed += 25
elif not self.button_speed_down(): elif self.button_speed_down():
new_speed -= 25 new_speed -= 25
elif not self.button_speed_full(): elif self.button_speed_full():
new_speed = 100 new_speed = 100
elif not self.button_speed_off(): elif self.button_speed_off():
new_speed = 0 new_speed = 0
else: else:
pass pass