Commit 1d2370e5 authored by Federico Meloda's avatar Federico Meloda

fixed audioinit

parents c4cc304e 3b86770b
servo_control: servo_control.c
$(CC) -o $@ $^ -lwiringPi -lpthread
sudo chown root $@
sudo chmod u+x $@
sudo chown root $@
import krpc
import zmq
import argparse
class ModelRocket:
socket = None
realRocket = None
topic = "events"
states = { -1:"abort", 0:"pre_launch",1:"liftoff", 2:"stage_1_separation", 3:"stage_2_separation"}
stage_map = {0:0,1:1,2:2,3:3}
def send(self,stage):
self.socket.send("%d %d" % (self.topic, self.stage_map[stage]))
def __init__(self,addr="localhost:5556"):
context = zmq.Context()
self.socket = context.socket(zmq.PUB)
self.socket.bind("tcp://%s" % addr)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='')
parser.add_argument('addr', type=str, default="localhost:5556", nargs="?")
args = parser.parse_args()
conn = krpc.connect()
vessel = conn.space_center.active_vessel
control = vessel.control
rocket = ModelRocket(args.addr)
stage = conn.add_stream(getattr, control, 'current_stage')
stage.add_callback(rocket.send)
stage.start()
while 42:
pass
#!/usr/bin/env python3
from time import sleep
from random import randint
import configparser
import zmq
import sys
import spidev
import ws2812
import OPi.GPIO as GPIO
from neopixel import *
from random import randint
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
def get_color():
rand = randint(0, 10)
if rand < 5:
return (248, 255, 255)
elif rand == 6:
return (111, 255, 0)
elif rand == 7:
return (234, 255, 0)
elif rand == 8:
return (87, 255, 34)
else:
return (0, 213, 0)
# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT)
# Intialize the library (must be called once before other functions).
strip.begin()
# LED strip configuration:
LED_COUNT = 16 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
def light_flame():
spi = spidev.SpiDev()
spi.open(1, 0)
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
while True:
ws2812.write2812(spi, [get_color() * 4])
sleep(0.2)
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Connecting to coordinator...")
socket.connect(f"tcp://localhost:{port}")
def main():
config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'})
config.read('config.cfg')
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
port = config['port']
host = config['host']
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
while True:
string = socket.recv()
topic, messagedata = string.split()
print(topic, messagedata)
print("Connecting to coordinator...")
socket.connect(f"tcp://{host}:{port}")
if messagedata == "liftoff":
light_flame()
elif messagedata == "stage_1_separation":
light_flame()
else:
print("Unhandled message")
def light_flame():
for i in range(0,strip.numPixels(),1):
rand = randint(0,10)
if rand<5:
color = (255, 248, 255)
else if rand==6:
color = (255, 111, 0)
else if rand==7:
color = (255, 234, 0)
else if rand==8:
color = (255, 87, 34)
else :
color = (213, 0, 0)
strip.setPixelColor(i, color)
strip.show()
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
while True:
string = socket.recv()
topic, messagedata = string.split()
print(topic, messagedata)
if messagedata == "liftoff":
light_flame()
elif messagedata == "stage_1_separation":
light_flame()
else:
print("Unhandled message")
if __name__ == "__main__":
main()
#!/usr/bin/env python3
import zmq
import sys
import subprocess
import configparser
import actions
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
def prime_stages():
subprocess.Popen('./servo_control', '1', '1')
subprocess.Popen('./servo_control', '7', '1')
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Connecting to coordinator...")
socket.connect(f"tcp://localhost:{port}")
def separate_stage_one():
subprocess.Popen('./servo_control', '1', '0')
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
while True:
string = socket.recv()
topic, messagedata = string.split()
def separate_stage_two():
subprocess.Popen('./servo_control', '7', '0')
if messagedata == "pre_launch":
actions.pre_launch()
elif messagedata == "liftoff":
actions.liftoff()
elif messagedata == "stage_1_separation":
actions.stage_1_separation()
elif messagedata == "stage_2_separation":
actions.stage_2_separation()
else:
print("Unhandled message")
print(topic, messagedata)
def main():
config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'})
config.read('config.cfg')
port = config['port']
host = config['host']
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Connecting to coordinator...")
socket.connect(f"tcp://{host}:{port}")
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
prime_stages()
while True:
string = socket.recv()
topic, messagedata = string.split()
if messagedata == "stage_1_separation":
separate_stage_one()
elif messagedata == "stage_2_separation":
separate_stage_two()
else:
print("Unhandled message")
print(topic, messagedata)
if __name__ == "__main__":
main()
#!/usr/bin/env python3
import pygame as pg
from threading import Timer
import zmq
import configparser
# fade out
def endMission():
pg.mixer.Channel(0).fadeout(5)
pass
def main():
config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'})
config.read('config.cfg')
port = config['port']
host = config['host']
pg.mixer.init()
pg.init(44100, size=-16, channels=2, buffer=4096)
pg.mixer.set_num_channels(3) # default is 8
# carico i file audio
lancio = pg.mixer.Sound('sounds/lancio.wav')
stageOne = pg.mixer.Sound('sounds/stageOne.wav')
stageTwo = pg.mixer.Sound('sounds/stageTwo.wav')
# tempo di fine suono dopo secondo modulo
t = Timer(30.0, endMission)
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Connecting to coordinator...")
socket.connect(f"tcp://{host}:{port}")
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
while True:
string = socket.recv()
topic, messagedata = string.split()
if messagedata == "pre_launch":
pg.mixer.Channel(0).play(lancio)
elif messagedata == "stage_1_separation":
pg.mixer.Channel(1).play(stageOne)
elif messagedata == "stage_2_separation":
pg.mixer.Channel(2).play(stageTwo)
t.start()
else:
print("Unhandled message")
print(topic, messagedata)
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment