FlexSEA Wiki

A WEARABLE ROBOTICS TOOLKIT

User Tools

Site Tools


python_interface_conversion

Converting from Interface 1.0 to Interface 2.0

The most noticeable new features are:

  • Multi-device connections are now possible
  • Improved communication and control between the computer and the FlexSEA device

As the new interface allows you to connect to multiple devices at a time, the interface needs some way for you to specify which device you intend to interact with at any given time. This handle is the device id. You can get a full list of available device ids by calling fxGetDeviceIds(). Thus for the most part, function calls will change in the following format:

foo(args…) → foo(devId, args…)

This is true of the following functions:

  • actPackFSM2
  • findPoles
  • setControlMode
  • setMotorVoltage
  • setMotorCurrent
  • setPosition
  • setZGains has been renamed setGains

There are however several changes to the interface that should simplify your code:

Initialization

The utility function loadAndGetDevice() should simplify your initialization to one line. It can be used in two ways

loadAndGetDevice( filename, numDevices)

  • filename contains the path to a txt file where each line is a com port
  • numDevices contains the number of devices we expect to be connected

loadAndGetDevice( comPortList )

  • comPortList contains a list of strings specifying ports to open
  • numDevices is implicitly set to len(comPortList)

The function opens all specified COM ports and waits until fxGetDeviceIds provides a list of ids that is at least numDevices long. On success, the function returns this list. Otherwise the function calls sys.exit().

If you'd like to write the initialization yourself, note the following changes in API functions:

  1. initPyFlexsea() → loadFlexsea()
  2. initControlVariables() → No longer needed
  3. setPyFlexSEASerialPort(s) → fxOpen(port, idx)
    • instead of creating a serial object and passing it to the interface, you simply give the port name and port index
    • the port index isn't really used after this, so as long as you use a different index for each port name you should be fine

There are however, several exceptions which should mostly simplify your code:

  1. initPyFlexsea() → loadFlexsea()
  2. initControlVariables() → No longer needed
  3. setPyFlexSEASerialPort(s) → fxOpen(port, idx)
    • instead of creating a serial object and passing it to the interface, you simply give the port name and port index
    • the port index isn't really used after this, so as long as you use a different index for each port name you should be fine

Streaming and Reading Data

Since the interface now abstracts communication protocols from the user this process is greatly simplified. To start streaming data from the device (and simultaneously stream control commands to the device) use the following

setSuccess = fxSetStreamVariables(devId, varsToStream) #varsToStream is a list of field ids taken from pyFlexsea_def.py
streamSuccess = fxStartStreaming(devId, frequencyInHz, shouldLogToFile, shouldUseAutoStreaming) 
#frequencyInHz must match a frequency in FX_VALID_FREQUENCIES from pyFlexsea_def.py

Note: The same function is used for different devices (rigid vs. pocket). You are expected to provide field ids that are valid for the device specified by devId.

The interface starts streaming data from the device, and populating an internal buffer with received data. The process for reading data is as follows:

dataValues = fxReadDevice(devId, fieldIds) #fieldIds is a list of field ids whose values are retrieved

dataValues is then populated with the values of the requested field ids, in the order requested. If an error occurred while fetching a field (fieldId invalid, or field not accessible because it's not being streamed) the value will be None.

Printing Data

Previous utility functions printRigid() and printPocket_s are replaced by printData(labels, values), where you should provide labels, a list of string which matches the length of values.

Sending Controller Commands

All controller commands simply take the device id handle, and are mentioned in the above section.

python_interface_conversion.txt · Last modified: 2019/04/15 17:40 by flabelle