Example #1
0
def main():
	fs = FileStorage()
	fs.readJson("net.json")

	try:
		hw = Process(target=HW_Func).start()
		snd = Process(target=Sound_Func).start()
		chaos = Process(target=Chaos_Func).start()
		js = Process(target=Joystick_Func).start()

		while True:
			time.sleep(3)

	except KeyboardInterrupt:
		print('<<<<<<<< keyboard >>>>>>>>>>>')
		if snd.is_alive():
			snd.join(0.1)
			snd.terminate()
		if hw.is_alive():
			hw.join(0.1)
			hw.terminate()
		if chaos.is_alive():
			chaos.join()
			chaos.terminate()
		if js.is_alive():
			js.join()
			js.terminate()
Example #2
0
    def __init__(self):
        self.sensors = Sensors()
        self.servos = Actuators()
        # self.logic_displays = Displays()

        #self.dome_mc = SMC()

        #self.js = Joystick()
        self.snd = Sounds()

        fs = FileStorage()
        fs.readJson("clips.json")
        self.clips = fs.db
Example #3
0
def Sound_Func():
    print('sounds starts')
    host = ('localhost', 9000)

    # get sound clips
    fs = FileStorage()
    fs.readJson("clips.json")
    db = fs.db
    # pprint(self.db)
    # self.play(self.db['start'])
    print('Found {} sounds clips'.format(len(db)))

    # pub/sub setup
    sub = zmq.Sub(['sounds', 'speak'], host)

    audio_player = AudioPlayer()
    audio_player.set_volume(15)  # volume is 0-100%
    time.sleep(0.1)
    print('AudioPlayer found:', audio_player.audio_player)

    r2 = TTAstromech()
    r2.speak('warning')
    time.sleep(0.5)

    print('------start--------')
    while True:
        topic, msg = sub.recv()
        # print('msg?')
        if msg:
            if topic == 'sounds':
                print('Topic, Msg:', topic, msg)
                # print('play sound')
                key = msg.dict['sound']
                if key in db:
                    audio_player.play('clips/' + db[key])
                else:
                    print('ERROR: key not found in db:', key)
            elif topic == 'speak':
                print('Topic, Msg:', topic, msg)
                word = msg.dict['speak']
                word = word[0:6]  # limit R2 to 6 letters
                r2.speak(word)
        # else:
        # print('nothing')
        time.sleep(0.5)
Example #4
0
    def __init__(self):
        print('sounds starts')

        # get sound clips
        fs = FileStorage()
        fs.readJson("clips.json")
        self.db = fs.db

        print('Found {} sounds clips'.format(len(self.db)))

        self.audio_player = AudioPlayer()
        self.audio_player.set_volume(15)  # volume is 0-100%
        time.sleep(0.1)
        print('AudioPlayer found:', self.audio_player.audio_player)

        self.r2 = TTAstromech()
        self.r2.speak('warning')
        time.sleep(0.5)
Example #5
0
def test_yaml():
    data = {'bob': 1, 'tom': 2, 'sam': 3}

    fname = 'test.yaml'

    fs = FileStorage()
    fs.writeYaml(fname, data)
    fs.clear()
    fs.readYaml(fname)

    # print fs.db
    os.remove(fname)

    assert fs.db == data
Example #6
0
def test_json():
    data = {'bob': 1, 'tom': 2, 'sam': 3}

    fname = 'test.json'

    fs = FileStorage()
    fs.writeJson(fname, data)
    fs.clear()
    fs.readJson(fname)

    # print fs.db
    os.remove(fname)

    assert fs.db == data
Example #7
0
def chaos(ns, run):
    """
    This does NOTHING USEFUL!!!!!!!
    It just exercises the codebase
    """
    sensors = Sensors()
    servos = Actuators()
    snd = Sounds()

    fs = FileStorage()
    fs.readJson("clips.json")
    clips = fs.db

    while run.is_set():
        # update display
        # logic_displays.update()

        # read inputs
        # ps4 = js.get()
        # print(ps4)

        # play random clip
        clip = random.choice(clips.keys())
        print('playing:', clip)
        snd.sound(clip)
        time.sleep(5)

        # speak random word
        char_set = string.ascii_lowercase
        word = ''.join(random.sample(char_set, 6))
        snd.speak(word)
        time.sleep(3)

        # move random servo
        num = random.choice(range(3))
        name = 'door{}'.format(num)
        angle = random.choice(range(30, 150, 10))
        print('Moving servro:', name, angle)
        servos.set(name, angle)
        time.sleep(1)
Example #8
0
def Chaos_Func():
	print('CHAOS BEGINS !!!!!!!!!!!!!!!!!!!!!!!!!!!!')

	fs = FileStorage()
	fs.readJson("net.json")
	net = fs.db
	# pprint(self.db)
	# self.play(self.db['start'])

	fs.db = {}
	fs.readJson("clips.json")
	clips = fs.db

	# subs = []
	# for sub in net:
	# 	ip = net[sub]
	# 	s = zmq.Pub(bind_to=(ip[0], ip[1]))
	# 	subs.append(s)
	# 	print(' >> Subscribed to:', sub, '@', ip)

	subs = {}
	subs['sounds'] = zmq.Pub(bind_to=('localhost', 9000))
	subs['speak'] = subs['sounds']
	subs['servos'] = zmq.Pub(bind_to=('localhost', 9004))

	while True:
		for key in subs.keys():
			if key == 'sounds':
				clip = random.choice(clips.keys())
				msg = Messages.Dictionary()
				msg.dict['sound'] = clip
				subs['sounds'].pub('sounds', msg)
				# print('msg:', msg)
				time.sleep(7)
			elif key == 'speak':
				word = getnrandom()
				msg = Messages.Dictionary()
				msg.dict[key] = word
				subs[key].pub(key, msg)
				time.sleep(4)
			elif key == 'servos':
				num = random.choice(range(3))
				name = 'door{}'.format(num)
				msg = Messages.Dictionary()
				msg.dict['name'] = name
				msg.dict['angle'] = random.choice(range(30, 150, 10))
				subs[key].pub(key, msg)
				time.sleep(1)
			else:
				print('<<< Oops, unknown key:', key, '>>>')