FlexSEA Wiki

A WEARABLE ROBOTICS TOOLKIT

User Tools

Site Tools


pythonscripts

Python Interface

This document describes the Python scripts that demonstrate how to control the Actuator Package. These scripts are accompanied by and are dependent upon C based libraries for both Windows (.dll) and Unix (.so). Pre-compiled libraries are provided for Windows 32 and 64 bits, Raspberry Pi and Linux (Ubuntu).

These scripts are written in Python 3 and have been tested on Python version 3.8 32 bit and 64 bit (using Windows 10 Pro), as well as 32 bit Rasbian on a Raspberry Pi 4 and Ubuntu 18 64 bits. Python versions lower than 3.7 are no longer supported. We recommend using 3.7+ 32-bit for a new install.

The code is available on GitHub at Actuator Package. This git repository contains the API, DLLs, and example scripts. The functions are documented in pyFlexsea.py. Additional documentation on the fx_plan_stack API can be found here.

Required Python packages

Use pip to install numpy, matplotlib, tornado and scipy.

Ex.: python -m pip install numpy

Converting from Python interface 2.0

The new Python interface addresses some shortcomings of the previous version. As the Python interface 2.0 is no longer supported, here is how to port your legacy code.

Quick Start

If you have not already setup up your Actuator Package, please read the ActPack's quick start guide.

Ready to get started? Try running a demo script:

  1. Make sure your device has recent firmware
    1. At a minimum it has to be newer than August 2018
    2. We recommend using the latest from the Release page
  2. Clone the repo :
    git clone https://github.com/DephyInc/Actuator-Package.git
  3. Copy Actuator-Package/Python/flexseapython/com_template.txt to a file named Actuator-Package/Python/flexseapython/com.txt
    • The first line is the baud rate. If connecting over USB or Bluetooth you can ignore the baud rate, otherwise please enter your desired rate.
    • The second line is the port name (ex.: COM5 or /dev/ttyACM0)
    • If connecting to more than one device you can add additional port names each on a new line
    • See below for a file example
    • Do not commit com.txt! We use com_template.txt to avoid pushing and pulling local changes.
  4. Plug in and turn on the device. If you are using Windows make sure that you have the STM32 Virtual Com Port Driver installed.
  5. From a cmd window or terminal, run the Actuator-Package/Python/fxMain.py script in Python
    python fxMain.py
  6. Enter the experiment number. Be careful, most of them will make the motor move!

Command line arguments

Since April 2020 the Python scripts accept command line arguments. The first argument is the experiment number and the second (optional) is the number of devices. To see a list of experiments do not include an argument:

python fxMain.py

Calling Read Only directly (default = 1 device):

python fxMain.py 0

Two Devices Leader Follower is #10 and it uses 2 devices. To launch it with one command:

python fxMain.py 10 2

Matplotlib

Some of the scripts (High-speed test, Impedance, etc.) include plotting. By default we use the WebAgg engine to show the plots in a browser. The first time you use the scripts you will need to install matplotlib and tornado (via pip). The plots will stop the Python program. A prompt will tell you how to get out of it. Typically, it's CTRL+C (Unix) or CTRL+BREAK (Windows).

com_template.txt and com.txt

com_template.txt:

# ***************** com.txt *****************
#
# Typical values shown in this file. May or may not work on your device.
# Bare minimum: two lines. Rest is optional.
# 1) First line without comments is baud rate (ex.: 230400)
# 2) Second line is the first port
# 3) List additional ports as needed.
#
# ******** Windows Example: ********
#
# 230400
# COM3
# COM4
#
# ******** Ubuntu ********
#
# 230400
# /dev/ttyS3 #(could also be /dev/ttyACM0)
# /dev/ttyS4
#
# ******** Raspberry Pi4 ********
#
# 230400
# /dev/ttyACM0
# /dev/ttyACM1

To use it, un-comment and/or modify the lines you need. Below is an example of that file used on Windows, with one port (COM5).

com.txt:

# ***************** com.txt *****************
#
# Typical values shown in this file. May or may not work on your device.
# Bare minimum: two lines. Rest is optional.
# 1) First line without comments is baud rate (ex.: 230400)
# 2) Second line is the first port
# 3) List additional ports as needed.
#
# ******** Windows Example: ********
#
230400
COM5
# COM4
#
# ******** Ubuntu ********
#
# 230400
# /dev/ttyS3 #(could also be /dev/ttyACM0)
# /dev/ttyS4
#
# ******** Raspberry Pi4 ********
#
# 230400
# /dev/ttyACM0
# /dev/ttyACM1

Notes

  • If you encounter problems with the DLLs, here are some useful tips.
  • If your device has never had poles configured, you should run “find poles” from the demo script before trying other demos
pythonscripts.txt · Last modified: 2020/08/20 18:57 by jfduval