Forum Software EmotivBCI BCI – OSC capturing output of example python OSC script

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1661
    Frost Sebastian Kai
    Participant
      @e50204da-64be22d3a5a00

      Hi there, I’m writing a project to trigger an event based on an OSC “lift” event from my headset I’ve gotten the python OSC example script working and connecting to EmotiveBCI. And when I run it it gives me the following

      /com/neutral: (0.0,)
      /com/neutral: (0.0,)
      /com/lift: (0.34032198786735535,)
      /com/lift: (0.460563987493515,)
      /com/lift: (0.562188982963562,)

      on an infinite loop. I’d like to capture and execute a block of code when a /com/lift event is detected but I don’t see how to access that stream in the code. My python is so-so and as far as I can see that output is generated by the line.

      server.serve_forever()

      How would I go about capturing the output and triggering executing further code based on a lift event? I can’t find any other good examples and am a bit stuck.

      Thanks in advance.

      #1662
      Frost Sebastian Kai
      Participant
        @e50204da-64be22d3a5a00

        I’ve managed to write this into the filter handler which works and prints “found lift” when I think that command. But I now want the program to return a value and exit but the “serve forever” part  means I can kill my thread but it just starts up looping again.

        How do I make it so the server exits cleanly and returns a required value once the command is detected?

        def filter_handler(address,*args):
        # print(f”{address}: {args}”)
        if (address == “/com/lift”):
        print(“Found lift”)

        #1663
        luckham jerill
        Participant
          @starex12-6058fa0f16135

          Hello Sebastian,

          Thank you for your post.   Please try the script below:

          # Regular expression to match lines with “lift”
          lift_pattern = re.compile(r’/com/lift:\s+\((\d+\.\d+)\)’)

          # Function to extract data values
          def extract_lift_values(stream_data):
          lift_values = []
          lines = stream_data.strip().split(‘\n’)
          for line in lines:
          match = lift_pattern.search(line)
          if match:
          lift_value = float(match.group(1))
          lift_values.append(lift_value)
          return lift_values

          # Call the function to get the lift values from the stream
          lift_values = extract_lift_values(stream)
          print(lift_values)
          `

           

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.
        Login