def compute_checksum(byte_seq):
    """Compute and return the checksum of the `byte_seq` packet.

    The checksum is the value of the last byte of each packet. It is used
    to prevent transmission errors of packets. Checksums are computed as
    follow::

        Checksum = ~(dynamixel_id + length + data1 + ... + dataN)

    where ~ represent the NOT logic operation.

    If the computed value is larger than 255, then only its lower byte is
    defined as the checksum value.

    :param bytes byte_seq: a byte sequence containing the packet's bytes
        involved in the computation of the checksum (i.e. from the third to the
        penultimate byte of the "full packet" considered).
    """

    # Check the argument and convert it to "bytes" if necessary.
    # Assert "byte_seq" items are in range (0, 0xff).
    # "TypeError" and "ValueError" are sent by the "bytes" constructor if
    # necessary.
    # The statement "tuple(byte_seq)" implicitely rejects integers (and all
    # non-iterable objects) to compensate the fact that the bytes constructor
    # doesn't reject them: bytes(3) is valid and returns b'\x00\x00\x00'.
    byte_seq = bytes(tuple(byte_seq))

    # Check the argument's length
    if len(byte_seq) < 3:
        raise ValueError("At least three bytes are required.")

    # Check the ID byte
    if not (0x00 <= byte_seq[0] <= 0xfe):
        msg = "Wrong dynamixel_id, a byte in range(0x00, 0xfe) is required."
        raise ValueError(msg)

    # Check the "length" byte
    if byte_seq[1] != (len(byte_seq) - 1):
        raise ValueError('Wrong length, at least 3 bytes are required.')

    checksum = ~sum(byte_seq) & 0xff

    return checksum