Refactor all and add some tests for the calculations

This commit is contained in:
2026-01-15 16:12:08 +01:00
parent cc3371b73b
commit 2d067013b4
11 changed files with 161 additions and 102 deletions

View File

@@ -5,24 +5,17 @@ from objects.board import Board
class Motor:
"""Model a type of servo motor."""
# Default vaules for every motor
MAX_PULSE = 2500
MIN_PULSE = 500
COVERAGE = 180 # Total degree of freedom in degrees
OFFSET = 0 # In degrees a constant to be added
SCALE = 1 # Scaling
# Used for ids
count = 0
def __init__(self, board: Board, angle=0):
self.board: Board = board
self.id: int = Motor.count
Motor.count += 1
self.id: int = Board.count
Board.count += 1
self.angle = angle
self.offset = Motor.OFFSET # Fine grained controls over every motor
self.coverage = Motor.COVERAGE
self.coverage = Board.COVER
self.scale = Motor.SCALE
# Initialization
@@ -41,5 +34,5 @@ class Motor:
def inc(self, inc):
self.angle += inc
self.angle = min(max(self.angle, 0), Motor.COVERAGE) # Clip
self.angle = min(max(self.angle, 0), Board.COVER) # Clip
self.set()