37 lines
987 B
Python
37 lines
987 B
Python
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
|