Skip to content

Commit 8977e3f

Browse files
committed
libs/unit/uwb.py: Refactor the UWB Unit.
Signed-off-by: lbuque <[email protected]>
1 parent bea785d commit 8977e3f

File tree

8 files changed

+872
-92
lines changed

8 files changed

+872
-92
lines changed

docs/en/refs/unit.uwb.ref

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
.. |UWBUnit| image:: https://static-cdn.m5stack.com/resource/docs/products/unit/uwb/uwb_01.webp
3+
:target: https://docs.m5stack.com/en/unit/uwb
4+
:height: 200px
5+
:width: 200px
6+
7+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/init.png
8+
.. |get_distance.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/get_distance.png
9+
.. |get_device_id.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/get_device_id.png
10+
.. |get_device_mode.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/get_device_mode.png
11+
.. |set_device_mode.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/set_device_mode.png
12+
.. |isconnected.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/isconnected.png
13+
.. |get_version.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/get_version.png
14+
.. |reset.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/reset.png
15+
.. |_extract_text.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/_extract_text.png
16+
.. |set_measurement_interval.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/set_measurement_interval.png
17+
.. |set_measurement.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/set_measurement.png
18+
.. |at_cmd_send.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/at_cmd_send.png
19+
.. |set_callback.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/set_callback.png
20+
.. |update.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/update.png
21+
22+
.. |example_anchor.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/example_anchor.png
23+
24+
.. |example_tag.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/uwb/example_tag.png
25+
26+
.. |core2_uwb_anchor_example.m5f2| raw:: html
27+
28+
<a
29+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/uwb/core2_uwb_anchor_example.m5f2"
30+
target="_blank"
31+
>
32+
core2_uwb_anchor_example.m5f2
33+
</a>
34+
35+
.. |stickc_plus2_uwb_tag_example.m5f2| raw:: html
36+
37+
<a
38+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/uwb/stickc_plus2_uwb_tag_example.m5f2"
39+
target="_blank"
40+
>
41+
stickc_plus2_uwb_tag_example.m5f2
42+
</a>

docs/en/units/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Unit
7575
tof.rst
7676
uhf_rfid.rst
7777
ultrasonic.rst
78+
uwb.rst
7879
vibrator.rst
7980
watering.rst
8081
weight_i2c.rst

docs/en/units/uwb.rst

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
2+
UWBUnit
3+
=======
4+
5+
.. include:: ../refs/unit.uwb.ref
6+
7+
UWB is a Unit which integrates the UWB(Ultra Wide Band) communication protocol which uses nanosecond pulses to locate objects and define position and orientation. The design uses the Ai-ThinkerBU01 Transceiver module which is based on Decawave's DW1000 design. The internal STM32 chip with its integrated ranging algorithm,is capable of 10cm positioning accuracy and also supports AT command control. Applications include: Indoor wireless tracking/range finding of assets,which works by triangulating the position of the base station/s and tag (the base station resolves the position information and outputs it to the tag).
8+
The firmware currently carried by this Unit only supports the transmission of ranging information, and does not currently support the transmission of custom information. When in use, it supports the configuration of 4 base station devices (using different IDs), and only a single tag device is allowed to operate at the same time.
9+
10+
11+
Support the following products:
12+
13+
|UWBUnit|
14+
15+
Micropython Anchor Example:
16+
17+
.. literalinclude:: ../../../examples/unit/uwb/core2_uwb_anchor_example.py
18+
:language: python
19+
:linenos:
20+
21+
Micropython Tag Example:
22+
23+
.. literalinclude:: ../../../examples/unit/uwb/stickc_plus2_uwb_tag_example.py
24+
:language: python
25+
:linenos:
26+
27+
28+
UIFLOW2 Anchor Example:
29+
30+
|example_anchor.png|
31+
32+
UIFLOW2 Tag Example:
33+
34+
|example_tag.png|
35+
36+
.. only:: builder_html
37+
38+
|core2_uwb_anchor_example.m5f2|
39+
40+
|stickc_plus2_uwb_tag_example.m5f2|
41+
42+
class UWBUnit
43+
-------------
44+
45+
Constructors
46+
------------
47+
48+
.. class:: UWBUnit(id, port, device_mode, device_id, verbose)
49+
50+
Create a UWB unit object.
51+
52+
:param id: UART ID.
53+
:param port: The port that the unit is connected to.
54+
:param device_mode: device mode.
55+
:param device_id: device ID.
56+
:param bool verbose: verbose output.
57+
58+
UIFLOW2:
59+
60+
|init.png|
61+
62+
63+
Methods
64+
-------
65+
66+
.. method:: UWBUnit.get_distance(index)
67+
68+
Get the distance to the anchor ID (0 ~ 3).
69+
70+
:return (float): distance in meters.
71+
:param int index: anchor ID (0 ~ 3).
72+
73+
UIFLOW2:
74+
75+
|get_distance.png|
76+
77+
.. method:: UWBUnit.get_device_id()
78+
79+
Get the device ID.
80+
81+
:return (int): device ID.
82+
83+
UIFLOW2:
84+
85+
|get_device_id.png|
86+
87+
.. method:: UWBUnit.get_device_mode()
88+
89+
Get the device mode.
90+
91+
:return (int): device mode.
92+
93+
UIFLOW2:
94+
95+
|get_device_mode.png|
96+
97+
.. method:: UWBUnit.set_device_mode(mode, id)
98+
99+
Set the device mode and ID.
100+
101+
:param int mode: device mode.
102+
Options:
103+
- ``Anchor``: UWBUnit.ANCHOR
104+
- ``Tag``: UWBUnit.TAG
105+
:param int id: device ID.
106+
107+
UIFLOW2:
108+
109+
|set_device_mode.png|
110+
111+
.. method:: UWBUnit.isconnected()
112+
113+
Check if the UWB unit is connected.
114+
115+
:return: True if connected, False otherwise.
116+
117+
UIFLOW2:
118+
119+
|isconnected.png|
120+
121+
.. method:: UWBUnit.get_version()
122+
123+
Get the UWB unit firmware version.
124+
125+
:return: firmware version.
126+
127+
UIFLOW2:
128+
129+
|get_version.png|
130+
131+
.. method:: UWBUnit.reset()
132+
133+
Reset the UWB unit.
134+
135+
.. method:: UWBUnit.set_measurement_interval(interval)
136+
137+
Set the measurement interval.
138+
139+
:param int interval: measurement interval.
140+
141+
UIFLOW2:
142+
143+
|set_measurement_interval.png|
144+
145+
.. method:: UWBUnit.set_measurement(enable)
146+
147+
Set the measurement output.
148+
149+
:param bool enable: enable or disable measurement output.
150+
151+
UIFLOW2:
152+
153+
|set_measurement.png|
154+
155+
.. method:: UWBUnit.set_callback(anchor, event, callback)
156+
157+
Set the callback function for the anchor status.
158+
159+
:param int anchor: anchor ID (0 ~ 3).
160+
:param int event: anchor status.
161+
Options:
162+
- ``ONLINE``: UWBUnit.ONLINE
163+
- ``OFFLINE``: UWBUnit.OFFLINE
164+
:param callback: callback function.
165+
166+
UIFLOW2:
167+
168+
|set_callback.png|
169+
170+
.. method:: UWBUnit.update()
171+
172+
Update the distances and anchor status.
173+
174+
UIFLOW2:
175+
176+
|update.png|
177+
178+
179+
180+
Constants
181+
---------
182+
183+
.. data:: UWBUnit.UNKNOWN
184+
.. data:: UWBUnit.ANCHOR
185+
.. data:: UWBUnit.TAG
186+
187+
device role
188+
189+
190+
.. data:: UWBUnit.OFFLINE
191+
.. data:: UWBUnit.ONLINE
192+
.. data:: UWBUnit._mode_map
193+
194+
device status
195+
196+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"V2.0","versionNumber":"V2.1.6","type":"stickc-plus2","components":[{"name":"screen","type":"screen","layer":0,"screenId":"builtin","screenName":"","id":"__stickc-plus2_screen","createTime":1730193842205,"x":0,"y":0,"width":135,"height":240,"backgroundColor":"#000000","size":0,"isSelected":true},{"name":"label0","type":"label","layer":1,"screenId":"builtin","screenName":"","id":"kS!fatSHiT!az1aV","createTime":1730347329701,"x":29,"y":36,"color":"#ffffff","backgroundColor":"#222222","text":"label0","engine":"gfx","font":"Widgets.FONTS.DejaVu24","rotation":0,"isSelected":false,"width":76,"height":28},{"name":"label1","type":"label","layer":2,"screenId":"builtin","screenName":"","id":"e1DM86gJW1CyY2L+","createTime":1730347366455,"x":44,"y":98,"color":"#ffffff","backgroundColor":"#222222","text":"0","engine":"gfx","font":"Widgets.FONTS.DejaVu72","rotation":0,"isSelected":false,"width":46,"height":82}],"resources":[{"hardware":["hardware_button","hardware_pin_button","imu","speaker","ir"]},{"unit":["unit_uwb"]}],"units":[{"type":"unit_uwb","name":"uwb_0","portList":["A","B","C","Custom"],"portType":"A","userPort":[22,21],"id":"wq&#vJ&koZE@^zfm","createTime":1730344044442}],"hats":[],"bases":[],"i2cs":[],"blockly":"<variables><variable id=\"T8s9UNT5^y?dX3U~5cg^\">anchor_id</variable></variables><block type=\"basic_on_setup\" id=\"setup_block\" deletable=\"false\" x=\"50\" y=\"130\"><mutation isBegin=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_begin\" id=\"system_m5_begin\"><next><block type=\"variables_set\" id=\"S$]E#@jpynr?KEX+;#)V\"><field name=\"VAR\" id=\"T8s9UNT5^y?dX3U~5cg^\">anchor_id</field><value name=\"VALUE\"><block type=\"math_number\" id=\"yVm.0,gX%|QLXw@,IAlA\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">0</field></block></value><next><block type=\"unit_uwb_init\" id=\"l?Z-Mt/:=}pA__5xI+U#\"><mutation mode=\"anchor\"></mutation><field name=\"NAME\">uwb_0</field><field name=\"MODE\">anchor</field><field name=\"VERBOSE\">False</field><value name=\"UART\"><shadow type=\"unit_uwb_id_option\" id=\"L_P1lWwVsGtGvNA(OKGq\"><field name=\"VALUE\">2</field></shadow></value><value name=\"ID\"><shadow type=\"math_slider\" id=\"os*@nftr+uU)%2Vy{sN`\"><mutation max=\"3\" min=\"0\" step=\"1\" precision=\"1\"></mutation><field name=\"NUM\">0</field></shadow></value><next><block type=\"text_print\" id=\"3dTe7EVevm!T1qziE:TN\"><value name=\"TEXT\"><shadow type=\"text\" id=\".U$~maX2:CS.h7UGM%J0\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"unit_uwb_isconnected\" id=\"1Ilr{.5D_]$V!aw~|/-m\"><field name=\"NAME\">uwb_0</field></block></value><next><block type=\"text_print\" id=\".r/va~JId_QFI2[GY(/a\"><value name=\"TEXT\"><shadow type=\"text\" id=\".U$~maX2:CS.h7UGM%J0\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"unit_uwb_get_version\" id=\"dR~e.dW6T1)L2$V_}xu^\"><field name=\"NAME\">uwb_0</field></block></value><next><block type=\"controls_ifelse\" id=\"Ojlibonp.)KD:cH0h.bw\"><value name=\"IF0\"><block type=\"logic_compare\" id=\"9Vt2j.Ll5CA*1-A~WDHy\"><field name=\"OP\">EQ</field><value name=\"A\"><block type=\"unit_uwb_get_device_mode\" id=\")f6Q@DG02YrES(]!i@tu\"><field name=\"NAME\">uwb_0</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"yBCte7CqdfYa.L14ljg~\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></block></value></block></value><statement name=\"DO0\"><block type=\"label_set_text\" id=\"QCkkrD1J4(2#c)@ao|94\"><field name=\"NAME\">label0</field><value name=\"TEXT\"><shadow type=\"text\" id=\"dNgYG$TS]CM?h#aq#]PF\"><field name=\"TEXT\">Anchor</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"label_set_text\" id=\"e_H3b=J_/UdQDBpZfPyk\"><field name=\"NAME\">label0</field><value name=\"TEXT\"><shadow type=\"text\" id=\"xAH+VX~Fn@8U,@6.@HN?\"><field name=\"TEXT\">Tag</field></shadow></value></block></statement><next><block type=\"label_set_text\" id=\"aLo~3.;NE(6l%oPM]CIa\"><field name=\"NAME\">label1</field><value name=\"TEXT\"><shadow type=\"text\" id=\";8)L(!fF8(y.9n~l8[FC\"><field name=\"TEXT\">Label</field></shadow><block type=\"unit_uwb_get_device_id\" id=\"4t))mp3g|Uth_1Y(ApPc\"><field name=\"NAME\">uwb_0</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block><block type=\"basic_on_loop\" id=\"loop_block\" deletable=\"false\" x=\"70\" y=\"650\"><mutation isUpdate=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_update\" id=\"system_m5_update\"></block></statement></block><block type=\"button_callback\" id=\"vD0yF+W?3f:#~L86,gxB\" x=\"50\" y=\"810\"><field name=\"NAME\">BtnA</field><field name=\"TYPE\">WAS_CLICKED</field><statement name=\"FUNC\"><block type=\"variables_set\" id=\"Pl5u[c_qq,.U0P3ZR-zf\"><field name=\"VAR\" id=\"T8s9UNT5^y?dX3U~5cg^\">anchor_id</field><value name=\"VALUE\"><block type=\"math_arithmetic\" id=\"*p7AM(5O(YhIM4/RY#d}\"><field name=\"OP\">REMAINDER</field><value name=\"A\"><shadow type=\"math_number\" id=\":9svC$F.VvBITGBx^^6!\" disabled=\"true\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></shadow><block type=\"math_arithmetic\" id=\"7xjEo/EeL9hIfD^$MsB}\"><field name=\"OP\">ADD</field><value name=\"A\"><shadow type=\"math_number\" id=\"#W,z3^mvKL}d{),}fwI$\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></shadow><block type=\"variables_get\" id=\"_hh;s3juU/F-u@aXr9Y?\"><field name=\"VAR\" id=\"T8s9UNT5^y?dX3U~5cg^\">anchor_id</field></block></value><value name=\"B\"><shadow type=\"math_number\" id=\"l`iYBe%ZZnka!eeOV{S=\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></shadow></value></block></value><value name=\"B\"><shadow type=\"math_number\" id=\"Oy6gNP`*gX,CAnQP8;Kr\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">4</field></shadow></value></block></value><next><block type=\"unit_uwb_set_device_mode\" id=\"018osu3]OFaeFI#v|Yan\"><mutation mode=\"anchor\"></mutation><field name=\"NAME\">uwb_0</field><field name=\"OPTION\">anchor</field><value name=\"ID\"><shadow type=\"math_slider\" id=\"I?zD!y2)T(*9Uw7}yod/\"><mutation max=\"3\" min=\"0\" step=\"1\" precision=\"1\"></mutation><field name=\"NUM\">2</field></shadow><block type=\"variables_get\" id=\"JU8{e@NkmS%mVCdECa1_\"><field name=\"VAR\" id=\"T8s9UNT5^y?dX3U~5cg^\">anchor_id</field></block></value><next><block type=\"label_set_text\" id=\"U5e`c697{!:8]//W|`KG\"><field name=\"NAME\">label1</field><value name=\"TEXT\"><shadow type=\"text\" id=\";8)L(!fF8(y.9n~l8[FC\"><field name=\"TEXT\">Label</field></shadow><block type=\"unit_uwb_get_device_id\" id=\"#l5!}bWD$}@mC5WmA~.{\"><field name=\"NAME\">uwb_0</field></block></value></block></next></block></next></block></statement></block>","screen":[{"simulationName":"Built-in","type":"builtin","width":135,"height":240,"scale":0.92,"screenName":"","blockId":"","screenColorType":0,"id":"builtin","createTime":1730193842203}],"logicWhenNum":0,"customList":[]}

0 commit comments

Comments
 (0)