Add IR, encoder, motor, display

This commit is contained in:
Konstantin Lampalzer 2021-08-22 18:37:20 +02:00
parent 530ddd8be7
commit 63b8f868c9
6 changed files with 248 additions and 247 deletions

37
compLib/Encoder.py Normal file
View file

@ -0,0 +1,37 @@
import atexit
from enum import Enum
from compLib.LogstashLogging import Logging
from compLib.Spi import Spi, Register
MOTOR_COUNT = 4
class Encoder(object):
"""Class used to read the encoders
"""
@staticmethod
def read(port: int) -> int:
"""Read encoder from a specified port
:param port: Port, which the motor is connected to. 1-4 allowed
:raises: IndexError
:return: Current encoder position
"""
if port <= 0 or port > MOTOR_COUNT:
raise IndexError("Invalid encoder port specified!")
if port == 1:
return Spi.read(Register.MOTOR_1_POS_B3, 4)
elif port == 2:
return Spi.read(Register.MOTOR_2_POS_B3, 4)
elif port == 3:
return Spi.read(Register.MOTOR_3_POS_B3, 4)
elif port == 4:
return Spi.read(Register.MOTOR_4_POS_B3, 4)
@staticmethod
def reset(port: int):
# TODO implement registers and me
pass