Skip to content

Commit 25eec97

Browse files
authored
Merge pull request #289 from sourcebots/examples
Add examples
2 parents 3e06bdd + fb06913 commit 25eec97

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

docs/source/api/power-board.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,34 @@ the start.
102102
103103
This may be useful for debugging, but be sure to remove it in the
104104
competition, as you won't be allowed to touch the start button after a match has begun!
105+
106+
Example
107+
-------
108+
109+
.. code:: python
110+
111+
from sbot import *
112+
import time
113+
114+
r = Robot()
115+
116+
# Turn off output H0
117+
r.power_board.outputs[PowerOutputPosition.H0].is_enabled = False
118+
119+
120+
# Measure the current drawn by output H1
121+
amps = r.power_board.outputs[PowerOutputPosition.H1].current
122+
print(f"Current drawn by H1: {amps}")
123+
124+
125+
# Check the battery voltage
126+
volts = r.power_board.battery_sensor.voltage
127+
print(f"Battery voltage: {volts}")
128+
129+
130+
# Play a tune
131+
tune_notes = [Note.D6, Note.G6, Note.A6, Note.D7, Note.F7, Note.A7, Note.C8]
132+
note_length = 0.25 # 4 notes per second
133+
for note in tune_notes:
134+
r.power_board.piezo.buzz(note_length, note)
135+
time.sleep(note_length)

docs/source/api/servo-board.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,26 @@ widths which in some cases will force the servo to try and turn past its
6060
internal end-stops. You should experiment and find what the actual limit
6161
of your servos are (it almost certainly won't be -1 and 1) and not
6262
drive them past that.
63+
64+
Example
65+
-------
66+
67+
.. code:: python
68+
69+
from sbot import *
70+
import time
71+
72+
r = Robot()
73+
servos = r.servo_board.servos
74+
75+
# Move all servos to the middle position
76+
for servo in servos:
77+
servo.position = 0
78+
79+
80+
# Slowly sweep servo 0 to the end and disengage it
81+
for percentage in range(100):
82+
position = percentage / 100
83+
servos[0].position = position
84+
time.sleep(0.05)
85+
servos[0].position = None

0 commit comments

Comments
 (0)