pypozyx.structures package

Submodules

pypozyx.structures.byte_structure module

pypozyx.structures.byte_structure - contains the ByteStructure class, thank you struct.

class pypozyx.structures.byte_structure.ByteStructure[source]

Bases: object

The ByteStructure class is the base class that all custom structs inherit their basic functionality from. It implements the low-level functionality that makes it easy to make use arbitrary struct formats in the interface with Pozyx.

byte_size = 4
bytes_to_data()[source]

Transforms hex data into packed UINT8 byte values

change_data(index, new_data)[source]

Changes the internal contained data of the structure. Good for large structures

data_format = 'BBBB'
load(data, convert=True)[source]

Loads data in its relevant class components.

load_bytes(byte_data)[source]

Loads a hex byte array in the structure’s data

load_hex_string()[source]

Loads the data’s hex string for sending

load_packed(packed)[source]

Unpacks the packed UINT8 bytes in their right format as given in data_format

set_packed_size()[source]

Sets the size (bytesize) to the structures data format, but packed

set_unpacked_size()[source]

Sets the size (bytesize) to the structures data format, unpacked

transform_data(new_format)[source]

Transforms the data to a new format, handy for decoding to bytes

transform_to_bytes()[source]

Transforms the data to a UINT8 bytestring in hex

update_data()[source]

Updates the class’s data when one of its components has changed.

pypozyx.structures.device module

pypozyx.structures.device - contains various classes representing device data

Structures contained

DeviceCoordinates
consists of a device’s ID, flag, and coordinates
DeviceRange
consists of a range measurements timestamp, distance, and RSS
NetworkID
container for a device’s ID. Prints in 0xID format.
DeviceList
container for a list of IDs. Can be initialized through size and/or IDs.
UWBSettings
contains all of the UWB settings: channel, bitrate, prf, plen, and gain.
class pypozyx.structures.device.AlgorithmData(algorithm=0, dimension=0)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

byte_size = 1
data_format = 'B'
get_algorithm_name()[source]
get_dimension_name()[source]
load(data=None, convert=False)[source]

Loads data in its relevant class components.

update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.device.DeviceCoordinates(network_id=0, flag=0, pos=<pypozyx.structures.sensor_data.Coordinates object>)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Container for both reading and writing device coordinates from and to Pozyx.

The keyword arguments are at once its properties.

Kwargs:
network_id: Network ID of the device flag: Type of the device. Tag or anchor. pos: Coordinates of the device. Coordinates().
byte_size = 15
data_format = 'HBiii'
load(data)[source]

Loads data in its relevant class components.

update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.device.DeviceList(ids=[], list_size=0)[source]

Bases: pypozyx.structures.generic.Data

Container for a list of device IDs.

Using list_size is recommended when having just used getDeviceListSize, while ids is recommended when one knows the IDs. When using one, the other automatically gets its respective value. Therefore, only use on of both.

Note also that DeviceList(list_size=1) is the same as NetworkID().

Kwargs:
ids: Array of known or unknown device IDs. Empty by default. list_size: Size of the device list.
load(data)[source]

Loads data in its relevant class components.

class pypozyx.structures.device.DeviceRange(timestamp=0, distance=0, RSS=0)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Container for the device range data, resulting from a range measurement.

The keyword arguments are at once its properties.

Kwargs:
timestamp: Timestamp of the range measurement distance: Distance measured by the device. RSS: Signal strength during the ranging measurement.
byte_size = 10
data_format = 'IIh'
load(data)[source]

Loads data in its relevant class components.

update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.device.FilterData(filter_type=0, filter_strength=0)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

byte_size = 1
data_format = 'B'
get_filter_name()[source]
load(data=[0], convert=False)[source]

Loads data in its relevant class components.

update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.device.NetworkID(network_id=0)[source]

Bases: pypozyx.structures.generic.Data

Container for a device’s network ID.

Kwargs:
network_id: The network ID of the device.
load(data)[source]

Loads data in its relevant class components.

update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.device.RXInfo(remote_id=0, amount_of_bytes=0)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

byte_size = 3
data_format = 'HB'
load(data)[source]

Loads data in its relevant class components.

update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.device.TXInfo(remote_id, operation=6)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Container for data transmission meta information

Parameters:
  • remote_id – ID to transmit to
  • operation – remote operation to execute
byte_size = 3
data_format = 'HB'
update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.device.UWBSettings(channel=0, bitrate=0, prf=0, plen=0, gain_db=0.0)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Container for a device’s UWB settings.

Its keyword arguments are at once its properties.

It also provides parsing functions for all its respective properties, which means this doesn’t need to be done by users. These functions are parse_prf, parse_plen and parse_bitrate.

You can also directly print the UWB settings, resulting in the following example output: “CH: 1, bitrate: 850kbit/s, prf: 16MHz, plen: 1024 symbols, gain: 15.0dB”

Kwargs:
channel: UWB channel of the device. See POZYX_UWB_CHANNEL. bitrate: Bitrate of the UWB commmunication. See POZYX_UWB_RATES. prf: Pulse repeat frequency of the UWB. See POZYX_UWB_RATES. plen: Preamble length of the UWB packets. See POZYX_UWB_PLEN. gain_db: Gain of the UWB transceiver, a float value. See POZYX_UWB_GAIN.
byte_size = 7
data_format = 'BBBBf'
load(data)[source]

Loads data in its relevant class components.

parse_bitrate()[source]

Parses the bitrate to be humanly readable.

parse_plen()[source]

Parses the preamble length to be humanly readable.

parse_prf()[source]

Parses the pulse repetition frequency to be humanly readable.

update_data()[source]

Updates the class’s data when one of its components has changed.

pypozyx.structures.generic module

pypozyx.structures.generic - introduces generic data structures derived from ByteStructure

Generic Structures

As the name implies, contains generic structures whose specific use is up to the user. You should use SingleRegister where applicable when reading/writing a single register, and use Data for larger data structures.

Structures contained: Data

THE generic data structure, a powerful way of constructing arbitrarily formed packed data structures
XYZ
A generic XYZ data structure that is used in much 3D sensor data
SingleRegister
Data resembling a single register. Can choose size and whether signed.
UniformData
A variation on Data with all data being a uniform format. Questionably useful.

The use of Data: Data creates a packed data structure with size and format that is entirely the user’s choice. The format follows the one used in struct, where b is a byte, h is a 2-byte int, and i is a default-sized integer, and f is a float. In capitals, these are signed. So, to create a custom construct consisting of 4 uint16 and a single int, the following code can be used.

>>> d = Data([0] * 5, 'HHHHi')

or

>>> data_format = 'HHHHi'
>>> d = Data([0] * len(data_format), data_format)
class pypozyx.structures.generic.Data(data=None, data_format=None)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Data allows the user to define arbitrary data structures to use with Pozyx.

The Leatherman of ByteStructure-derived classes, Data allows you to create your own library-compatible packed data structures. Also for empty data, this is used.

The use of Data: Data creates a packed data structure with size and format that is entirely the user’s choice. The format follows the one used in struct, where b is a byte, h is a 2-byte int, and i is a default-sized integer, and f is a float. In capitals, these are unsigned. So, to create a custom construct consisting of 4 uint16 and a single int, the following code can be used.

>>> d = Data([0] * 5, 'HHHHi')

or

>>> data_format = 'HHHHi'
>>> d = Data([0] * len(data_format), data_format)
Parameters:
  • data (optional) – Data contained in the data structure. When no data_format is passed, these are assumed UInt8 values.
  • data_format (optional) – Custom data format for the data passed.
load(data, convert=True)[source]

Loads data in its relevant class components.

class pypozyx.structures.generic.SingleRegister(value=0, size=1, signed=0, print_style='hex')[source]

Bases: pypozyx.structures.generic.Data

SingleRegister is container for the data from a single Pozyx register.

By default, this represents a UInt8 register. Used for both reading and writing. The size and whether the data is a ‘signed’ integer are both changeable by the user using the size and signed keyword arguments.

Parameters:
  • value (optional) – Value of the register.
  • size (optional) – Size of the register. 1, 2, or 4. Default 1.
  • signed (optional) – Whether the data is signed. unsigned by default.
  • print_hex (optional) – How to print the register output. Hex by default. Special options are ‘hex’ and ‘bin’ other things, such as ‘dec’, will return decimal output.
byte_size = 1
data_format = 'B'
load(data, convert=True)[source]

Loads data in its relevant class components.

value
class pypozyx.structures.generic.SingleSensorValue(value=0)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Generic Single Sensor Value data structure.

Not recommended to use in practice, as relevant sensor data classes are derived from this.

If deriving this, don’t forget to implement your own update_data function, or data will be [value] consistently instead of […, value, …].

byte_size = 4
data_format = 'i'
load(data=None, convert=True)[source]

Loads data in its relevant class components.

physical_convert = 1
update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.generic.XYZ(x=0, y=0, z=0)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Generic XYZ data structure consisting of 3 integers x, y, and z.

Not recommended to use in practice, as relevant sensor data classes are derived from this.

If deriving this, don’t forget to implement your own update_data function, or data will be [x, y, z] consistently instead of […, x, y, z, …].

byte_size = 12
data_format = 'iii'
load(data, convert=True)[source]

Loads data in its relevant class components.

physical_convert = 1
update_data()[source]

Updates the class’s data when one of its components has changed.

pypozyx.structures.generic.dataCheck(data)[source]

Returns whether an object is part of the ByteStructure-derived classes or not.

The function checks the base classes of the passed data object. This function enables many library functions to be passed along its data as either an int/list or the properly intended data structure. For example, the following code will result in the same behaviour:

>>> p.setCoordinates([0, 0, 0])
>>> # or
>>> coords =  Coordinates()
>>> p.setCoordinates(coords)

AND

>>> p.setNetworkId(0x6000)
>>> # or
>>> n = NetworkID(0x6000)
>>> p.setNetworkId(n)

Note that this only works for functions where you change one of the Pozyx’s settings. When reading data from the Pozyx, you have to pass along the correct data structure.

Using dataCheck: You might want to use this in your own function, as it makes it more robust to whether an int or list gets sent as a parameter to your function, or a ByteStructure-like object. If so, you can perform:

>>> if not dataCheck(sample): # assume a is an int but you want it to be a SingleRegister
>>>     sample = SingleRegister(sample)
pypozyx.structures.generic.is_functioncall(reg)[source]

Returns whether a Pozyx register is a Pozyx function.

pypozyx.structures.generic.is_reg_readable(reg)[source]

Returns whether a Pozyx register is readable.

pypozyx.structures.generic.is_reg_writable(reg)[source]

Returns whether a Pozyx register is writeable.

pypozyx.structures.sensor_data module

pypozyx.structures.sensor_data - Contains container classes for data from the Pozyx’s many sensors.

class pypozyx.structures.sensor_data.Acceleration(x=0, y=0, z=0)[source]

Bases: pypozyx.structures.generic.XYZ

Container for acceleration in x, y, and z (in mg).

byte_size = 6
data_format = 'hhh'
physical_convert = 1.0
class pypozyx.structures.sensor_data.AngularVelocity(x=0, y=0, z=0)[source]

Bases: pypozyx.structures.generic.XYZ

Container for angular velocity in x, y, and z (in dps).

byte_size = 6
data_format = 'hhh'
physical_convert = 16.0
class pypozyx.structures.sensor_data.Coordinates(x=0, y=0, z=0)[source]

Bases: pypozyx.structures.generic.XYZ

Container for coordinates in x, y, and z (in mm).

byte_size = 12
data_format = 'iii'
load(data, convert=False)[source]

Loads data in its relevant class components.

class pypozyx.structures.sensor_data.CoordinatesWithStatus(x=0, y=0, z=0, status=False)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Container for coordinates in x, y, and z (in mm).

byte_size = 13
data_format = 'iiiB'
load(data, convert=False)[source]

Loads data in its relevant class components.

update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.sensor_data.EulerAngles(heading=0, roll=0, pitch=0)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Container for euler angles as heading, roll, and pitch (in degrees).

byte_size = 6
data_format = 'hhh'
load(data, convert=True)[source]

Loads data in its relevant class components.

physical_convert = 16.0
update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.sensor_data.LinearAcceleration(x=0, y=0, z=0)[source]

Bases: pypozyx.structures.generic.XYZ

Container for linear acceleration in x, y, and z (in mg), as floats.

byte_size = 6
data_format = 'hhh'
load(data, convert=True)[source]

Loads data in its relevant class components.

physical_convert = 1.0
class pypozyx.structures.sensor_data.Magnetic(x=0, y=0, z=0)[source]

Bases: pypozyx.structures.generic.XYZ

Container for coordinates in x, y, and z (in uT).

byte_size = 6
data_format = 'hhh'
physical_convert = 16.0
class pypozyx.structures.sensor_data.MaxLinearAcceleration(value=0)[source]

Bases: pypozyx.structures.generic.SingleSensorValue

byte_size = 2
data_format = 'h'
physical_convert = 1.0
class pypozyx.structures.sensor_data.PositionError(x=0, y=0, z=0, xy=0, xz=0, yz=0)[source]

Bases: pypozyx.structures.generic.XYZ

Container for position error in x, y, z, xy, xz, and yz (in mm).

byte_size = 12
data_format = 'hhhhhh'
load(data)[source]

Loads data in its relevant class components.

physical_convert = 1
update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.sensor_data.PositioningData(flags)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

SENSOR_ORDER = [<class 'pypozyx.structures.sensor_data.CoordinatesWithStatus'>, <class 'pypozyx.structures.sensor_data.Acceleration'>, <class 'pypozyx.structures.sensor_data.AngularVelocity'>, <class 'pypozyx.structures.sensor_data.Magnetic'>, <class 'pypozyx.structures.sensor_data.EulerAngles'>, <class 'pypozyx.structures.sensor_data.Quaternion'>, <class 'pypozyx.structures.sensor_data.LinearAcceleration'>, <class 'pypozyx.structures.sensor_data.Acceleration'>, <class 'pypozyx.structures.sensor_data.Pressure'>, <class 'pypozyx.structures.sensor_data.MaxLinearAcceleration'>]
add_sensor(sensor_class)[source]
has_ranges()[source]
load(data, convert=0)[source]

Loads data in its relevant class components.

load_bytes(byte_data)[source]

Loads a hex byte array in the structure’s data

number_of_ranges
set_amount_of_ranges(amount_of_ranges)[source]
set_data_structures()[source]
class pypozyx.structures.sensor_data.Pressure(value=0)[source]

Bases: pypozyx.structures.generic.SingleSensorValue

byte_size = 4
data_format = 'I'
physical_convert = 1000.0
class pypozyx.structures.sensor_data.Quaternion(w=0, x=0, y=0, z=0)[source]

Bases: pypozyx.structures.generic.XYZ

Container for quaternion data in x, y, z and w.

byte_size = 8
data_format = 'hhhh'
get_sum()[source]

Returns the normalization value of the quaternion

load(data, convert=True)[source]

Loads data in its relevant class components.

normalize()[source]

Normalizes the quaternion’s data

physical_convert = 16384.0
update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.sensor_data.RangeInformation(device_id=0, distance=0)[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

byte_size = 6
data_format = 'HI'
load(data, convert=0)[source]

Loads data in its relevant class components.

update_data()[source]

Updates the class’s data when one of its components has changed.

class pypozyx.structures.sensor_data.RawSensorData(data=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])[source]

Bases: pypozyx.structures.sensor_data.SensorData

Container for raw sensor data

This includes, in order, with respective structure:
  • pressure : UInt32
  • acceleration : Acceleration
  • magnetic : Magnetic
  • angular_vel : AngularVelocity
  • euler_angles : EulerAngles
  • quaternion : Quaternion
  • linear_acceleration: LinearAcceleration
  • gravity_vector: LinearAcceleration
  • temperature: Int8
load(data)[source]

Loads data in its relevant class components.

class pypozyx.structures.sensor_data.SensorData(data=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])[source]

Bases: pypozyx.structures.byte_structure.ByteStructure

Container for all sensor data.

This includes, in order, with respective structure:
  • pressure : UInt32
  • acceleration : Acceleration
  • magnetic : Magnetic
  • angular_vel : AngularVelocity
  • euler_angles : EulerAngles
  • quaternion : Quaternion
  • linear_acceleration: LinearAcceleration
  • gravity_vector: LinearAcceleration
  • temperature: Int8
byte_size = 49
data_format = 'Ihhhhhhhhhhhhhhhhhhhhhhb'
load(data, convert=True)[source]

Loads data in its relevant class components.

update_data()[source]

Not used so data remains the raw unformatted data

class pypozyx.structures.sensor_data.Temperature(value=0)[source]

Bases: pypozyx.structures.generic.SingleSensorValue

byte_size = 1
data_format = 'b'
physical_convert = 1.0

Module contents

pypozyx.structures - contains ByteStructure and derived classes that contain the Pozyx data.

The PyPozyx library is designed to work with these objects, and they abstract the low-level approach that would otherwise be necessary in using the serial port, so these are very recommended to use.

This package is subdivided in three groups of structures, derived from ByteStructure:
  • device: containers for device functionality. Network ID, UWB settings, device coordinates/range
  • sensor_data: containers for sensor data retrieved from the Pozyx. Magnetic, acceleration, etc.
    These also take care of the physical convertion to the respective standard units for that sensor.
  • generic: as the name suggests, generic containers. The SingleRegister object is a
    multipurpose object that can be used to read single registers of any size. Data can be used to create your own arbitrary packed structures.

When importing this package, you will get all of the device classes, the sensor data classes, and both SingleRegister and Data.