def print_anchor_config(self): print("Anchor coordinate config:") anchor_coordinate = Coordinates() uwb_setting = UWBSettings() for i in range(len(self.anchor_list)): status = self.pozyx.getDeviceCoordinates( self.anchor_list[i].network_id, anchor_coordinate) if status == POZYX_SUCCESS: print("anchor " + hex(self.anchor_list[i].network_id) + " coordinate is X: " + str(anchor_coordinate.x) + " mm; Y: " + str(anchor_coordinate.y) + " mm; Z: " + str(anchor_coordinate.z) + " mm;") else: print("get anchor" + hex(self.anchor_list[i].network_id) + " coordinate config err") status = self.pozyx.getUWBSettings(uwb_setting, self.anchor_list[i].network_id) if status == POZYX_SUCCESS: print("UWB Setting, channel: " + str(uwb_setting.channel) + " Bitrate: " + str(uwb_setting.bitrate) + " Prf: " + str(uwb_setting.prf) + " Plen: " + str(uwb_setting.plen) + " Gain: " + str(uwb_setting.gain_db) + " DB") else: print("get UWB Setting err")
def discover_all_devices(pozyx): amount_of_settings = len([uwb for uwb in all_discovery_uwb_settings()]) original_uwb_settings = UWBSettings() pozyx.getUWBSettings(original_uwb_settings) devices = set() print('\nStarting discovery') print('------------------') sys.stdout.write("Discovery progress [%s]" % (" " * amount_of_settings)) sys.stdout.flush() sys.stdout.write( "\b" * (amount_of_settings + 1)) # return to start of line, after '[' counter = 0 s = "[" for uwb_settings in all_discovery_uwb_settings(): pozyx.setUWBSettings(uwb_settings) for i in range(2): pozyx.clearDevices() pozyx.doDiscovery(PozyxConstants.DISCOVERY_ALL_DEVICES) for device_coordinates in all_device_coordinates_in_device_list( pozyx): uwb_device = UWBSettings() pozyx.getUWBSettings(uwb_device, remote_id=device_coordinates.network_id) device = Device(device_coordinates.network_id, uwb_device) # print(device, hash(device)) # print(device in devices) devices.add(device) sys.stdout.write("=") sys.stdout.flush() sys.stdout.write("]\n\nDiscovery finished.\n") for device in devices: pozyx.setUWBSettings(device.uwb_settings) device_check(pozyx, device._id) print() pozyx.setUWBSettings(original_uwb_settings)
def device_check(pozyx, remote_id=None): # pozyx.resetSystem() system_details = DeviceDetails() status = pozyx.getDeviceDetails(system_details, remote_id=remote_id) if status != POZYX_SUCCESS: print("Unable to get device details for device with id 0x%0.4x" % remote_id) return if remote_id is None: print("Local %s with id 0x%0.4x" % (system_details.device_name, system_details.id)) else: print("%s with id 0x%0.4x" % (system_details.device_name.capitalize(), system_details.id)) print("\tWho am i: 0x%0.2x" % system_details.who_am_i) print("\tFirmware version: v%s" % system_details.firmware_version_string) print("\tHardware version: v%s" % system_details.hardware_version_string) print("\tSelftest result: %s" % system_details.selftest_string) print("\tError: 0x%0.2x" % system_details.error_code) print("\tError message: %s" % system_details.error_message) uwb_settings = UWBSettings() pozyx.getUWBSettings(uwb_settings, remote_id=remote_id) print("\tUWB settings: %s" % uwb_settings) print("\tTotal saved registers: %s" % pozyx.getNumRegistersSaved(remote_id=remote_id)) saved_registers_to_check = PozyxRegisters.ALL_POSITIONING_REGISTERS + PozyxRegisters.ALL_UWB_REGISTERS saved_registers = pozyx.getSavedRegisters(remote_id=remote_id) if saved_registers: # if system_details.device_name == "tag": print("\t\t- Positioning registers: ") for register, register_name in zip(PozyxRegisters.ALL_POSITIONING_REGISTERS, ["Filter", "Algorithm & Dimension", "Ranging protocol", "Height"]): byte_num = int(register / 8) bit_num = register % 8 register_saved = bool(saved_registers[byte_num] >> bit_num & 0x1) print("\t\t\t- {}: {}".format(register_name, register_saved)) print("\t\t- UWB registers: ") for register, register_name in zip(PozyxRegisters.ALL_UWB_REGISTERS, ["Channel", "Bitrate & PRF", "Preamble length", "Gain"]): byte_num = int(register / 8) bit_num = register % 8 register_saved = bool(saved_registers[byte_num] >> bit_num & 0x1) print("\t\t\t- {}: {}".format(register_name, register_saved)) else: print("\tFailed to retrieve saved registers.") if system_details.device_name == "tag" and remote_id is not None: print("\tDevices for positioning:") pozyx.printDeviceList(remote_id=remote_id, include_coordinates=True, prefix="\t\t-")
def discover_all_devices(pozyx): original_uwb_settings = UWBSettings() pozyx.getUWBSettings(original_uwb_settings) for uwb_settings in all_discovery_uwb_settings(): pozyx.setUWBSettings(uwb_settings) pozyx.clearDevices() pozyx.doDiscoveryAll(slots=3, slot_duration=0.1) device_list = get_device_list(pozyx) if device_list: print("Found on {}".format(uwb_settings)) for device_id in device_list: uwbOnDevice = UWBSettings() status = pozyx.getUWBSettings(uwbOnDevice, device_id) if status == PozyxConstants.STATUS_SUCCESS: print("\t- {}, {}".format(hex(device_id), uwbOnDevice)) else: print("\t- {}".format(hex(device_id))) pozyx.setUWBSettings(original_uwb_settings)
def discover_all_devices(pozyx): original_uwb_settings = UWBSettings() pozyx.getUWBSettings(original_uwb_settings) for uwb_settings in all_discovery_uwb_settings(): pozyx.setUWBSettings(uwb_settings) pozyx.clearDevices() pozyx.doDiscoveryAll(slots=3, slot_duration=0.1) device_list = get_device_list(pozyx) if device_list: print("Found on {}".format(uwb_settings)) for device_id in device_list: print("\t- {}".format(device_id)) pozyx.setUWBSettings(original_uwb_settings)
def ConfigureUWB(self, id, txPower=33.0, channel=1, bitrate=0, gain=67, prf=2, preamble=40): if txPower < 0.0 or txPower > 33.0: raise ValueError("Invalid txPower") if id == self.id: id = None settings = UWBSettings() settings.bitrate = bitrate settings.channel = channel settings.gain_db = gain settings.plen = preamble settings.prf = prf status = self.pozyx.setUWBSettings(settings, id) self.CheckStatus(status) status = self.pozyx.setTxPower(txPower, id) self.CheckStatus(status)
#import pypozyx import sys, time from pypozyx import PozyxSerial, get_first_pozyx_serial_port, POZYX_SUCCESS, SingleRegister, EulerAngles, Acceleration, UWBSettings #pozyx = PozyxLib() # PozyxSerial has PozyxLib's functions, just for generality CURSOR_UP_ONE = '\x1b[1A' ERASE_LINE = '\x1b[2K' is_cursor_up = False #print(pypozyx.get_first_pozyx_serial_port()) pozyx = PozyxSerial(get_first_pozyx_serial_port()) who_am_i = SingleRegister() # get the data, passing along the container status = pozyx.getWhoAmI(who_am_i) acceleration = Acceleration() euler_angles = EulerAngles() uwb_settings = UWBSettings() # check the status to see if the read was successful. Handling failure is covered later. if status == POZYX_SUCCESS: # print the container. Note how a SingleRegister will print as a hex string by default. print('Who Am I: {}'.format(who_am_i)) # will print '0x43' while True: # initalize the Pozyx as above # initialize the data container # and repeat # initialize the data container # get the data, passing along the container if is_cursor_up: sys.stdout.write(CURSOR_UP_ONE)
def all_discovery_uwb_settings(): for channel in PozyxConstants.ALL_UWB_CHANNELS: for bitrate in PozyxConstants.ALL_UWB_BITRATES: for prf in PozyxConstants.ALL_UWB_PRFS: for plen in [PozyxConstants.UWB_PLEN_64, PozyxConstants.UWB_PLEN_1536]: yield UWBSettings(channel, bitrate, prf, plen, 33)
for uwb_settings in all_discovery_uwb_settings(): pozyx.setUWBSettings(uwb_settings) pozyx.clearDevices() pozyx.doDiscoveryAll(slots=3, slot_duration=0.1) device_list = get_device_list(pozyx) if device_list: print("Found on {}".format(uwb_settings)) for device_id in device_list: uwbOnDevice = UWBSettings() status = pozyx.getUWBSettings(uwbOnDevice, device_id) if status == PozyxConstants.STATUS_SUCCESS: print("\t- {}, {}".format(hex(device_id), uwbOnDevice)) else: print("\t- {}".format(hex(device_id))) pozyx.setUWBSettings(original_uwb_settings) if __name__ == '__main__': from pypozyx import PozyxSerial, get_first_pozyx_serial_port pozyx = PozyxSerial(get_first_pozyx_serial_port()) uwb = UWBSettings() pozyx.getUWBSettings(uwb) print("Local device on {}".format(uwb)) discover_all_devices(pozyx)