def decode(data): """Decodes message data into alpha and beta moves.""" alpha_steps = bytes_to_int(data[0:4], dtype="i4") beta_steps = bytes_to_int(data[4:8], dtype="i4") return motor_steps_to_angle(alpha_steps, beta_steps)
def gotoPosition(posID, alphaDeg, betaDeg): alpha_steps, beta_steps = motor_steps_to_angle(alphaDeg, betaDeg, inverse=True) data = int_to_bytes(alpha_steps) + int_to_bytes(beta_steps) sendMsg(GO_TO_ABSOLUTE_POSITION, posID, data) arb, data = getReply() betaTime = bytes_to_int(data[4:]) alphaTime = bytes_to_int(data[0:4]) assert arb[0] == posID print("times to move", betaTime * 0.0005, alphaTime * 0.0005)
def encode(alpha, beta): """Returns the position as a bytearray in positioner units.""" alpha_motor, beta_motor = motor_steps_to_angle(alpha, beta, inverse=True) alpha_bytes = int_to_bytes(int(alpha_motor), "i4") beta_bytes = int_to_bytes(int(beta_motor), "i4") data = alpha_bytes + beta_bytes return data
def __init__( self, positioner_ids: int | List[int], alpha=None, beta=None, **kwargs, ): if alpha is not None and beta is not None: alpha_steps, beta_steps = motor_steps_to_angle(alpha, beta, inverse=True) data = int_to_bytes(int(alpha_steps)) + int_to_bytes(int(beta_steps)) kwargs["data"] = data super().__init__(positioner_ids, **kwargs)
def __init__( self, positioner_ids: int | List[int], alpha: float | None = None, beta: float | None = None, **kwargs, ): if alpha is not None and beta is not None: alpha_steps, beta_steps = motor_steps_to_angle(alpha, beta, inverse=True) alpha_bytes = int_to_bytes(alpha_steps, dtype="i4") beta_bytes = int_to_bytes(beta_steps, dtype="i4") data = alpha_bytes + beta_bytes kwargs["data"] = data super().__init__(positioner_ids, **kwargs)
def get_positions(self) -> Dict[int, Tuple[float, float]]: """Returns the positions of alpha and beta in degrees. Raises ------ ValueError If no reply has been received or the data cannot be parsed. """ positions = {} for reply in self.replies: pid = reply.positioner_id data = reply.data beta = bytes_to_int(data[4:], dtype="i4") alpha = bytes_to_int(data[0:4], dtype="i4") positions[pid] = motor_steps_to_angle(alpha, beta) return positions
def get_offsets(self) -> Dict[int, numpy.ndarray]: """Returns the alpha and beta offsets, in degrees. Raises ------ ValueError If no reply has been received or the data cannot be parsed. """ offsets = {} for reply in self.replies: pid = reply.positioner_id data = reply.data alpha = bytes_to_int(data[0:4], dtype="i4") beta = bytes_to_int(data[4:], dtype="i4") offsets[pid] = numpy.array(motor_steps_to_angle(alpha, beta)) return offsets