FlexSEA Wiki

A WEARABLE ROBOTICS TOOLKIT

User Tools

Site Tools


interface_conversion_3_to_4

This is an old revision of the document!


Converting from Stack 3.0 Interface to Stack 4.0 Interface

Table of Contents

Overview

New features:

  • Increased stability
  • Unified stack for GUI and scripts
  • Easier-to-use, cleaner API
  • Error codes (Exceptions in Python)

Deprecated:

  • fxSetup and fxCleanup
  • fxSetStreamVariables
  • Python Stream class
  • portIdx (everything is based on device ID now, returned by fxOpen)
  • commManager

Initialization

Before:

Before doing anything you would have to call fxSetup(). For Python scripts the Stream class would be used to open a device. Otherwise you could use fxOpen to open a device at the selected port, then you would use fxGetDeviceIds and select a device ID to use for all the subsequent API functions.

After:

Call fxOpen with the desired serial port name, baudRate (230400 is a good default), and debug logging level (0-6, with 0 being the MOST verbose and 6+ being the LEAST verbose). fxOpen returns the device ID which will be used in all subsequent API functions.

Deprecated:
  • fxSetup
  • Python Stream class
C Example
// Open a device at port ACM0 with baud 230400 and most verbose logging
// Save the returned device ID as a variable
// If devId == -1 then the device is invalid
int devId = fxOpen('/tty/ACM0', 230400, 0);

Reading Device Data and Streaming

Before:

To read device data you would start streaming, then set the variables you want to stream, then run fxReadDevice (or Stream on Python) to get the read results. The variables to stream are defined as indices into a larger array which contains all of the possible read data.

After:

Now to read device data, you start streaming then call fxReadDevice with an ActPackState pointer to fill which will then contain all the valid read data unless the read was unsuccessful. Unsuccessful reads are reported by the fxReadDevice returned error code.

In Python fxReadDevice simply returns the ActPackState containing all read data or throws an exception if the read was unsuccessful.

C Example
// Start streaming on device 77 at 100Hz and save the data log
fxStartStreaming(77, 100, true);
// Local ActPackState to populate
ActPackState actPackState;
// Read the device state data from device 77
ErrorCode = fxReadDevice(77, &actPackState);
Python Example
# Start streaming on device 77 at 100Hz and save the data log
fxStartStreaming(77, 100, True)
# Read the device state data from device 77
# Throwable
actPackState = fxReadDevice(77)

Sending Commands

Before:

To send a motor command you must first specify the gains (except for open controller), then the control type, then you must use the set* command corresponding to your selected control type.

After:

Now to send a motor command you must specify the gains (except for open controller), then call fxSendMotorCommand with your desired control type and value setpoint.

C Example
// Set the proportional gain of device 77 to 100 and the integral gain to 30
fxSetGains(77, 100, 30, 0, 0, 0);
// Set the motor voltage of device 77 to 1500mA.
fxSendMotorCommand(77, FxCurrent, 1500);

API Changes

fxSetup() and fxCleanup() are both deprecated. The Python Stream class is deprecated.

Function by function before and after:

Before:

void fxOpen(char* portName, int portIdx);

After:

int fxOpen(const char* portName,
                const unsigned int baudRate,
                const unsigned int logLevel);
  • Returns device ID.

Before:

uint8_t fxIsOpen(int portIdx);

After:

bool fxIsOpen(const unsigned int deviceId);

Before:

void fxClose(uint16_t portIdx);

After:

FxError fxClose(const unsigned int deviceId);

Before:

void fxGetDeviceIds(int *idarray, int n);

After:

void fxGetDeviceIds(int* const idArray, const unsigned int size);

Before:

uint8_t fxStartStreaming(int devId, int freq, bool shouldLog, int shouldAuto);

After:

FxError fxStartStreaming(const unsigned int deviceId,
                        const unsigned int frequency,
                        const bool shouldLog);

Before:

uint8_t fxStopStreaming(int devId);

After:

FxError fxStopStreaming(const unsigned int deviceId);

Before:

int* fxReadDevice(int devId, int* fieldIds, uint8_t* success, int n);

After:

FxError fxReadDevice(const unsigned int deviceId, ActPackState* readData);

Before:

void setGains(int devId, int g0, int g1, int g2, int g3);

After:

FxError fxSetGains(const unsigned int deviceId,
                        const unsigned int kp,
                        const unsigned int ki,
                        const unsigned int kd,
                        const unsigned int K,
                        const unsigned int B);
  • Now the gain parameters correspond to their real-life equivalents. kp for position gain, ki for integral gain, kd for differential gain, K for stiffness, and B for damping.
  • K (stiffness) and B (damping) are used in impedance control mode only.

Before:

void setControlMode(int devId, int ctrlMode);
void setMotorVoltage(int devId, int mV);
void setMotorCurrent(int devId, int cur);
void setPosition( int devId, int pos );

After:

FxError fxSendMotorCommand(const unsigned int deviceId, const FxControlMode controlMode, const int value);
  • Now motor commands take a value and FxControlMode (defined above) instead of being divided across multiple commands.
  • For more information see Sending Commands

Before:

void findPoles(int devId, int block);

After:

FxError fxFindPoles(const unsigned int deviceId);
interface_conversion_3_to_4.1580833126.txt.gz · Last modified: 2020/02/04 16:18 by rqurashi