Cyton defaults referential, or differential like Ganglion? / Python command automation

edited April 2017 in Cyton
Within the Python SDK, when streaming data to the dongle and reading real time at either the terminal or outputting to a .csv, what are the potentials at each channel in reference to?
The Readme doc provides: 

"Basic usage

The startStreaming function of the Board object takes a callback function and begins streaming data from the board. Each packet it receives is then parsed as an OpenBCISample which is passed to the callback function as an argument.

OpenBCISample members: -id: int from 0-255. Used to tell if packets were skipped.

-channel_data: 8 int array with current voltage value of each channel (1-8)

-aux_data: 3 int array with current auxiliary data. (0s by default)"

but it doesn't disclose whether the potentials at each channel are in reference to a common reference (SRB2) or whether they are referenced to the N and P of each respective channel. 
I'm sure with some digging/experimenting this can be figured out, but if someone had this information so that I could skip a few steps, I'd really appreciate it!

Best,

Mike


Comments

  • wjcroftwjcroft Mount Shasta, CA
    edited February 2017
    The default CHAN SET settings are SRB2 reference. You only get N P differential pins if you use the CHAN SET tab in the GUI. See the Cyton tutorial for more info.
  • wjcroftwjcroft Mount Shasta, CA
    See this section for the commands to do CHAN SET operations without the GUI,

  • @wjcroft

    I'm having a bit of trouble feeding those commands via the python SDK. For my purpose, I'm plugging in values of "s" directly into a modified "user.py" class and running a separate script to call user so that "user" calls the appropriate functions automatically (without any user input).
    However, since the code is not constantly checking for a change in "s"  (presumably where I'd feed in channel setting commands), is it possible to force communication with the board to change these settings directly (before or after starting to stream?)? There seems to be a "board" object called with multiple functions (an example being boardThread = threading.Thread(target=board.start_streaming, args=(fun, lapse))), is it possible to send the channel setting commands directly to board?

    Any insight you could provide would be very appreciated!

  • wjcroftwjcroft Mount Shasta, CA
    Are you using x and X commands as shown here,


    Removing the channel from SRB* and Bias is how you would achieve differential.

  • @wjcroft

    I am using the x and X commands, however since I'm running the user file (modified) from a separate script, I can't feed in commands via the UI. How would I go about applying those commands implicitly within "user.py" or another class?

  • wjcroftwjcroft Mount Shasta, CA
    Jeremy Frey @jfrey might have some insights how you can automate the input of commands. He is the Python framework developer. If you are using x and X, why did you mention 's'?
  • I was initially using "s" to start streaming from the board (which works), then sleeping the UI while the board streams and writes to a csv. After its finished, it closes and I can recall the "user.py" class (acting as a function in my case) and gather new data. Analysis on the data is performed after the board stops streaming (end of sleep) each iteration, rather than analyzing realtime in a separate thread (which could be messy since it's writing to the csv that I'm analyzing. 
    I thought that 's' could be used to feed the channel setting commands to the board, but it doesn't seem to be responding to the commands. I still think that feeding the command through 's' might be the way to do it, but I'm having trouble figuring out when to do it. If I set s='xMysettingsX' prior to where I place s='/start' the board doesn't respond to the command (presumably because s isn't checking for xX setting commands?)

  • wjcroftwjcroft Mount Shasta, CA
    Ah, sorry for the confusion, you are referring to the 's' variable in the Python code, not the 's' command sent to the board firmware.

    Hoping Jeremy will have some suggestions.
  • Problem solved, the key was forcing the board to update sooner by moving:
                  for c in s:
                    if sys.hexversion > 0x03000000:
                        board.ser.write(bytes(c, 'utf-8'))
                        print('writing utf-8')
                    else:
                        board.ser.write(bytes(c))
                        print('writing alternative')
                    time.sleep(0.100)

    to be before starting the streaming thread but after defining the channel settings.
  • wjcroftwjcroft Mount Shasta, CA
    Mike, thanks!

    @jfrey I think will likely incorporate this in the Github repo, since it may help others trying to automate commands to the board.

    William
  • wjcroftwjcroft Mount Shasta, CA
    Mike can you log your issue and solution at the repo? Then your fix can better be incorporated by @jfrey or other Python developers.


  • @wjcroft
    Truthfully, it isn't a fix the Python developers should implement. Although my solution does work, it's far from ideal. The correct solution would have been to change the default channel settings during initialization. In order to avoid having to modify the Cyton firmware the Python hack was my work around.

    If anyone wants the details feel free to contact me and I'll post what I did. I should note that the key to changing the settings through the user.py file was to use board.ser.write(bytes(c)) where c is the command to the board. You can verify that the commands were received through the board.ser.read while loop that is used at the end of the user class. Also,make sure to place the ser.write fnxn must be placed after the board thread has been started!

  • Hello,

    If you manage to set these custom commands, good work!

    I don't have the opportunity to dwell into the code right now, but I guess that you could send whatever string (xX...) in a modified user.py file, around line 180, where it inits the board (maybe it is what you did, though). However, there might be a problem if for whatever reason the board si stopped/started again during streaming, because this configuration should be sent again...

    I guess that could be an "official" feature for the python repo, where the user could specify a parameter to user.py, a string that would be sent to the board.

    Good luck with the modification, dont't hesitate to make a bug report or, even better to do a pull request, as suggested by william ;)
Sign In or Register to comment.