Beispiel #1
0
    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)
Beispiel #2
0
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)
Beispiel #3
0
    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
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
    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
Beispiel #7
0
    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