def app():
    # Init Dynamixel connection
    global dxlIO, foundIds
    ports = pypot.dynamixel.get_available_ports()
    if not ports:
        raise IOError('No port available.')
    port = ports[0]
    dxlIO = pypot.dynamixel.DxlIO(port)
    print 'Connected'
    # Setup motors
    dxlIO.enable_torque([leftWheelMotorId, rightWheelMotorId, dremelMotorId])
    dxlIO.set_moving_speed({dremelMotorId: dremelJointSpeedMin})
    # Init OSC server
    simpleOSC.initOSCServer(receiveAddress, receivePort)
    simpleOSC.setOSCHandler('/wheelspeed', wheelSpeedHandler)
    simpleOSC.setOSCHandler('/wheelslowdown', wheelSlowdownHandler)
    simpleOSC.setOSCHandler('/dremeljointpos', dremelJointPosHandler)
    simpleOSC.setOSCHandler('/dremeljointspeed', dremelJointSpeedHandler)
    simpleOSC.startOSCServer()
    # Enter infinite loop to be able to catch KeyboardInterrupt
    try:
        while True:
            time.sleep(0)
    except KeyboardInterrupt:
        simpleOSC.closeOSC()
Example #2
0
def run():
    # SETUP #
    resetCanvas()
    import time
    out.FADERATE = 8  # fade rate, currently broken?
    out.start()

    # OSC SERVER/HANDLERS #
    initOSCServer(ip, port)  # setup OSC server
    setOSCHandler('/reset', reset)  # resets the visualization
    setOSCHandler('/asteroid', orb)  # when an orb moves on the screen
    setOSCHandler('/set_max_brightness', setMax)
    setOSCHandler('/set_min_brightness', setMin)

    # SERVER START #
    startOSCServer()
    print "server is running, listening at " + str(ip) + ":" + str(port)

    # SERVER LOOP#
    try:
        clock = 1
        while (1):
            out.write(canvas)  # write to canvas
            time.sleep(0.1)  # tick every 0.1 seconds
            if ((clock % 1000) == 0):  # every 1000 ticks
                plasmaCanvas()
            clock = (clock +
                     1) % 10000  # increment clock, reseting every 10000 ticks
    except KeyboardInterrupt:
        print "closing all OSC connections... and exit"
        closeOSC()  # close the osc connection before exiting
Example #3
0
def run():
	# SETUP #
	resetCanvas()
	import time
	out.FADERATE = 8 # fade rate, currently broken?
	out.start()
	
	# OSC SERVER/HANDLERS #
	initOSCServer(ip, port) # setup OSC server
	setOSCHandler('/reset', reset)	# resets the visualization
	setOSCHandler('/asteroid', orb)	# when an orb moves on the screen
	setOSCHandler('/set_max_brightness', setMax)
	setOSCHandler('/set_min_brightness', setMin)

	# SERVER START #
	startOSCServer()
	print "server is running, listening at " + str(ip) + ":" + str(port)

	# SERVER LOOP#
	try:
		clock = 1
		while(1):
			out.write(canvas) # write to canvas
			time.sleep(0.1) # tick every 0.1 seconds
			if ((clock%1000) == 0): # every 1000 ticks
				plasmaCanvas()
			clock = (clock+1)%10000 # increment clock, reseting every 10000 ticks
	except KeyboardInterrupt:
		print "closing all OSC connections... and exit"
		closeOSC() # close the osc connection before exiting	
Example #4
0
    def run_server(self):

        # OSC SERVER/HANDLERS #
        initOSCServer(self.ip, self.rport) # setup OSC server
	
        setOSCHandler('/shape', shape_handler)
        setOSCHandler('/boundary', boundary_handler)
        setOSCHandler('/contact', contact_handler)
        setOSCHandler('/hand', hand_handler)
        setOSCHandler('/finger', finger_handler)
        setOSCHandler('/background', background_handler)
        setOSCHandler('/bgrgb/red', bgred_handler)
        setOSCHandler('/bgrgb/green', bggreen_handler)
        setOSCHandler('/bgrgb/blue',bgblue_handler)
        # SERVER START #
        startOSCServer()
        print "server is running, listening at " + str(self.ip) + ":" + str(self.rport)
        print "use Ctrl-C to quit."

        # SERVER LOOP #
        try:
            clock = 1
            while(1):
                time.sleep(5)
        except KeyboardInterrupt:
            print "closing all OSC connections... and exit"
            closeOSC() # close the osc connection before exiting	
Example #5
0
def myTest():
    """ a simple function that creates the necesary sockets and enters an enless
        loop sending and receiving OSC
    """
    import time # in this example we will have a small delay in the while loop
    
    initOSCClient() # takes args : ip, port
    initOSCServer() # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server
    
    # bind addresses to functions 
    setOSCHandler('/check', checkcheckcheck)

    startOSCServer() # and now set it into action

    print 'ready to receive and send osc messages ...'

    try:
        while 1:
            sendOSCMsg("/test", [444]) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 

            # create and send a bundle
            bundle = createOSCBundle("/test/bndlprt1")
            bundle.append(666) # 1st message appent to bundle
            bundle.append("the number of the beast") # 2nd message appent to bundle
            sendOSCBundle(bundle) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 

            time.sleep(0.5) # you don't need this, but otherwise we're sending as fast as possible.

    except KeyboardInterrupt:
       print "closing all OSC connections... and exit"
       closeOSC() # finally close the connection before exiting or program.
Example #6
0
def setup():
    """ initializes everything """

    # start serial comm
    global port
    port = serial.Serial("/dev/ttyUSB0", baudrate=19200, timeout=3.0)

    # start OSC comm and attach handlers
    global haveClient
    haveClient = False
    initOSCServer("192.168.0.160", 9001,
                  0)  # last arg: 0 basic, 1 threading, 2 forking
    setOSCHandler("/client", client)
    setOSCHandler("/initialize", initialize)
    setOSCHandler("/calibrate", calibrate)
    setOSCHandler("/toollength", toollength)
    setOSCHandler("/speed", speed)
    setOSCHandler("/home", home)
    setOSCHandler("/where", where)
    setOSCHandler("/cartesian", cartesian)
    setOSCHandler("/joint", joint)
    setOSCHandler("/move", move)
    setOSCHandler("/off", off)

    startOSCServer()

    global busy
    busy = False

    print "roboforthOSC started..."
Example #7
0
def LaserLoop():
	initOSCClient('127.0.0.1', 8000) # takes args : ip, port
	initOSCServer('127.0.0.1', 8001) # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking 

	# bind addresses to functions 
	setOSCHandler('/laser', laser)
	startOSCServer() # and now set it into action

	print 'ready to receive and send osc messages ...'
Example #8
0
def run():
	try:
		initOSCServer(ip, port)

		setOSCHandler('/collision', col)

		startOSCServer()
		print "server is running, listening at " + str(ip) + ":" + str(port)
	except KeyboardInterrupt:
		closeOSC()
Example #9
0
def LaserLoop():
    initOSCClient('127.0.0.1', 8000)  # takes args : ip, port
    initOSCServer(
        '127.0.0.1', 8001
    )  # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking

    # bind addresses to functions
    setOSCHandler('/laser', laser)
    startOSCServer()  # and now set it into action

    print 'ready to receive and send osc messages ...'
Example #10
0
def run():
	try:
		initOSCClient(ip, client_port)

		# initOSCClient(ip, client_port)
		initOSCServer(ip, server_boids_port)
		setOSCHandler('/collision', col)
		startOSCServer()

		initOSCServer(ip, server_sound_port)
		setOSCHandler('/request', request)
		startOSCServer()

	except KeyboardInterrupt:
		closeOSC()
Example #11
0
def myTest():
    initOSCClient("192.168.0.2", 9000)  # takes args : ip, port
    initOSCServer(
        "192.168.0.7", 9001,
        0)  # takes args : ip, port, mode => 0 basic, 1 threading, 2 forking

    setOSCHandler('/test', test)
    startOSCServer()

    print 'ready to receive and send osc messages...'

    try:
        while 1:
            sendOSCMsg("/sup", [444, 4.4, 'yomama is a baby'])
            time.sleep(1)

    except KeyboardInterrupt:
        print "closing all OSC connections and exiting"
        closeOSC()
Example #12
0
    def run_server(self):

        # OSC SERVER/HANDLERS #
        initOSCServer(self.ip, self.rport) # setup OSC server
	
        setOSCHandler('/async/hue', hue_handler)
        # SERVER START #
        startOSCServer()
        print "server is running, listening at " + str(self.ip) + ":" + str(self.rport)
        print "use Ctrl-C to quit."

        # SERVER LOOP #
        try:
            clock = 1
            while(1):
                time.sleep(5)
        except KeyboardInterrupt:
            print "closing all OSC connections... and exit"
            closeOSC() # close the osc connection before exiting	
Example #13
0
def myTest():
    """ a simple function that creates the necesary sockets and enters an enless
        loop sending and receiving OSC
    """
    import time  # in this example we will have a small delay in the while loop

    initOSCClient()  # takes args : ip, port
    print 'client'
    initOSCServer(
    )  # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server
    print 'server'

    # bind addresses to functions
    setOSCHandler('/check', checkcheckcheck)
    print 'check'

    startOSCServer()  # and now set it into action

    print 'ready to receive and send osc messages ...'

    try:
        while 1:
            print 'sending...'
            sendOSCMsg(
                "/test", [444]
            )  # !! it sends by default to localhost ip "127.0.0.1" and port 9000

            # create and send a bundle
            bundle = createOSCBundle("/test/bndlprt1")
            bundle.append(666)  # 1st message appent to bundle
            bundle.append(
                "the number of the beast")  # 2nd message appent to bundle
            sendOSCBundle(
                bundle
            )  # !! it sends by default to localhost ip "127.0.0.1" and port 9000

            time.sleep(
                0.5
            )  # you don't need this, but otherwise we're sending as fast as possible.

    except KeyboardInterrupt:
        print "closing all OSC connections... and exit"
        closeOSC()  # finally close the connection before exiting or program.
def stuff():
	import time

	a = []
	a.len
	
	initOSCServer(ip, port)
	
	setOSCHandler('/collision', collision)

	startOSCServer()
	print "server is running, listening at " + str(ip) + ":" + str(port)

	try:
		while(1):
			time.sleep(1000)
	except KeyboardInterrupt:
		print "closing all OSC connections... and exit"
		closeOSC() # finally close the connection before exiting or program.
Example #15
0
File: main.py Project: AR-S/Nodes
    def do_connect(self):
        config = self.config
        host = config.get('network', 'host')
        sport = config.getint('monome', 'send_port')
        rport = config.getint('monome', 'receive_port')
        mdevice = config.getint('midi', 'device')
        # osc
        initOSCClient(host, sport)
        initOSCServer(host, rport)
        # midi
        #pygame.midi.init()
        #pygame.midi.get_count()
        #self.midi_out = pygame.midi.Output(device_id=mdevice)
        #self.device_name = pygame.midi.get_device_info(mdevice)

        # switch to main screen
        parent = self.root.parent
        parent.remove_widget(self.root)
        self.root = BrokerControlMain(app=self)
        parent.add_widget(self.root)
Example #16
0
    def do_connect(self):
        config = self.config
        host = config.get('network', 'host')
        sport = config.getint('monome', 'send_port')
        rport = config.getint('monome', 'receive_port')
        mdevice = config.getint('midi', 'device')
        # osc
        initOSCClient(host, sport)
        initOSCServer(host, rport)
        # midi
        #pygame.midi.init()
        #pygame.midi.get_count()
        #self.midi_out = pygame.midi.Output(device_id=mdevice)
        #self.device_name = pygame.midi.get_device_info(mdevice)

        # switch to main screen
        parent = self.root.parent
        parent.remove_widget(self.root)
        self.root = BrokerControlMain(app=self)
        parent.add_widget(self.root)
        for i in range(0, 200, 25):
            print i
            self.send("*" * i)

    def closed(self, code, reason=None):
        print "Closed down", code, reason

    def received_message(self, m):
        print m
        if len(m) == 175:
            self.close(reason='Bye bye')

if __name__ == '__main__':
    # try:
    try:
        initOSCServer(ip, port)

        setOSCHandler('/collision', col)

        startOSCServer()
        print "server is running, listening at " + str(ip) + ":" + str(port)

        ws = DummyClient('ws://localhost:9000/', protocols=['nlcp'])
        ws.connect()
        ws.run_forever()
    except KeyboardInterrupt:
        ws.close()
        closeOSC()

def col(addr, tags, data, source):
    print "got collision"
import time
import nmx
from random import random
from simpleOSC import initOSCClient, initOSCServer, setOSCHandler, sendOSCMsg, closeOSC, \
        createOSCBundle, sendOSCBundle, startOSCServer


ip = "127.0.0.1"
client_port = 8001

# takes args : ip, port
initOSCClient(ip=ip, port=client_port)

# takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server
initOSCServer(ip=ip, port=6400)

# and now set it into action
startOSCServer()

for x in range(100):
    try:
        # !! it sends by default to localhost ip "127.0.0.1" and port 9000 
        sendOSCMsg("/nmx/test/", [random.random()])
        # create and send a bundle
        bundle = createOSCBundle("/nmx/test/x")
        # 1st message appent to bundle
        bundle.append(666)
        # 2nd message appent to bundle
        bundle.append("the number of the beast")
        # !! it sends by default to localhost ip "127.0.0.1" and port 9000 
Example #19
0
    print "New face with ID %s detected" % data

def deleteface(addr, tags, data, source):
    print "Face with ID %s escaped" % data

def facelist(addr, tags, data, source):
    print "Face %s position: x:%s y:%s, motion: x:%sy:%s, distance:%s" % (data[0], data[1], data[2], data[3], data[4], data[5])

def end(addr, tags, data, source):
	closeOSC()
	print "Bye"
	sys.exit()


if __name__ == '__main__':

	initOSCServer('127.0.0.1', 7000)
	setOSCHandler('/newface', newface)
	setOSCHandler('/deleteface', deleteface)
	setOSCHandler('/facelist', facelist)
	setOSCHandler('/end', end)
	startOSCServer()

	while True:
	    try:
		pass
	    except KeyboardInterrupt:
		closeOSC()
		print "Bye"
		sys.exit()
Example #20
0
fmin = 8
fmax = 12

baseline = 3
bp_base = []

n_eeg = 16
sfreq = 250
picks = np.arange(n_eeg)

# takes args : ip, port
initOSCClient(ip=ip, port=client_port)

# takes args : ip, port, mode --> 0 for basic server,
# 1 for threading server, 2 for forking server
initOSCServer(ip=ip, port=6400, mode=1)

# and now set it into action
startOSCServer()

# get measurement info guessed by MNE-Python
ch_names = ['EEG-%i' % i for i in np.arange(n_eeg)]
raw_info = mne.create_info(ch_names, sfreq)

with FieldTripClient(info=raw_info, host='localhost', port=1972,
                     tmax=150, wait_max=10) as rt_client:

    tstart = time.time()
    told = tstart
    for ii in range(100):
        epoch = rt_client.get_data_as_epoch(n_samples=n_samples, picks=picks)
Example #21
0
fmin = 8
fmax = 12

baseline = 3
bp_base = []

n_eeg = 16
sfreq = 250
picks = np.arange(n_eeg)

# takes args : ip, port
initOSCClient(ip=ip, port=client_port)

# takes args : ip, port, mode --> 0 for basic server,
# 1 for threading server, 2 for forking server
initOSCServer(ip=ip, port=6400, mode=1)

# and now set it into action
startOSCServer()

# get measurement info guessed by MNE-Python
ch_names = ['EEG-%i' % i for i in np.arange(n_eeg)]
raw_info = mne.create_info(ch_names, sfreq)

with FieldTripClient(info=raw_info,
                     host='localhost',
                     port=1972,
                     tmax=150,
                     wait_max=10) as rt_client:

    tstart = time.time()
Example #22
0

from simpleOSC import initOSCClient, initOSCServer, setOSCHandler, sendOSCMsg, closeOSC, \
     createOSCBundle, sendOSCBundle, startOSCServer

import granular_control
import time


control = granular_control.GranularController()
control.start_log(str(time.time()) + ".dat")

initOSCServer("127.0.0.1", 60001) # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server
initOSCClient("127.0.0.1", 60000)

def ping(addr, tags, data, source):
    print "Received ping request!"
    sendOSCMsg("/ping", [str(time.time())])

def receive_kinect_data(addr, tags, data, source):
    global control
    control.record_control(data)

def playback_data_point(addr, tags, data, source):
    global control
    try:
        d = control.get_data()
        sendOSCMsg("/kinect", list(d))
    except:
        sendOSCMsg("/error", ["No more recorded data to playback!"])
Example #23
0
    num_scale_step = 4
    num_dist_step = 4
    num_rotation_bool = 2
    action_size = num_objects * num_angle_step * num_scale_step * num_dist_step * num_rotation_bool

    agent = DQNAgent(state_size, action_size)
    my_file = Path("./save/weights.h5")

    if my_file.is_file():
        agent.load("./save/weights.h5")
    else:
        agent.save("./save/weights.h5")

    done = False
    batch_size = 32

    # setup OSC parts
    initOSCClient()  # takes args : ip, port
    print 'client'
    initOSCServer(
    )  # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server
    print 'server'

    # bind addresses to functions
    setOSCHandler('/inputs_current', currentHandler)
    setOSCHandler('/inputs_next', nextHandler)
    print 'address binding check'

    startOSCServer()  # and now set it into action
    print 'ready to receive and send osc messages ...'
Example #24
0
def server():
    initOSCServer("0.0.0.0", 9000, 0)
    setOSCHandler('/drink', drink)
    startOSCServer()
# Not in use
def shutdown(pl):
    input("Press any key to close OSC server")
    closeOSC()
    pl.terminate()


if __name__ == '__main__':
    b = nxt.locator.find_one_brick()
    controls = MotorControl(b)

    # takes args : ip, port
    initOSCClient()

    # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server
    initOSCServer(ip='127.0.0.1', port=20002, mode=1)

    # bind addresses to functions
    setOSCHandler('/motors', controls.motor_osc_handler)

    # and now set it into action
    startOSCServer()

    # starting the sensor broadcast in parallel
    pool = mp.Pool()
    #pool.apply_async(shutdown(pool))
    pool.apply_async(sensor_broadcast(controls))
    pool.close()
    pool.join()
    # server = sensor_broadcast(controls)
    # procOSC = mp.Process(server)
Example #26
0
                        help="The port to listen on")
    parser.add_argument("--port_send",
                        type=int,
                        default=9002,
                        help="The port to send messages to")
    args = parser.parse_args()

    # Configure connection to/from Push2 MIDI
    try:
        push2_midi_out = mido.open_output(
            'Ableton Push 2:Ableton Push 2 MIDI 1 16:0')
        push2_midi_in = mido.open_input(
            'Ableton Push 2:Ableton Push 2 MIDI 1 16:0')
        push2_midi_in.callback = midi_from_push_handler
        print("Listening for MIDI messages comming from push...")
    except OSError:
        print("Could not connect to Push2 MIDI ports")
        sys.exit(0)
    except IOError:
        print("Could not connect to Push2 MIDI ports")
        sys.exit(0)

    # Configure OSC client for sending messages to
    initOSCClient(ip=args.ip, port=args.port_send)

    # Configure OSC server to receive messages from OCTOPUSH
    initOSCServer(ip=args.ip, port=args.port_listen)
    setOSCHandler('/topush', midi_to_push_handler)
    startOSCServer()
    print("Listening OSC on {}".format(args.port_listen))
Example #27
0
# Not in use
def shutdown(pl):
    input("Press any key to close OSC server")
    closeOSC()
    pl.terminate()


if __name__ == '__main__':
    b = nxt.locator.find_one_brick()
    controls = MotorControl(b)

    # takes args : ip, port
    initOSCClient()

    # takes args : ip, port, mode --> 0 for basic server, 1 for threading server, 2 for forking server
    initOSCServer(ip='127.0.0.1', port=20002, mode=1)

    # bind addresses to functions
    setOSCHandler('/motors', controls.motor_osc_handler)

    # and now set it into action
    startOSCServer()

    # starting the sensor broadcast in parallel
    pool = mp.Pool()
    #pool.apply_async(shutdown(pool))
    pool.apply_async(sensor_broadcast(controls))
    pool.close()
    pool.join()
    # server = sensor_broadcast(controls)
    # procOSC = mp.Process(server)
Example #28
0
 def start(self):
     initOSCServer(self.ip, self.port)  # setup OSC server
     setOSCHandler('/send_next_song', self.buffer_handler)
     startOSCServer()
     self.main_method()
     sendOSCMsg("/startprogram", [1])
Example #29
0
eeg_waves = []
a_waves = []
b_waves = []



ip = "localhost"
port1 = 9002
port_receive = 9001
base_a4=440


port1 = sys.argv[1]

initOSCClient(ip, int(port1))
'''
initOSCServer(ip, int(port_receive), 0)
setOSCHandler('/mood', process_mood)
startOSCServer()
'''

def mtof(midi):
	return base_a4*2**((midi-9)/12.0)



def process_eeg(addr, tags, data, source):

  print "received new osc msg from %s" % getUrlStr(source)
  print "with addr : %s" % addr
  print "typetags :%s" % tags