Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Commit f11e341

Browse files
authored
Merge pull request #244 from jtwhit/master
[auton] Added program to control autonomy light.
2 parents 6fb6d2b + 9a42f67 commit f11e341

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

onboard/auton_light/project.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[build]
2+
lang=python
3+
deps=rover_msgs,rover_common
4+
executable=True
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import lcm
2+
from pathlib import Path
3+
from rover_msgs import AutonState
4+
5+
6+
gpio_pin = '397'
7+
autonomy_on = False
8+
gpio_path = Path('/sys/class/gpio/gpio{}'.format(gpio_pin))
9+
export_file = Path('/sys/class/gpio/export')
10+
unexport_file = Path('/sys/class/gpio/unexport')
11+
12+
13+
def export_pin():
14+
global gpio_pin, export_file, gpio_path
15+
export_file.write_text(gpio_pin)
16+
(gpio_path / 'direction').write_text('out')
17+
18+
19+
def unexport_pin():
20+
global gpio_pin, unexport_file
21+
try:
22+
unexport_file.write_text(gpio_pin)
23+
except OSError:
24+
pass
25+
26+
27+
def write_gpio(value):
28+
global gpio_path
29+
30+
(gpio_path / 'value').write_text(value)
31+
32+
33+
def auton_state_callback(channel, msg):
34+
global autonomy_on
35+
36+
auton_msg = AutonState.decode(msg)
37+
if auton_msg.is_auton and not autonomy_on:
38+
write_gpio('1')
39+
autonomy_on = True
40+
elif not auton_msg.is_auton and autonomy_on:
41+
write_gpio('0')
42+
autonomy_on = False
43+
44+
45+
def main():
46+
unexport_pin()
47+
export_pin()
48+
write_gpio('0')
49+
50+
lc = lcm.LCM()
51+
lc.subscribe('/auton', auton_state_callback)
52+
53+
try:
54+
while True:
55+
lc.handle()
56+
except KeyboardInterrupt:
57+
unexport_pin()

0 commit comments

Comments
 (0)