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

Commit

Permalink
Merge pull request #244 from jtwhit/master
Browse files Browse the repository at this point in the history
[auton] Added program to control autonomy light.
  • Loading branch information
jtwhit authored May 29, 2019
2 parents 6fb6d2b + 9a42f67 commit f11e341
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions onboard/auton_light/project.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
lang=python
deps=rover_msgs,rover_common
executable=True
57 changes: 57 additions & 0 deletions onboard/auton_light/src/__main__.py
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()

0 comments on commit f11e341

Please sign in to comment.