This repository has been archived by the owner on May 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from jtwhit/master
[auton] Added program to control autonomy light.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[build] | ||
lang=python | ||
deps=rover_msgs,rover_common | ||
executable=True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import lcm | ||
from pathlib import Path | ||
from rover_msgs import AutonState | ||
|
||
|
||
gpio_pin = '397' | ||
autonomy_on = False | ||
gpio_path = Path('/sys/class/gpio/gpio{}'.format(gpio_pin)) | ||
export_file = Path('/sys/class/gpio/export') | ||
unexport_file = Path('/sys/class/gpio/unexport') | ||
|
||
|
||
def export_pin(): | ||
global gpio_pin, export_file, gpio_path | ||
export_file.write_text(gpio_pin) | ||
(gpio_path / 'direction').write_text('out') | ||
|
||
|
||
def unexport_pin(): | ||
global gpio_pin, unexport_file | ||
try: | ||
unexport_file.write_text(gpio_pin) | ||
except OSError: | ||
pass | ||
|
||
|
||
def write_gpio(value): | ||
global gpio_path | ||
|
||
(gpio_path / 'value').write_text(value) | ||
|
||
|
||
def auton_state_callback(channel, msg): | ||
global autonomy_on | ||
|
||
auton_msg = AutonState.decode(msg) | ||
if auton_msg.is_auton and not autonomy_on: | ||
write_gpio('1') | ||
autonomy_on = True | ||
elif not auton_msg.is_auton and autonomy_on: | ||
write_gpio('0') | ||
autonomy_on = False | ||
|
||
|
||
def main(): | ||
unexport_pin() | ||
export_pin() | ||
write_gpio('0') | ||
|
||
lc = lcm.LCM() | ||
lc.subscribe('/auton', auton_state_callback) | ||
|
||
try: | ||
while True: | ||
lc.handle() | ||
except KeyboardInterrupt: | ||
unexport_pin() |