35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import compLib.CompLib_pb2 as CompLib_pb2
|
|
from compLib.CompLibClient import CompLibClient
|
|
|
|
|
|
class Encoder(object):
|
|
"""Class used to read the encoders
|
|
"""
|
|
|
|
@staticmethod
|
|
def read_all_positions():
|
|
"""Read all encoder positions.
|
|
|
|
:return: Tuple of all current encoder positions
|
|
"""
|
|
request = CompLib_pb2.EncoderReadPositionsRequest()
|
|
request.header.message_type = request.DESCRIPTOR.full_name
|
|
|
|
response = CompLib_pb2.EncoderReadPositionsResponse()
|
|
response.ParseFromString(CompLibClient.send(request.SerializeToString(), request.ByteSize()))
|
|
|
|
return tuple(i for i in response.positions)
|
|
|
|
@staticmethod
|
|
def read_all_velocities():
|
|
"""Read the velocity of all motors connected.
|
|
|
|
:return: Tuple of all current motor velocities
|
|
"""
|
|
request = CompLib_pb2.EncoderReadVelocitiesRequest()
|
|
request.header.message_type = request.DESCRIPTOR.full_name
|
|
|
|
response = CompLib_pb2.EncoderReadVelocitiesResponse()
|
|
response.ParseFromString(CompLibClient.send(request.SerializeToString(), request.ByteSize()))
|
|
|
|
return tuple(i for i in response.velocities)
|