当前位置: 首页>>代码示例>>Python>>正文


Python Emotiv.dequeue方法代码示例

本文整理汇总了Python中emokit.emotiv.Emotiv.dequeue方法的典型用法代码示例。如果您正苦于以下问题:Python Emotiv.dequeue方法的具体用法?Python Emotiv.dequeue怎么用?Python Emotiv.dequeue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在emokit.emotiv.Emotiv的用法示例。


在下文中一共展示了Emotiv.dequeue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: evt_main

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def evt_main():
    global is_running
    ring_buf = np.zeros(x.size)
    ring_buf2 = np.zeros(x.size)
    headset = Emotiv()

    gevent.spawn(headset.setup)
    gevent.sleep(0)
    pos = 0
    try:
        while is_running:
            packet = headset.dequeue()
            print packet.gyro_x, packet.gyro_y

            ring_buf[pos] = packet.sensors["O1"]["value"]
            ring_buf2[pos] = packet.sensors["O2"]["value"]
            pos = (pos + 1) % ring_buf.size
            if pos % 4 == 0:
                yield np.concatenate((ring_buf[pos:ring_buf.size:1], ring_buf[0:pos:1])), np.concatenate((ring_buf2[pos:ring_buf.size:1], ring_buf2[0:pos:1]))

            gevent.sleep(0)
    except KeyboardInterrupt:
        headset.close()
    finally:
        is_running = False
        headset.close()
开发者ID:cactorium,项目名称:UCFBrainStuff,代码行数:28,代码来源:convolv.py

示例2: console_gather

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def console_gather() :

    os.system('clear')

    headset = Emotiv()
    gevent.spawn(headset.setup)
    gevent.sleep(0)

    packets = 0
    now = datetime.now()
    filename = str(now.time()) + "_" + str(now.date())
    while True :
        dir = str(input("Choose input: \n 1. up\n 2. down\n 3. left\n 4. right\n 0. neutral\n"))
        if dir in ['1','2','3','4','0'] : break
    filename += "_" + dir
    if TEST : filename = "TEST_" + filename


    buffers = []
    names = 'AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4'.split(' ')
    for name in names :
        buffers.append(sensor_buffer(name))

    print "Training will start in..."; sleep(1); print "3..."; sleep(1); print "2..."; sleep(1); print "1..."; sleep(1); print "Focus!"

    qualities = []
    timeout = time() + 12
    while True:
        if time() > timeout :
            break

        packet = headset.dequeue()
        for buffer in buffers :
            buffer.update( packet )
        packets += 1
        gevent.sleep(0)

    headset.close()

    quality = 0.
    f = open("./data/" + filename,'w')
    columns = []
    for name in names :
        columns.append(str(name))
        columns.append('Q' + str(name))
    f.write(','.join(columns))
    f.write('\n')
    while packets > 0 :
        for buffer in buffers :
            f.write( buffer.pop() )
        f.write('\n')
        packets -= 1

    f.close()


    print "Finished reading, saved to file %s" % filename
    for buffer in buffers :
        print "Sensor %s mean quality: %.2f" % (buffer.name, buffer.mean_quality())
开发者ID:uj-robotics,项目名称:emokit-ev3elephant,代码行数:61,代码来源:data_gatherer.py

示例3: epoc_publish_frames

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def epoc_publish_frames():
    # Setup ROS publisher.
    publisher = rospy.Publisher('epoc/frames', EEGFrame)

    # Open a connection to the Emotiv EPOC.
    headset = Emotiv()
    gevent.spawn(headset.setup)
    gevent.sleep(1)

    # Initialize ROS node+publisher.
    rospy.init_node('epoc_publish')

    # Start the publishing loop.
    rospy.loginfo('Starting publishing loop...')
    published_count = 0
    try:
        while not rospy.is_shutdown():
            # Get the next packet from the EPOC.
            packet = headset.dequeue()

            frame_header = Header(published_count, rospy.Time.now(), '/epoc')
            frame_accel_x = packet.sensors['X']['value']
            frame_accel_y = packet.sensors['Y']['value']
            frame_signals = [
                packet.sensors[channel]['value']
                for channel in channels]
            frame_qualities = [
                packet.sensors[channel]['quality']
                for channel in channels]
            frame = EEGFrame(
                frame_header,
                frame_accel_x,
                frame_accel_y,
                14,
                channels,
                frame_signals,
                frame_qualities)

            # Publish the the EEG channels and accelerometer values.
            publisher.publish(frame)

            # Update and print information count.
            published_count += 1
            print('\rPublished: %d' % published_count, end='')

            gevent.sleep(0)
    except rospy.ROSInterruptException:
        headset.close()
开发者ID:robotoer,项目名称:emotiv_epoc,代码行数:50,代码来源:epoc_publish.py

示例4: evt_main

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def evt_main():
    global is_running
    ring_buf = np.zeros(x.size)
    headset = Emotiv()

    gevent.spawn(headset.setup)
    gevent.sleep(0)
    pos = 0
    try:
        while is_running:
            packet = headset.dequeue()
            yield packet
            gevent.sleep(0)
    except KeyboardInterrupt:
        headset.close()
    finally:
        is_running = False
        headset.close()
开发者ID:asandow,项目名称:SeniorDesignSSEVP,代码行数:20,代码来源:smoothed_period.py

示例5: main_process

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
	def main_process(self):
		"""
		Get realtime EEG data from Emotiv EPOC, process all data (FFT, feature extraction, and classification), and predict the emotion.
		Input: -
		Output: Class of emotion between 1 to 5 according to Russel's Circumplex Model.
		"""
		headset = Emotiv()
		gevent.spawn(headset.setup)
		gevent.sleep(0)

		threads = []
		eeg_realtime = np.zeros((number_of_channel,number_of_realtime_eeg),dtype=np.double)
		counter=0
		init=True

		try:
			#Looping to get realtime EEG data from Emotiv EPOC
		    while True:
		        packet = headset.dequeue()

		        #Get initial EEG data for all channels
		        if init:
		        	for i in range(number_of_channel):eeg_realtime[i,counter]=packet.sensors[channel_names[i]]['value']
		        else:
		        	new_data=[packet.sensors[channel_names[i]]['value'] for i in range(number_of_channel)]
		        	eeg_realtime=np.insert(eeg_realtime,number_of_realtime_eeg,new_data,axis=1)
		        	eeg_realtime=np.delete(eeg_realtime,0,axis=1)
		        
		        #If EEG data have been recorded in ... seconds, then process data to predict emotion
		        if counter == (sampling_rate-1) or counter == (number_of_realtime_eeg-1):
		        	t = threading.Thread(target=rte.process_all_data, args=(eeg_realtime,))
		        	threads.append(t)
		        	t.start()

		        	init=False
		        	counter=0

		        gevent.sleep(0)
		        counter += 1

		except KeyboardInterrupt:
		    headset.close()
		finally:
		    headset.close()
开发者ID:lijian8,项目名称:Realtime-EEG-Based-Emotion-Recognition,代码行数:46,代码来源:realtime-emotion.py

示例6: packets

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def packets():
    global is_running
    ring_buf = np.zeros(x.size)
    headset = Emotiv()

    gevent.spawn(headset.setup)
    gevent.sleep(0)
    pos = 0
    try:
        while is_running:
            packet = headset.dequeue()
            data = {key: (value["value"], value["quality"])
                    for (key, value) in packet.sensors.items()}
            yield data
            gevent.sleep(0)
    except KeyboardInterrupt:
        headset.close()
    finally:
        is_running = False
        headset.close()
开发者ID:cactorium,项目名称:UCFBrainStuff,代码行数:22,代码来源:brainstuff2.py

示例7: epoc_publish_channels

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def epoc_publish_channels():
    # Setup ROS publishers.
    signal_publishers = {
        channel: rospy.Publisher('epoc/signal/%s' % channel, UInt32)
        for channel
        in channels}
    quality_publishers = {
        channel: rospy.Publisher('epoc/quality/%s' % channel, UInt32)
        for channel
        in channels}

    # Open a connection to the Emotiv EPOC.
    headset = Emotiv()
    gevent.spawn(headset.setup)
    gevent.sleep(1)

    # Initialize ROS node+publisher.
    rospy.init_node('epoc_publish')

    # Start the publishing loop.
    rospy.loginfo('Starting publishing loop...')
    published_count = 0
    try:
        while not rospy.is_shutdown():
            # Get the next packet from the EPOC.
            packet = headset.dequeue()

            # Publish the the EEG channels and accelerometer values.
            for channel in channels:
                signal = UInt32(packet.sensors[channel]['value'])
                quality = UInt32(packet.sensors[channel]['quality'])
                signal_publishers[channel].publish(signal)
                quality_publishers[channel].publish(quality)

            # Update and print information count.
            published_count += 1
            print('\rPublished: %d' % published_count, end='')

            gevent.sleep(0)
    except rospy.ROSInterruptException:
        headset.close()
开发者ID:robotoer,项目名称:emotiv_epoc,代码行数:43,代码来源:epoc_publish.py

示例8: evt_main

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def evt_main(ring_buf):
    headset = Emotiv()

    gevent.spawn(headset.setup)
    gevent.sleep(0)
    pos = 0
    try:
        while True:
            packet = headset.dequeue()
            print packet.gyro_x, packet.gyro_y

            ring_buf[pos] = packet.gyro_x
            if pos % 4 == 0:
                yield ring_buf
            pos = (pos + 1) % 1024

            gevent.sleep(0)
    except KeyboardInterrupt:
        headset.close()
    finally:
        is_running = False
        headset.close()
开发者ID:asandow,项目名称:SeniorDesignSSEVP,代码行数:24,代码来源:gyro_plot.py

示例9: evt_main

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def evt_main(ring_buf):
    global is_running
    headset = Emotiv()

    gevent.spawn(headset.setup)
    gevent.sleep(0)
    pos = 0
    try:
        while is_running:
            packet = headset.dequeue()
            print packet.gyro_x, packet.gyro_y

            ring_buf[pos] = packet.sensors["FC5"]["value"]
            if pos % 4 == 0:
                yield ring_buf
            pos = (pos + 1) % ring_buf.size

            gevent.sleep(0)
    except KeyboardInterrupt:
        headset.close()
    finally:
        is_running = False
        headset.close()
开发者ID:cactorium,项目名称:UCFBrainStuff,代码行数:25,代码来源:eeg_plot.py

示例10: main

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def main(debug=False):
    global gheight
    pygame.init()
    screen = pygame.display.set_mode((1600, 900))
    graphers = []
    recordings = []
    recording = False
    record_packets = []
    updated = False
    curX, curY = 400, 300

    for name in 'AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4'.split(' '):
        graphers.append(Grapher(screen, name, len(graphers)))
    fullscreen = False
    emotiv = Emotiv(displayOutput=False)
    gevent.spawn(emotiv.setup)
    gevent.sleep(1)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                emotiv.close()
                return
            if (event.type == pygame.KEYDOWN):
                if (event.key == pygame.K_ESCAPE):
                    emotiv.close()
                    return
                elif (event.key == pygame.K_f):
                    if fullscreen:
                        screen = pygame.display.set_mode((1600, 900))
                        fullscreen = False
                    else:
                        screen = pygame.display.set_mode((1600,900), FULLSCREEN, 16)
                        fullscreen = True
                elif (event.key == pygame.K_r):
                    if not recording:
                        record_packets = []
                        recording = True
                    else:
                        recording = False
                        recordings.append(list(record_packets))
                        record_packets = None
        packetsInQueue = 0
        try:
            while packetsInQueue < 8:
                packet = emotiv.dequeue()
                print(packet.sensors)
                if abs(packet.gyroX) > 1:
                    curX = max(0, min(curX, 1600))
                    curX -= packet.gyroX
                if abs(packet.gyroY) > 1:
                    curY += packet.gyroY
                    curY = max(0, min(curY, 900))
                map(lambda x: x.update(packet), graphers)
                if recording:
                    record_packets.append(packet)
                updated = True
                packetsInQueue += 1
        except Exception, e:
            print e

        if updated:
            screen.fill((75, 75, 75))
            map(lambda x: x.draw(), graphers)
            pygame.draw.rect(screen, (255, 255, 255), (curX - 5, curY - 5, 10, 10), 0)
            pygame.display.flip()
            updated = False
        gevent.sleep(0)
开发者ID:uj-robotics,项目名称:jasugun,代码行数:69,代码来源:render.py

示例11: Emotiv

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
# This is an example of popping a packet from the Emotiv class's packet queue
# and printing the gyro x and y values to the console. 

from emokit.emotiv import Emotiv
import gevent

if __name__ == "__main__":
    headset = Emotiv()
    gevent.spawn(headset.setup)
    gevent.sleep(0)
    try:
        while True:
            packet = headset.dequeue()
            print packet.gyro_x, packet.gyro_y
            gevent.sleep(0)
    except KeyboardInterrupt:
        headset.close()
    finally:
        headset.close()
开发者ID:openube,项目名称:emokit,代码行数:21,代码来源:example.py

示例12: main

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
def main():
    """
    Creates pygame window and graph drawing workers for each sensor.
    """
    global gheight
    pygame.init()
    screen = pygame.display.set_mode((1280, 800))
    graphers = []
    recordings = []
    recording = False
    record_packets = []
    updated = False
    cursor_x, cursor_y = 400, 300
    #for name in 'AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4'.split(' '):
    for name in 'AF4 P8 F4 T8 O2'.split(' '):
        graphers.append(Grapher(screen, name, len(graphers)))
    fullscreen = False
    emotiv = Emotiv(display_output=True)
    gevent.spawn(emotiv.setup)
    gevent.sleep(0)
    while emotiv.running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                emotiv.close()
                return
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    emotiv.close()
                    return
                elif event.key == pygame.K_f:
                    if fullscreen:
                        screen = pygame.display.set_mode((1280, 800))
                        fullscreen = False
                    else:
                        screen = pygame.display.set_mode((1280, 800), FULLSCREEN, 16)
                        fullscreen = True
                elif event.key == pygame.K_r:
                    if not recording:
                        record_packets = []
                        recording = True
                    else:
                        recording = False
                        recordings.append(list(record_packets))
                        record_packets = None
        packets_in_queue = 0
        try:
            while packets_in_queue < 8:
                packet = emotiv.dequeue()
                if abs(packet.gyro_x) > 1:
                    cursor_x = max(0, min(cursor_x, 1280))
                    cursor_x -= packet.gyro_x
                if abs(packet.gyro_y) > 1:
                    cursor_y += packet.gyro_y
                    cursor_y = max(0, min(cursor_y, 800))
                map(lambda x: x.update(packet), graphers)
                if recording:
                    record_packets.append(packet)
                updated = True
                packets_in_queue += 1
        except Exception, ex:
            print ex

        if updated:
            screen.fill((75, 75, 75))
            map(lambda x: x.draw(), graphers)
            pygame.draw.rect(screen, (255, 255, 255), (cursor_x - 5, cursor_y - 5, 10, 10), 0)
            pygame.display.flip()
            updated = False
        gevent.sleep(0)
开发者ID:Alvin-Vuong,项目名称:emocar,代码行数:71,代码来源:render.py

示例13: processPacket

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
# run forever
try:
    running = True
    while running:

        if guifeature:
            for event in pygame.event.get():
                if event.type == QUIT:
                    running = False
                    break
            if not running:
                break

        # get sensor values from headset
        packet = emotiv.dequeue()
        processPacket(packet)
        for i in range(len(sensornames)):
            updateQuality(i, packet.sensors[sensornames[i]]['quality'])
        if guifeature:
            pygame.display.flip()
        gevent.sleep(0)
    print "Terminating client."
    if guifeature:
        pygame.quit()
    emotiv.close()
    closeOSC()
    sys.exit()

# cleanly exit the client
except KeyboardInterrupt:
开发者ID:woodrowbarlow,项目名称:biogen-music,代码行数:32,代码来源:client.py

示例14: EEGRenderer

# 需要导入模块: from emokit.emotiv import Emotiv [as 别名]
# 或者: from emokit.emotiv.Emotiv import dequeue [as 别名]
class EEGRenderer():

    def __init__(self, channels, gheight):
        """
        Creates pygame window and graph drawing workers for each sensor.
        """
        pygame.init()
        self.screen = pygame.display.set_mode(resolution)
        self.graphers = []

        self.record_packets = []
        self.fullscreen = False
        self.recording = False
        self.updated = False
        self.middle_x, self.middle_y = resolution[0]/2, resolution[1]/2
        for i, name in enumerate(channels):
            self.graphers.append(Grapher(self.screen, gheight, name, i))

        self.emotiv = Emotiv(display_output=False)
        gevent.spawn(self.emotiv.setup)
        gevent.sleep(0)

    def handleEvents(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.emotiv.close()
                return
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.emotiv.close()
                    return
                elif event.key == pygame.K_f:
                    if self.fullscreen:
                        self.screen = pygame.display.set_mode(resolution)
                        self.fullscreen = False
                    else:
                        self.screen = pygame.display.set_mode(resolution, FULLSCREEN, 16)
                        self.fullscreen = True
                elif event.key == pygame.K_r:
                    if not self.recording:
                        self.record_packets = []
                        self.recording = True
                    else:
                        self.recording = False
                        self.recordings.append(list(self.record_packets))
                        self.record_packets = None


    def update(self, cursor_x, cursor_y):
        if self.updated:
            self.screen.fill((75, 75, 75))
            map(lambda x:x.draw(), self.graphers)
            pygame.draw.rect(self.screen, (255, 0, 255), [cursor_x, cursor_y, 5, 5], 5)
            pygame.display.flip()
            self.updated = False

    def main(self):
        while self.emotiv.running:
            self.handleEvents()
            packets_in_queue = 0
            try:
                cursor_x, cursor_y = self.middle_x, self.middle_y
                while packets_in_queue < 8:
                    packet = self.emotiv.dequeue()
                    if abs(packet.gyro_x) > 1:
                        cursor_x += packet.gyro_x-GYRO_DEFAULT
                    if abs(packet.gyro_y) > 1:
                        cursor_y += packet.gyro_y-GYRO_DEFAULT
                    map(lambda x: x.update(packet), self.graphers)
                    if self.recording:
                        self.record_packets.append(packet)
                    self.updated = True
                    packets_in_queue += 1
                cursor_x = self.middle_x + cursor_x / packets_in_queue
                cursor_y = self.middle_y + cursor_y / packets_in_queue
            except (Exception, KeyboardInterrupt) as e:
                raise e
    
            self.update(cursor_x, cursor_y)
            gevent.sleep(0)
开发者ID:ppasler,项目名称:current-adas,代码行数:82,代码来源:render.py


注:本文中的emokit.emotiv.Emotiv.dequeue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。