Utils module

This module contains some general purpose utility functions.

pyax12.utils.int_to_little_endian_bytes(integer)[source]

Converts a two-bytes integer into a pair of one-byte integers using the little-endian notation (i.e. the less significant byte first).

The integer input must be a 2 bytes integer, i.e. integer must be greater or equal to 0 and less or equal to 65535 (0xffff in hexadecimal notation).

For instance, with the input decimal value integer=700 (0x02bc in hexadecimal notation) this function will return the tuple (0xbc, 0x02).

Parameters:integer (int) – the 2 bytes integer to be converted. It must be in range (0, 0xffff).
pyax12.utils.little_endian_bytes_to_int(little_endian_byte_seq)[source]

Converts a pair of bytes into an integer.

The little_endian_byte_seq input must be a 2 bytes sequence defined according to the little-endian notation (i.e. the less significant byte first).

For instance, if the little_endian_byte_seq input is equals to (0xbc, 0x02) this function returns the decimal value 700 (0x02bc in hexadecimal notation).

Parameters:little_endian_byte_seq (bytes) – the 2 bytes sequence to be converted. It must be compatible with the “bytes” type and defined according to the little-endian notation.
pyax12.utils.pretty_hex_str(byte_seq, separator=', ')[source]

Converts a squence of bytes to a string of hexadecimal numbers.

For instance, with the input tuple (255, 0, 10) this function will return the string "ff,00,0a".

Parameters:
  • byte_seq (bytes) – a sequence of bytes to process. It must be compatible with the “bytes” type.
  • separator (str) – the string to be used to separate each byte in the returned string (default ”,”).
pyax12.utils.dxl_angle_to_degrees(dxl_angle)[source]

Normalize the given angle.

PxAX-12 uses the position angle (-150.0°, +150.0°) range instead of the (0°, +300.0°) range defined in the Dynamixel official documentation because the former is easier to use (especially to make remarkable angles like right angles or 45° and 135° angles).

Parameters:dxl_angle (int) –

an angle defined according to the Dynamixel internal notation, i.e. in the range (0, 1023) where:

  • 0 is a 150° clockwise angle;
  • 1023 is a 150° counter clockwise angle.
Returns:an angle defined in degrees in the range (-150.0°, +150.0°) where:
  • -150.0 is a 150° clockwise angle;
  • +150.0 is a 150° counter clockwise angle.
Return type:float.
pyax12.utils.degrees_to_dxl_angle(angle_degrees)[source]

Normalize the given angle.

PxAX-12 uses the position angle (-150.0°, +150.0°) range instead of the (0°, +300.0°) range defined in the Dynamixel official documentation because the former is easier to use (especially to make remarkable angles like right angles or 45° and 135° angles).

Parameters:angle_degrees (float) –

an angle defined in degrees the range (-150.0°, +150.0°) where:

  • -150.0 is a 150° clockwise angle;
  • +150.0 is a 150° counter clockwise angle.
Returns:an angle defined according to the Dynamixel internal notation, i.e. in the range (0, 1023) where:
  • 0 is a 150° clockwise angle;
  • 1023 is a 150° counter clockwise angle.
Return type:int.