From 5fa2bb7fca710962283e6790d5a1c2022336aedd Mon Sep 17 00:00:00 2001 From: Trivernis Date: Mon, 3 Dec 2018 16:50:28 +0100 Subject: [PATCH] Post-Merge Cleanup --- lib/controllib.py | 2 +- lib/graphiclib.py | 5 +++-- lib/gyro.py | 2 +- lib/hardwarelib.py | 4 ++-- lib/ultrasonic.py | 6 ++++-- testscripts/motor_test.py | 4 ++-- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/controllib.py b/lib/controllib.py index cc88d4d..650f663 100644 --- a/lib/controllib.py +++ b/lib/controllib.py @@ -2,7 +2,7 @@ import os import pygame -class Joystick(): +class Joystick: def __init__(self, navigator, light, configuration, camera): # joystick pygame.joystick.init() diff --git a/lib/graphiclib.py b/lib/graphiclib.py index 5a2bf80..228324a 100644 --- a/lib/graphiclib.py +++ b/lib/graphiclib.py @@ -1,6 +1,7 @@ -import pygame, pygame.camera import picamera import picamera.array +import pygame +import pygame.camera from pygame import * @@ -13,6 +14,7 @@ class Screen: """The Screen for the Terminal""" def __init__(self, size=(100, 100), title="Screen"): + self.fullscreen = True pygame.display.init() self.size = size self.screen = pygame.display.set_mode(self.size) @@ -29,7 +31,6 @@ class Screen: displayinfo = pygame.display.Info() fullsize = (displayinfo.current_w, displayinfo.current_h) pygame.display.set_mode(fullsize, FULLSCREEN | DOUBLEBUF) - self.fullscreen = True class List(pygame.sprite.Sprite): diff --git a/lib/gyro.py b/lib/gyro.py index 460b6aa..779731e 100644 --- a/lib/gyro.py +++ b/lib/gyro.py @@ -24,7 +24,7 @@ def read_word(reg): def read_word_2c(reg): val = read_word(reg) - if (val >= 0x8000): + if val >= 0x8000: return -((65535 - val) + 1) else: return val diff --git a/lib/hardwarelib.py b/lib/hardwarelib.py index f836b20..5a20ca8 100644 --- a/lib/hardwarelib.py +++ b/lib/hardwarelib.py @@ -4,7 +4,7 @@ import RPi.GPIO as GPIO import time -class Navigator(): +class Navigator: """Forward Motor with relais, Steering with servo""" def __init__(self, mrelaispin): @@ -66,7 +66,7 @@ class Ultrasonic: self.distance = 0 def get_distance(self): - if (time.time()-self.time)>1: + if (time.time() - self.time) > 1: self.distance = self.sensor.echo() self.time = time.time() return self.distance diff --git a/lib/ultrasonic.py b/lib/ultrasonic.py index c8836dc..d648352 100644 --- a/lib/ultrasonic.py +++ b/lib/ultrasonic.py @@ -5,10 +5,13 @@ GPIO.setmode(GPIO.BOARD) class Sensor(object): - def init(self, TRIG, ECHO): + def __init__(self): self.TRIGGER = TRIG self.ECHO = ECHO self.lastValues = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + self.lastValues = self.lastValues[1:] + + def init(self, TRIG, ECHO): GPIO.setup(self.TRIGGER, GPIO.OUT) GPIO.setup(self.ECHO, GPIO.IN) GPIO.output(self.TRIGGER, False) @@ -36,7 +39,6 @@ class Sensor(object): distance = pulse_duration * 17150 distance = round(distance, 2) self.lastValues.append(distance) - self.lastValues = self.lastValues[1:] distance = round((sum(self.lastValues)) / (len(self.lastValues)), 2) # print(self.lastValues) # print("Distance: {}".format(distance)) diff --git a/testscripts/motor_test.py b/testscripts/motor_test.py index 1e10205..e3d7fd3 100644 --- a/testscripts/motor_test.py +++ b/testscripts/motor_test.py @@ -129,10 +129,10 @@ if __name__ == '__main__': while True: try: start = time.time() - while (time.time() < start + 10): + while time.time() < start + 10: forward(pins) start = time.time() - while (time.time() < start + 10): + while time.time() < start + 10: backward(pins) except KeyboardInterrupt: break