-
-
Save marcmerlin/a3bba2231a3371266e595aa0e6028b77 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
test -e /tmp/leds || mkfifo -m666 /tmp/leds | |
sudo /home/pi/env/bin/python /home/pi/leds.py |
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
#!/usr/bin/env python | |
# https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage | |
# Simple test for NeoPixels on Raspberry Pi | |
import board | |
import errno | |
import neopixel | |
import os | |
import time | |
PATH="/tmp/leds" | |
bufferSize = 100; | |
# Choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D18 | |
# NeoPixels must be connected to D10, D12, D18 or D21 to work. | |
pixel_pin = board.D18 | |
# The number of NeoPixels | |
num_pixels = 18 | |
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed! | |
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW. | |
ORDER = neopixel.GRB | |
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.2, auto_write=False, | |
pixel_order=ORDER) | |
def wheel(pos): | |
# Input a value 0 to 255 to get a color value. | |
# The colours are a transition r - g - b - back to r. | |
if pos < 0 or pos > 255: | |
r = g = b = 0 | |
elif pos < 85: | |
r = int(pos * 3) | |
g = int(255 - pos*3) | |
b = 0 | |
elif pos < 170: | |
pos -= 85 | |
r = int(255 - pos*3) | |
g = 0 | |
b = int(pos*3) | |
else: | |
pos -= 170 | |
r = 0 | |
g = int(pos*3) | |
b = int(255 - pos*3) | |
return (r, g, b) if ORDER == neopixel.RGB or ORDER == neopixel.GRB else (r, g, b, 0) | |
def rainbow_cycle(wait): | |
for j in range(255): | |
for i in range(num_pixels): | |
pixel_index = (i * 256 // num_pixels) + j | |
pixels[i] = wheel(pixel_index & 255) | |
pixels.show() | |
time.sleep(wait) | |
hue = 0 | |
def cylon(wait): | |
global hue | |
for i in list(range(0, num_pixels)) + list(range(num_pixels-1, 0, -1)): | |
pixels[i] = wheel(hue) | |
hue += 1 | |
if hue > 255: | |
hue = 0 | |
pixels.show() | |
pixels[i] = 0 | |
time.sleep(wait) | |
timer = 30 | |
demo = 'cylon' | |
pipe = os.open(PATH, os.O_RDONLY | os.O_NONBLOCK); | |
while True: | |
mode = '' | |
try: | |
input = os.read(pipe,bufferSize); | |
except OSError as err: | |
if err.errno == 11: | |
continue; | |
else: | |
raise err; | |
if input: | |
mode = input | |
print("Received " + str(input)) | |
if mode == b'r': | |
pixels.fill((255, 0, 0)) | |
pixels.show() | |
timer = 60 | |
print("Switching to red") | |
if mode == b'g': | |
pixels.fill((0, 255, 0)) | |
pixels.show() | |
timer = 60 | |
print("Switching to green") | |
if mode == b'b': | |
pixels.fill((0, 0, 255)) | |
pixels.show() | |
timer = 60 | |
print("Switching to blue") | |
if mode == b'cylon': | |
demo = 'cylon' | |
print("Switching to cylon") | |
if mode == b'rainbow': | |
demo = 'rainbow' | |
print("Switching to rainbow") | |
else: | |
if timer == 0: | |
if demo == 'rainbow': | |
rainbow_cycle(0.001) | |
else: | |
cylon(0.03) | |
time.sleep(0.1) | |
if timer > 0: | |
timer -= 1 | |
# vim:sts=4:sw=4 |
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
--- manage.py.orig 2018-06-11 08:14:34.079999106 +0000 | |
+++ manage.py 2019-01-23 04:33:56.403501447 +0000 | |
@@ -122,6 +122,9 @@ | |
tub = TubWriter(path=cfg.TUB_PATH, inputs=inputs, types=types) | |
V.add(tub, inputs=inputs, run_condition='recording') | |
+ with open("/tmp/leds", "w") as fifo: | |
+ fifo.write("g") | |
+ | |
# run the vehicle | |
V.start(rate_hz=cfg.DRIVE_LOOP_HZ, | |
max_loop_count=cfg.MAX_LOOPS) | |
@@ -169,6 +172,8 @@ | |
cfg = dk.load_config() | |
if args['drive']: | |
+ with open("/tmp/leds", "w") as fifo: | |
+ fifo.write("b") | |
drive(cfg, model_path=args['--model'], use_chaos=args['--chaos']) | |
elif args['train']: |
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
#!/bin/sh -e | |
# | |
# rc.local | |
# | |
# This script is executed at the end of each multiuser runlevel. | |
# Make sure that the script will "exit 0" on success or any other | |
# value on error. | |
# | |
# In order to enable or disable this script just change the execution | |
# bits. | |
# | |
# By default this script does nothing. | |
# Print the IP address | |
_IP=$(hostname -I) || true | |
if [ "$_IP" ]; then | |
printf "My IP address is %s\n" "$_IP" | |
fi | |
/home/pi/leds & | |
su - pi -c 'cd ~/ohmc_car; /home/pi/env/bin/python manage.py drive &>/tmp/out' & | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment