- Custom Development
To learn the basics and how to install Python please refer to the original article: Actuator Package: Python scripts.
The new python interface addresses some short comings of the previous version. The main features are:
The new interface is available from the dev branch of the git repo under the Python folder (Not sure how to clone a repo? Please refer to Source Code). The new access functions are documented in pyFlexsea.py. Take a look at the new python demo scripts to see examples of the interface usage, and look here for an overview of the API functions.
Ready to get started? Try running a demo script:
git clone -b dev –recursive https://github.com/DephyInc/Actuator-Package)
If you encounter problems with the DLLs, refer to the General Hints Page for helpful actions.
The main functionality change is that the new interface allows you to connect to multiple devices at a time. This means that 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:
There are however several changes to the interface that should simplify your code:
The utility function loadAndGetDevice() should simplify your initialization to one line. It can be used in two ways
loadAndGetDevice( filename, numDevices)
loadAndGetDevice( 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:
There are however, several exceptions which should mostly simplify your code:
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.
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.
All controller commands simply take the device id handle, and are mentioned in the above section.
Before you start, install the following tools:
Detailed instructions: Install Build Tools (Windows).
First, navigate to the directory you'd like to contain all the source code.
Clone the code repositories:
git clone https://github.com/DephyInc/serial.git git clone --recursive https://github.com/DephyInc/FlexSEA-Stack-SharedLib.git git clone --recursive https://github.com/DephyInc/Actuator-Package.git
Compile the serial library:
cd serial git checkout dev mkdir build && cd build cmake .. #See note 1) make #See note 2)
Compile FlexSEA-Stack-SharedLib (see note 3):
cd ../../FlexSEA-Stack-SharedLib mkdir build && cd build cmake .. make
The libs are built inside a directory depending on your platform. 'win' for windows, 'unix' for unix. Copy the libs from the build directory to the folder where they'll be used. You can do that graphically, or via command line. What you want is to have libserialc.a and libFlexSEA-Stack-Plan.a in the fx_plan_stack\lib folder.
cp serial/build/unix/libserialc.a Actuator-Package/fx_plan_stack/lib/ cp FlexSEA-Stack-SharedLib/Release_static/libFlexSEA-Stack-Plan.a Actuator-Package/fx_plan_stack/lib/
cd Actuator-Package/fx_plan_stack mkdir build && cd build cmake .. make
Test the lib:
cmake .. -G "MinGW Makefiles"