Skip to content

Commit f5b5e8e

Browse files
committed
Updated range tutorial to reflect changes with the protocol
1 parent 574af81 commit f5b5e8e

4 files changed

Lines changed: 48 additions & 30 deletions

File tree

pypozyx/definitions/bitmasks.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
POZYX_INT_MASK_PIN = 0x80
2727
POZYX_INT_MASK_ALL = 0x1F
2828

29-
# Bit mask for POZYX_RANGE_PROTOCOL
30-
POZYX_RANGE_PROTOCOL_PRECISION = 0x00
31-
POZYX_RANGE_PROTOCOL_FAST = 0x01
32-
POZYX_RANGE_PROTOCOL_TEST = 0x02
33-
3429
# Bit mask for POZYX_LED_CTRL
3530
POZYX_LED_CTRL_LED1 = 0x01
3631
POZYX_LED_CTRL_LED2 = 0x02

pypozyx/definitions/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
POZYX_POS_ALG_UWB_ONLY = 0
6262
POZYX_POS_ALG_TRACKING = 4
6363

64+
# ranging protocol options
65+
POZYX_RANGE_PROTOCOL_PRECISION = 0x00
66+
POZYX_RANGE_PROTOCOL_FAST = 0x01
67+
POZYX_RANGE_PROTOCOL_TEST = 0x02
68+
6469
# positioning filters
6570
FILTER_TYPE_NONE = 0
6671
FILTER_TYPE_FIR = 1

pypozyx/lib.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,40 @@ def getUpdateInterval(self, ms, remote_id=None):
547547
"""
548548
return self.getRead(POZYX_POS_INTERVAL, ms, remote_id)
549549

550+
def getRangingProtocol(self, protocol, remote_id=None):
551+
"""
552+
Obtains the Pozyx's ranging protocol
553+
554+
Args:
555+
protocol: Container for the read protocol data. SingleRegister or Data([0])
556+
557+
Kwargs:
558+
remote_id: Remote Pozyx ID
559+
560+
Returns:
561+
POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT
562+
"""
563+
return self.getRead(POZYX_RANGE_PROTOCOL, protocol, remote_id)
564+
565+
def setRangingProtocol(self, protocol, remote_id=None):
566+
"""
567+
Set the Pozyx's ranging protocol.
568+
569+
Args:
570+
protocol: the new ranging protocol. See POZYX_RANGE_PROTOCOL register. integer or SingleRegister(protocol)
571+
572+
Kwargs:
573+
remote_id: Remote Pozyx ID
574+
575+
Returns:
576+
POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT
577+
"""
578+
if not dataCheck(protocol):
579+
protocol = SingleRegister(protocol)
580+
assert protocol[0] >= 0 and protocol[0] <=2, 'setRangingProtocol: wrong protocol %i' % protocol[0]
581+
582+
return self.setWrite(POZYX_RANGE_PROTOCOL, protocol, remote_id)
583+
550584
def getPositionAlgorithm(self, algorithm, remote_id=None):
551585
"""
552586
Obtains the Pozyx's positioning algorithm.
@@ -736,26 +770,6 @@ def setUpdateInterval(self, ms, remote_id=None):
736770
0] <= 600000, 'setUpdateInterval: ms not 100<ms<60000'
737771
return self.setWrite(POZYX_POS_INTERVAL, ms, remote_id)
738772

739-
def setOperationMode(self, mode, remote_id=None):
740-
"""
741-
Set the Pozyx's operation mode.
742-
743-
Args:
744-
mode: New operation mode. See POZYX_OPERATION_MODE register. integer mode or SingleRegister(mode).
745-
746-
Kwargs:
747-
remote_id: Remote Pozyx ID.
748-
749-
Returns:
750-
POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT
751-
"""
752-
if not dataCheck(mode):
753-
mode = SingleRegister(mode)
754-
assert mode[0] == POZYX_ANCHOR_MODE or mode[
755-
0] == POZYX_TAG_MODE, 'setOperationMode: wrong mode'
756-
757-
return self.setWrite(POZYX_OPERATION_MODE, mode, remote_id)
758-
759773
def setCoordinates(self, coordinates, remote_id=None):
760774
"""
761775
Set the Pozyx's coordinates.

tutorials/ready_to_range.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
The Pozyx ready to range tutorial (c) Pozyx Labs
44
Please read the tutorial that accompanies this sketch: https://www.pozyx.io/Documentation/Tutorials/ready_to_range/Python
55
6-
This demo requires two Pozyx devices and one Arduino. It demonstrates the ranging capabilities and the functionality to
7-
to remotely control a Pozyx device. Place one of the Pozyx shields on the Arduino and upload this sketch. Move around
8-
with the other Pozyx device.
6+
This demo requires two Pozyx devices. It demonstrates the ranging capabilities and the functionality to
7+
to remotely control a Pozyx device. Move around with the other Pozyx device.
98
109
This demo measures the range between the two devices. The closer the devices are to each other, the more LEDs will
1110
light up on both devices.
@@ -16,11 +15,12 @@
1615
class ReadyToRange(object):
1716
"""Continuously performs ranging between the Pozyx and a destination and sets their LEDs"""
1817

19-
def __init__(self, pozyx, destination_id, range_step_mm=1000, remote_id=None):
18+
def __init__(self, pozyx, destination_id, range_step_mm=1000, protocol=POZYX_RANGE_PROTOCOL_FAST, remote_id=None):
2019
self.pozyx = pozyx
2120
self.destination_id = destination_id
2221
self.range_step_mm = range_step_mm
2322
self.remote_id = remote_id
23+
self.protocol = protocol
2424

2525
def setup(self):
2626
"""Sets up both the ranging and destination Pozyx's LED configuration"""
@@ -41,6 +41,8 @@ def setup(self):
4141
self.pozyx.setLedConfig(led_config, self.remote_id)
4242
# do the same for the destination.
4343
self.pozyx.setLedConfig(led_config, self.destination_id)
44+
# set the ranging protocol
45+
self.pozyx.setRangingProtocol(self.protocol)
4446

4547
def loop(self):
4648
"""Performs ranging and sets the LEDs accordingly"""
@@ -76,8 +78,10 @@ def ledControl(self, distance):
7678
destination_id = 0x6069 # network ID of the ranging destination
7779
range_step_mm = 1000 # distance that separates the amount of LEDs lighting up.
7880

81+
ranging_protocol = POZYX_RANGE_PROTOCOL_PRECISION # the ranging protocol
82+
7983
pozyx = PozyxSerial(port)
80-
r = ReadyToRange(pozyx, destination_id, range_step_mm, remote_id)
84+
r = ReadyToRange(pozyx, destination_id, range_step_mm, ranging_protocol, remote_id)
8185
r.setup()
8286
while True:
8387
r.loop()

0 commit comments

Comments
 (0)