Skip to content

Commit d55c0fa

Browse files
committed
Merge branch 'document-radio'
2 parents 8429d35 + f05dc74 commit d55c0fa

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

_data/sidebar_tree.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ tree:
7171
title: Motors
7272
- url: /programming/sr/power/
7373
title: Power
74+
- url: /programming/sr/radio/
75+
title: Radio
7476
- url: /programming/sr/ruggeduinos/
7577
title: Ruggeduinos
7678
tree:

programming/sr/radio/index.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
layout: page
3+
title: Radio
4+
---
5+
6+
# Radio
7+
8+
<div class="info">
9+
This documentation refers to a feature which is only available within the simulator.
10+
</div>
11+
12+
The `sr.robot` library contains support for using a simulated radio unit on the robot.
13+
Radio transmitters and receivers are attached to various items in the Student Robotics arena.
14+
Each transmitter encodes their identity in a machine-readable way, which means that receivers can identify these objects.
15+
16+
## [Detecting other stations](#detecting-other-stations) {#detecting-other-stations}
17+
18+
Using the signal strength and bearing of the received radio signals, you are able to
19+
determine the distance and direction of a transmitter in 2D space relative to
20+
the radio. Therefore, if the robot can detect transmitters that is at a fixed
21+
location in the arena, a robot can calculate its exact position in the arena.
22+
23+
The `sr.robot` library provides this through a `radio` attached to your `Robot`,
24+
which is can perform a `sweep` to detect transmitters:
25+
26+
~~~~~ python
27+
from sr.robot import *
28+
R = Robot()
29+
transmitters = R.radio.sweep()
30+
~~~~~
31+
32+
When called, the `sweep` function uses the radio reciever to scan for nearby transmitters.
33+
It returns a list of `Target` objects, each of which describes one of the transmitters that were found within range.
34+
A detailed description of the attributes of `Target` objects is provided [later in this page](#Target).
35+
36+
Here's an example that will repeatedly print out the bearing and signal stength of each arena transmitter in range:
37+
38+
~~~~~ python
39+
from sr.robot import *
40+
R = Robot()
41+
42+
while True:
43+
transmitters = R.radio.sweep()
44+
print("I found", len(transmitters), "transmitter(s):")
45+
46+
for tx in transmitters:
47+
print(" - Transmitter {0} Bearing: {1} with a signal strength of {2}".format(
48+
tx.target_info.station_code,
49+
tx.bearing,
50+
tx.signal_strength,
51+
))
52+
~~~~~
53+
54+
<!-- TODO: radio tranmission here -->
55+
56+
## [Objects of the Radio System](#radio_objects) {#radio_objects}
57+
58+
### [`Target`](#Target) {#Target}
59+
60+
A `Target` object contains information about a _detected_ transmitter.
61+
It has the following attributes:
62+
63+
target_info
64+
: A [`TargetInfo`](#TargetInfo) object containing information about the transmitter that was detected.
65+
66+
signal_strength
67+
: The measured strength of the signal as a float.
68+
69+
bearing
70+
: A float giving the angle to the `Target` in radians.
71+
<br>
72+
A bearing of `0` is in front of the robot. Positive bearings are to the robot's right.
73+
74+
### [`TargetInfo`](#TargetInfo) {#TargetInfo}
75+
76+
The `TargetInfo` object contains information about a transmitter.
77+
It has the following attributes:
78+
79+
station_code
80+
: The two character identifier of the transmitter.
81+
Valid values are members of the `StationCode` enum.
82+
~~~~~ python
83+
from sr.robot import StationCode
84+
85+
for station in StationCode:
86+
print(station)
87+
~~~~~
88+
89+
owned_by
90+
: The zone id of the robot that currently owns the stations territory. A `None` value indicates an unclaimed territory.
91+
<br>
92+
Remember that you can find out which zone your robot is in using <a href="/docs/programming/sr/#OtherRobotAttributes"><code>R.zone</code></a>.

0 commit comments

Comments
 (0)