Skip to content

Commit e7d0879

Browse files
committed
Wrote getting started and more
1 parent 904fa4e commit e7d0879

File tree

7 files changed

+360
-0
lines changed

7 files changed

+360
-0
lines changed

docs/getting_started/index.rst

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
Getting started
2+
---------------
3+
4+
.. note::
5+
6+
In this text, the word tag and shield will be used interchangeably.
7+
8+
Arduino
9+
~~~~~~~~~~~~~~~~~~~~~~~~
10+
11+
If you're not familiar with the Arduino platform as a whole, `this <https://www.arduino.cc/en/Guide/HomePage>`_ is a good place to get started and set up with testing your Arduino's basic functionality.
12+
13+
14+
Setup
15+
~~~~
16+
17+
Role of Arduino
18+
_______________
19+
20+
The Arduino communicates to the Pozyx device using the I2C protocol.
21+
22+
Something that has been confusing to a lot of people is how to set up the Pozyx on Arduino, especially
23+
when multiple devices come into play.
24+
25+
And with the additional existence of the `Python library that provides direct USB access to the Pozyx <pypozyx.rtfd.io>`_,
26+
we have even seen people trying to use the Python library with an Arduino which had a
27+
Pozyx shield attached, which of course did not work.
28+
29+
In this section, we intend to give you insight of the hardware you need!
30+
31+
Pozyx on Arduino
32+
________________
33+
34+
The only Pozyx device that needs an Arduino is the one you're running the positioning/ranging sketches on.
35+
This device is called the master device, as this will also direct the operation of other Pozyx devices through
36+
UWB communication.
37+
38+
Remote Pozyx devices on Arduino
39+
_______________________________
40+
41+
Remote Pozyx tags don't need to have an Arduino attached! This is an important point. They just need to be powered.
42+
Phone powerbanks play well with the micro USB port on the tags!
43+
44+
Only perform positioning and ranging functions on your master device.
45+
46+
.. note::
47+
48+
You might want to have an Arduino on remote shields if you want to read their sensor data locally.
49+
However, do not use functions like positioning and ranging on multiple devices at the same time!
50+
51+
An example is the Cloud example where an Arduino is used to read the tag's position.
52+
In this example, the positioning is directed by the Pozyx attached to the server, and the Arduino
53+
checks the tag's status to see whether a new position has been calculated.
54+
55+
Pozyx via USB
56+
_______________
57+
58+
Instead of using an Arduino locally, you can skip the Arduino and use an USB cable directly.
59+
60+
This has advantages like:
61+
62+
* Very cross platform serial protocol.
63+
* Easy to use Python programming language for flexible functionality (and extendability).
64+
* Computer can be as powerful as you want.
65+
* You can implement the serial communication in any other programming language.
66+
67+
But disadvantages too:
68+
69+
* Arduino is very cheap and small standalone hardware, compared to a Raspberry Pi or regular PC.
70+
* The new Arduino Web IDE is amazing.
71+
* You're comfortable with Arduino programming but not with Python.
72+
73+
Ultimately, the decision which you want to use depends on your application and your
74+
available hardware.
75+
76+
The documentation for using USB directly can be found `here <pypozyx.rtfd.io>`_.
77+
78+
Required headers
79+
~~~~~~~~~~~~~~~~
80+
81+
To use the Pozyx library, you have to include the following headers:
82+
83+
.. code-block:: cpp
84+
85+
#include <Pozyx.h>
86+
#include <Pozyx_definitions.h>
87+
88+
89+
Connecting to the Pozyx
90+
~~~~~~~~~~~~~~~~~~~~~~~
91+
92+
Connecting with the Pozyx is very straightforward. A safe way is presented here:
93+
94+
.. code-block:: cpp
95+
96+
void setup(){
97+
Serial.begin(115200);
98+
if(Pozyx.begin() == POZYX_FAILURE){
99+
Serial.println(F("ERROR: Unable to connect to POZYX shield"));
100+
Serial.println(F("Reset required"));
101+
delay(100);
102+
abort();
103+
}
104+
}
105+
106+
With this, you initialize the Pozyx and can use the entire API in the rest of your script!
107+
108+
General philosophy
109+
~~~~~~~~~~~~~~~~~~
110+
111+
Essentially, you can do three things with Pozyx:
112+
113+
1. Reading register data, which includes sensors and the device's configuration
114+
2. Writing data to registers, making it possible to change the device's configuration ranging from its positioning algorithm to its very ID.
115+
3. Performing Pozyx functions like ranging, positioning, saving the device's configuration to its flash memory...
116+
117+
All these things are possible to do on the shield connected to your Arduino, and powered remote devices as well. In this section we'll go over all of these.
118+
119+
Reading data
120+
~~~~~~~~~~~~
121+
122+
To read data from the Pozyx, a simple pattern is followed. This pattern can be used with almost all methods starting with the words 'get':
123+
124+
1. Initialize the appropriate container for your data read.
125+
2. Pass this container along with the get functions.
126+
3. Check the status to see if the operation was successful and thus the data trustworthy.
127+
128+
You can see the same pattern in action above when reading the UWB data.
129+
130+
.. TODO An overview of all data containers, their usage and their particularities can be found here:
131+
132+
.. TODO also mention that they all have human readable __str__ conversions
133+
134+
.. code-block:: cpp
135+
136+
// initialize the data container
137+
uint8_t who_am_i;
138+
uint8_t status = Pozyx.getWhoAmI(&whoami);
139+
140+
// check the status to see if the read was successful. Handling failure is covered later.
141+
if (status == POZYX_SUCCESS) {
142+
// print the container. Note how a SingleRegister will print as a hex string by default.
143+
Serial.println(who_am_i); // will print '0x43'
144+
}
145+
146+
# and repeat
147+
# initialize the data container
148+
acceleration_t acceleration;
149+
# get the data, passing along the container
150+
Pozyx.getAcceleration_mg(&acceleration);
151+
152+
# initialize the data container
153+
euler_angles_t euler_angles;
154+
# get the data, passing along the container
155+
Pozyx.getEulerAngles_deg(&euler_angles)
156+
157+
158+
Writing data
159+
~~~~~~~~~~~~
160+
161+
Writing data follows a similar pattern as reading, but making a container for the data is optional. This pattern can be used with all methods starting with the words 'set':
162+
163+
1. (Optional) Initialize the appropriate container with the right contents for your data write.
164+
2. Pass this container or the right value along with the set functions.
165+
3. Check the status to see if the operation was successful and thus the data written.
166+
167+
Some typical write operations
168+
169+
.. code-block:: cpp
170+
171+
# initialize Pozyx as above
172+
173+
uint8_t status = Pozyx.setPositionAlgorithm(POZYX_POS_ALG_UWB_ONLY);
174+
// Note: this shouldn't ever happen when writing locally.
175+
if (status == POZYX_FAILURE) {
176+
Serial.println("Settings the positioning algorithm failed");
177+
}
178+
179+
Pozyx.setPositioningFilter(FILTER_TYPE_MOVING_AVERAGE, 10);
180+
181+
182+
Performing functions
183+
~~~~~~~~~~~~~~~~~~~~
184+
185+
Positioning, ranging, configuring the anchors for a tag to use... While the line is sometimes thin,
186+
these aren't per se writes or reads as they are implemented as functions on the Pozyx.
187+
188+
A Pozyx device function typically can take a container object for storing the function's
189+
return data, and a container object for the function parameters.
190+
191+
For example, when adding an anchor to a tag's device list, the anchor's ID and position
192+
are the function's parameters, but there is no return data. Thus, the function addDevice
193+
only needs a container object containing the anchor's properties.
194+
195+
In the library, function wrappers are written in such a way that when no parameters are
196+
required, they are hidden from the user, and the same goes for return data.
197+
198+
.. code-block:: cpp
199+
200+
// assume an anchor 0x6038 that we want to add to the device list and
201+
// immediately save the device list after.
202+
device_coordinates_t anchor;
203+
anchor.network_id = 0x6038;
204+
anchor.flag = 0x1;
205+
anchor.pos.x = 5000;
206+
anchor.pos.y = 5000;
207+
anchor.pos.z = 0;
208+
Pozyx.addDevice(anchor);
209+
210+
.. TODO find better example than positioning since that's a lie
211+
212+
Remote
213+
~~~~~~
214+
215+
To interface with a remote device, every function has a remote_id optional parameter. Thus, every function you just saw can be performed on a remote device as well!
216+
217+
(The exceptions are doPositioning and doRanging, which have doRemotePositioning and doRemoteRanging)
218+
219+
.. code-block:: cpp
220+
221+
// let's assume there is another tag present with ID 0x6039
222+
uint16_t remote_device_id = 0x6039;
223+
224+
// this will read the WHO_AM_I register of the remote tag
225+
uint8_t who_am_i;
226+
Pozyx.getWhoAmI(&whoami, remote_device_id);
227+
228+
229+
Saving writable register data
230+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231+
232+
Basically, every register you can write data to as a user can be saved in the device's flash memory. This means that when the device is powered on, its configuration will remain. Otherwise, the device will use its default values again.
233+
234+
.. TODO add default values for registers so that users know what to expect.
235+
236+
This is useful for multiple things:
237+
238+
* Saving the UWB settings so all your devices remain on the same UWB settings.
239+
* Saving the anchors the tag uses for positioning. This means that after a reset, the tag can resume positioning immediately and doesn't need to be reconfigured!
240+
* Saving positioning algorithm, dimension, filter... you'll never lose your favorite settings when the device shuts down.
241+
242+
There are various helpers in the library to help you save the settings you prefer, not requiring you to look up the relevant registers.
243+
244+
..
245+
.. code-block:: python
246+
# Saves the positioning settings
247+
pozyx.savePositioningSettings()
248+
# Saves the device list used for positioning
249+
pozyx.saveNetwork()
250+
# Saves the device's UWB settings
251+
pozyx.saveUWBSettings()
252+
253+
254+
Finding out the error
255+
~~~~~~~~~~~~~~~~~~~~~
256+
257+
Pozyx functions typically return a status to indicate the success of the function. This is useful to indicate failure especially. When things go wrong, it's advised to read the error as well.
258+
259+
A code snippet shows how this is typically done
260+
261+
..
262+
.. code-block:: python
263+
from pypozyx import PozyxSerial, get_first_pozyx_serial_port, POZYX_SUCCESS, SingleRegister
264+
# initialize Pozyx as above
265+
if pozyx.saveUWBSettings() != POZYX_SUCCESS:
266+
# this is one way which retrieves the error code
267+
error_code = SingleRegister()
268+
pozyx.getErrorCode(error_code)
269+
print('Pozyx error code: %s' % error_code)
270+
# the other method returns a descriptive string
271+
print(pozyx.getSystemError())

docs/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ Welcome to Pozyx Arduino Library's documentation!
1010
:maxdepth: 2
1111
:caption: Contents:
1212

13+
overview/index
14+
getting_started/index
15+
examples/index
16+
troubleshooting/index
1317
api/index
1418

docs/overview/index.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Arduino Pozyx
2+
=============
3+
4+
About
5+
-----
6+
7+
Arduino Pozyx is an Arduino library providing a high-level interface to a Pozyx shield attached to the Arduino,
8+
making the Pozyx shield compatible with Arduino Uno, Arduino Mega, and Arduino Nano.
9+
10+
11+
12+
Features
13+
--------
14+
15+
* Easy to use, allowing both high-level and low-level interfacing with the Pozyx device.
16+
* Straightforward API
17+
* Specialized structs for all important Pozyx data.
18+
* Compatible with Arduino Uno, Mega, and Nano.
19+
20+
Requirements
21+
------------
22+
23+
* Arduino Web IDE or Arduino IDE 1.6+
24+
25+
Installation
26+
------------
27+
28+
Web IDE
29+
~~~~~~~
30+
31+
When you're using the Web IDE, Arduino Pozyx should install automagically
32+
when you include ``<Pozyx.h>``.
33+
34+
Arduino Library Manager
35+
~~~~~~~~~~~~~~~~~~~~~~~
36+
37+
Currently, the Arduino Pozyx library is easily installable from the Arduino Library
38+
manager.
39+
40+
From source
41+
~~~~~~~~~~~
42+
43+
To install from source, you'll have to download the source files first and put them in
44+
your Arduino sketchbook libraries folder. You can do this either by:
45+
46+
* ``git clone https://github.com/pozyxLabs/Pozyx-Arduino-library`` and move the folder to your sketchbook libraries
47+
* Download it from `the repository <https://github.com/pozyxLabs/Pozyx-Arduino-library>`_ and extracting it.
48+
* Downloading the `zip file <https://github.com/pozyxLabs/Pozyx-Arduino-library/archive/master.zip>`_ directly, and extracting it.
49+

docs/system/index.rst

Whitespace-only changes.

docs/tips-and-tricks/index.rst

Whitespace-only changes.

docs/troubleshooting/index.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Troubleshooting
2+
===============
3+
4+
FAQ
5+
---
6+
7+
Lost a device?
8+
--------------
9+
10+
Contacting support
11+
------------------
12+
13+
If you want to contact support, please include the following:
14+
15+
* Run the pozyx_basic_troubleshooting.ino (provide link to github location of script) script and attach its output.
16+
* Mention what you want to achieve. Our support team has experience with many use cases and can set you on the right track.
17+
* If you get an error or exception, please include this in your mail instead of just saying something is broken.
18+
19+
Ultimately, the more information you can provide our support team from the start, the less they'll have to ask of you and the quicker your problem resolution.

docs/tutorials/index.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Tutorials
2+
=========
3+
4+
Ready to range
5+
--------------
6+
7+
8+
Ready to localize
9+
-----------------
10+
11+
12+
Obtaining the sensor data
13+
-------------------------
14+
15+
16+
Multitag positioning
17+
--------------------

0 commit comments

Comments
 (0)