Skip to content

Commit 4f949b6

Browse files
authored
Merge pull request #35 from pozyxLabs/develop
PR for PyPozyx release v1.1
2 parents f15d642 + 60d615e commit 4f949b6

31 files changed

+880
-350
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ p = PozyxSerial(port)
2323
If your port is correct and the serial connection to the Pozyx isn't used by other software, this will run without any errors.
2424

2525
#### But! How do I know what port my Pozyx is on?
26-
You can see the COM ports on your system easily using Python with:
26+
* You can see the COM ports on your system easily using Python with:
2727
`python -c "from pypozyx import *;list_serial_ports()"`
28-
28+
* **NEW** You can quickly find whether there's a recognized Pozyx device using:
29+
`python -c "from pypozyx import *;print(get_first_pozyx_serial_port())"`
2930

3031
### Documentation and examples
31-
You can find the Python tutorials on our site. You probably got here from [the getting started page](https://www.pozyx.io/Documentation/Tutorials/getting_started/Python)
32+
You can find the Python tutorials on our site. You probably got here from [the getting started page](https://www.pozyx.io/Documentation/Tutorials/getting_started/Python) after all.
33+
34+
Documentation can be found [here](https://www.pozyx.io/Documentation/Datasheet/python).
3235

33-
There is currently a lack of documentation, unlike for the Arduino library. For now, these pointers and pages should be helpful:
34-
* All functions that exist in the Arduino library, also exist in the Python library under the same name and functionality, so most of the [Arduino Library Documentation](https://www.pozyx.io/Documentation/Datasheet/arduino) is transformable to this. The major difference is that you don't ever again need to pass along the length of the data you're reading/writing. This is taken care of by the library:
35-
* The Data and SingleRegister classes take care of this. eg. to read out the WhoAmI register, appending to the test code above.
36+
* This was originally a port of the Pozyx's Arduino library, so most of the [Arduino Library Documentation](https://www.pozyx.io/Documentation/Datasheet/arduino) is transformable to this. The major difference is that you don't ever again need to pass along the length of the data you're reading/writing. This is taken care of by the library through the Data and SingleRegister classes like so:
3637
```python
3738
whoami = SingleRegister()
3839
pozyx.regRead(POZYX_WHO_AM_I, whoami) # which is pozyx.getWhoAmI(whoami)
3940
```
4041
* `SingleRegister(value=0, size=1, signed=1)` is basically an instance `Data([0], 'B')`, which functions as a single uint8_t. If you want to make your custom data, for a single register you can adapt the size and signed parameters, and for larger data structures you can use your own data formats. `Data([0]*3, 'BHI')`, for example, creates a structure of 1 uint8_t, uint16_t and uint32_t. Writing and reading data using this example as a parameter will automatically read/write 7 bytes worth of data. To specify your own data formats, check the [struct package documentation for Python 3](https://docs.python.org/3.5/library/struct.html#format-characters) or [Python 2](https://docs.python.org/2/library/struct.html).
42+
* A more pythonic library would be nice, but isn't in the works.
4143

4244

43-
More usage examples can be found in the useful and examples folders of the repository.
45+
More usage examples can be found in the [useful](https://github.com/pozyxLabs/Pozyx-Python-library/tree/master/useful) and [tutorials](https://github.com/pozyxLabs/Pozyx-Python-library/tree/master/tutorials) folders of the repository.

README.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Pozyx-Python-library
2+
====================
3+
The unofficial release of the Python library (Beta version) to work with the pozyx indoor positioning system
4+
5+
This library works with both Python 2 and 3.
6+
7+
Prerequisites
8+
-------------
9+
* Download and install Python. On Windows, make your life easier and make sure Python is in your PATH. A recommended install is therefore the `Anaconda Suite <https://www.continuum.io/downloads>`_ by Continuum. If you're going to follow the tutorials, you'll need to install Python 3 for the python-osc support.
10+
* Install the PySerial package. If you have pip installed, you can do this by writing ``pip install pyserial`` in your command line interface (cmd on Windows).
11+
* **Windows only** install `ST's virtual COM driver <http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-utilities/stsw-stm32102.html>`_. After running this installer, please run the correct driver package for your system, located in "C:\\Program Files (x86)\\STMicroelectronics\\Software\\Virtual comport driver". Choose Win7 if you run Windows 7 or older. Choose Win8 for Windows 8 or newer. Run "dpinst_amd64.exe" on a 64-bit system, "dpinst_x86.exe"on a 32-bit system.
12+
13+
Installing this package
14+
-----------------------
15+
As it's not yet available on PyPi, you will have to install the library from source like this
16+
17+
* Download the library as a zip file, or clone it in a folder.
18+
* After changing your command window's working directory to the extracted/cloned folder, perform ``python setup.py install``
19+
20+
PyPozyx is now installed. To check whether it is: if you followed all the steps correctly, and know which port your Pozyx is on, the following code should work:
21+
22+
.. code:: python
23+
24+
from pypozyx import PozyxSerial
25+
port = 'COMX' # on UNIX systems this will be '/dev/ttyACMX'
26+
p = PozyxSerial(port)
27+
28+
29+
If your port is correct and the serial connection to the Pozyx isn't used by other software, this will run without any errors.
30+
31+
But! How do I know what port my Pozyx is on?
32+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33+
34+
* You can see the COM ports on your system easily using Python with: ``python -c "from pypozyx import *;list_serial_ports()"``
35+
36+
* **NEW** You can quickly find whether there's a recognized Pozyx device using: ``python -c "from pypozyx import *;print(get_first_pozyx_serial_port())"``
37+
38+
39+
Documentation and examples
40+
--------------------------
41+
You can find the Python tutorials on our site. You probably got here from `the getting started page <https://www.pozyx.io/Documentation/Tutorials/getting_started/Python>`_
42+
43+
Documentation can be found `here <https://www.pozyx.io/Documentation/Datasheet/python>`_.
44+
45+
* This was originally a port of the Pozyx's Arduino library, so most of the `Arduino Library Documentation <https://www.pozyx.io/Documentation/Datasheet/arduino>`_ is transformable to this. The major difference is that you don't ever again need to pass along the length of the data you're reading/writing. This is taken care of by the library through the Data and SingleRegister classes like so:
46+
47+
.. code:: python
48+
49+
whoami = SingleRegister()
50+
pozyx.regRead(POZYX_WHO_AM_I, whoami) # which is pozyx.getWhoAmI(whoami)
51+
52+
* `SingleRegister(value=0, size=1, signed=1)` is basically an instance `Data([0], 'B')`, which functions as a single uint8_t. If you want to make your custom data, for a single register you can adapt the size and signed parameters, and for larger data structures you can use your own data formats. `Data([0]*3, 'BHI')`, for example, creates a structure of 1 uint8_t, uint16_t and uint32_t. Writing and reading data using this example as a parameter will automatically read/write 7 bytes worth of data. To specify your own data formats, check the `struct package documentation for Python 3 <https://docs.python.org/3.5/library/struct.html#format-characters>`_ or `Python 2 <https://docs.python.org/2/library/struct.html>`_.
53+
54+
* A more pythonic library would be nice, but isn't in the works.
55+
56+
57+
More usage examples can be found in the `useful <https://github.com/pozyxLabs/Pozyx-Python-library/tree/master/useful>`_ and `tutorials <https://github.com/pozyxLabs/Pozyx-Python-library/tree/master/tutorials>`_ folders of the repository.

pypozyx/__init__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@
5858
Pozyx constant definitions, such as general constants, register indexes,
5959
and bit masks for certain functionality.
6060
61-
State of the beta
62-
-----------------
63-
The PyPozyx package is currently in Beta version 1. In this Beta, the initial
64-
run of documentation will be added, and bugfixes will be done as encountered.
65-
When this is done, the library will enter Beta version 2, which is the final
66-
planned beta. In this, we will focus on robustness and do a final documentation
67-
evaluation. After this, we'll consider it 1.0.
6861
6962
Serial port warnings
7063
--------------------
@@ -87,9 +80,14 @@
8780
8881
"""
8982

83+
__version__ = '1.1.0'
84+
85+
VERSION = __version__
86+
version = __version__
87+
88+
9089
from pypozyx.definitions.constants import *
91-
from pypozyx.pozyx_serial import (PozyxSerial, get_pozyx_ports,
92-
get_serial_ports, list_serial_ports)
90+
from pypozyx.pozyx_serial import *
9391
from pypozyx.structures.device import *
9492
from pypozyx.structures.generic import *
9593
from pypozyx.structures.sensor_data import *

pypozyx/core.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
is_functioncall, is_reg_readable,
1818
is_reg_writable)
1919

20+
from warnings import warn
2021

2122
class PozyxCore():
2223
"""PozyxCore
@@ -84,8 +85,6 @@ def remoteRegWrite(self, destination, address, data):
8485
Returns:
8586
POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT
8687
"""
87-
if is_reg_writable(address) == 0:
88-
return POZYX_FAILURE
8988
if len(data) > MAX_BUF_SIZE - 1:
9089
return POZYX_FAILURE
9190

@@ -99,7 +98,7 @@ def remoteRegWrite(self, destination, address, data):
9998
status = self.regFunction(POZYX_TX_SEND, params, Data([]))
10099
if status == POZYX_FAILURE:
101100
return status
102-
return self.checkForFlag(POZYX_INT_STATUS_FUNC, 0.1)
101+
return self.checkForFlag(POZYX_INT_STATUS_FUNC, 0.5)
103102

104103
def remoteRegRead(self, destination, address, data):
105104
"""
@@ -115,8 +114,6 @@ def remoteRegRead(self, destination, address, data):
115114
"""
116115
if dataCheck(destination):
117116
destination = destination[0]
118-
if is_reg_readable(address) == 0:
119-
return POZYX_FAILURE
120117
if len(data) > MAX_BUF_SIZE:
121118
return POZYX_FAILURE
122119
if destination == 0:
@@ -157,9 +154,6 @@ def remoteRegFunction(self, destination, address, params, data):
157154
Returns:
158155
POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT
159156
"""
160-
if is_functioncall(address) == 0:
161-
return POZYX_FAILURE
162-
163157
send_data = Data([0, address] + params.data, 'BB' + params.data_format)
164158
status = self.regFunction(POZYX_TX_DATA, send_data, Data([]))
165159
if status == POZYX_FAILURE:
@@ -243,6 +237,9 @@ def setWrite(self, address, data, remote_id=None, local_delay=POZYX_DELAY_LOCAL_
243237
>>> leds = SingleRegister(0xFF)
244238
>>> self.setWrite(POZYX_LED_CTRL, leds)
245239
"""
240+
if not is_reg_writable(address):
241+
if not self.suppress_warnings:
242+
warn("Register 0x%0.02x isn't writable" % address, stacklevel=3)
246243
if remote_id is None:
247244
status = self.regWrite(address, data)
248245
sleep(local_delay)
@@ -271,6 +268,9 @@ def getRead(self, address, data, remote_id=None):
271268
>>> print(whoami)
272269
67
273270
"""
271+
if not is_reg_readable(address):
272+
if not self.suppress_warnings:
273+
warn("Register 0x%0.02x isn't readable" % address, stacklevel=3)
274274
if remote_id is None:
275275
return self.regRead(address, data)
276276
else:
@@ -294,6 +294,9 @@ def useFunction(self, function, params=None, data=None, remote_id=None):
294294
Example:
295295
>>> self.useFunction(POZYX_DEVICES_CLEAR)
296296
"""
297+
if not is_functioncall(function):
298+
if not self.suppress_warnings:
299+
warn("Register 0x%0.02x isn't a function register" % address, stacklevel=3)
297300
if params is None:
298301
params = Data([])
299302
if data is None:

pypozyx/definitions/constants.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
# physical quantities
8181
POZYX_POS_DIV_MM = 1.0
8282
POZYX_PRESS_DIV_PA = 1000.0
83-
POZYX_ACCEL_DIV_MG = 1.0
83+
POZYX_MAX_LIN_ACCEL_DIV_MG = 1.0
84+
POZYX_ACCEL_DIV_MG = 16.0
8485
POZYX_GYRO_DIV_DPS = 16.0
8586
POZYX_MAG_DIV_UT = 16.0
8687
POZYX_EULER_DIV_DEG = 16.0
@@ -137,3 +138,34 @@
137138
POZYX_ALL_BITRATES = [0, 1, 2]
138139
POZYX_ALL_PRFS = [1, 2]
139140
POZYX_ALL_PLENS = [0x04, 0x14, 0x24, 0x34, 0x08, 0x18, 0x28, 0x0C]
141+
142+
143+
ERROR_CODES = {
144+
POZYX_ERROR_NONE: "NO ERROR",
145+
POZYX_ERROR_I2C_WRITE: "ERROR 0x01: Error writing to a register through the I2C bus",
146+
POZYX_ERROR_I2C_CMDFULL: "ERROR 0x02: Pozyx cannot handle all the I2C commands at once",
147+
POZYX_ERROR_ANCHOR_ADD: "ERROR 0x03: Cannot add anchor to the internal device list",
148+
POZYX_ERROR_COMM_QUEUE_FULL: "ERROR 0x04: Communication queue is full, too many UWB messages",
149+
POZYX_ERROR_I2C_READ: "ERROR 0x05: Error reading from a register from the I2C bus",
150+
POZYX_ERROR_UWB_CONFIG: "ERROR 0x06: Cannot change the UWB configuration",
151+
POZYX_ERROR_OPERATION_QUEUE_FULL: "ERROR 0x07: Pozyx cannot handle all the operations at once",
152+
POZYX_ERROR_STARTUP_BUSFAULT: "ERROR 0x08: Internal bus error",
153+
POZYX_ERROR_FLASH_INVALID: "ERROR 0x09: Flash memory is corrupted or invalid",
154+
POZYX_ERROR_NOT_ENOUGH_ANCHORS: "ERROR 0x0A: Not enough anchors available for positioning",
155+
POZYX_ERROR_DISCOVERY: "ERROR 0x0B: Error during the Discovery process",
156+
POZYX_ERROR_CALIBRATION: "ERROR 0x0C: Error during the auto calibration process",
157+
POZYX_ERROR_FUNC_PARAM: "ERROR 0x0D: Invalid function parameters for the register function",
158+
POZYX_ERROR_ANCHOR_NOT_FOUND: "ERROR 0x0E: The coordinates of an anchor are not found",
159+
POZYX_ERROR_FLASH: "ERROR 0x0F: Flash error",
160+
POZYX_ERROR_MEMORY: "ERROR 0x10: Memory error",
161+
POZYX_ERROR_RANGING: "ERROR 0x11: Ranging failed",
162+
POZYX_ERROR_RTIMEOUT1: "ERROR 0x12: Ranging timeout",
163+
POZYX_ERROR_RTIMEOUT2: "ERROR 0x13: Ranging timeout",
164+
POZYX_ERROR_TXLATE: "ERROR 0x14: Tx was late",
165+
POZYX_ERROR_UWB_BUSY: "ERROR 0x15: UWB is busy",
166+
POZYX_ERROR_POSALG: "ERROR 0x16: Positioning failed",
167+
POZYX_ERROR_NOACK: "ERROR 0x17: No Acknowledge received",
168+
POZYX_ERROR_NEW_TASK: "ERROR 0xF1: Cannot create task",
169+
POZYX_ERROR_UNRECDEV: "ERROR 0xFE: Hardware not recognized. Please contact [email protected]",
170+
POZYX_ERROR_GENERAL: "ERROR 0xFF: General error",
171+
}

0 commit comments

Comments
 (0)