FlexSEA Wiki


User Tools

Site Tools


Python Library

This document describes the Python scripts that demonstrate how to control the Actuator Package. These scripts rely on the flexsea python library bundled with the required binary libraries precompiled for both Windows 32 and 64 bits (.dll), and Linux (.so) including Rapspbian and Ubuntu.

These scripts require Python 3.7.x and have been tested to work on the following platforms:

  • 32-bit and 64-bit Windows 10 Pro (timing and control speed is highly dependent on the hardware and system load).
  • armv7l Rasbian on a Raspberry Pi 4
  • x86_64 Ubuntu 18.04 and 20.04 64 bits.

Follow the instructions on the readme to install Python to your OS.

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 sample scripts. The fx_plan_stack API is encapsulated in the flexsea python library. More information on the API can be found here.

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

Before starting, set up your Actuator Package following it's ActPack's quick start guide.

Let's get started by running a demo script:

  1. Make sure your device has recent firmware
    1. It has to be newer than January 2021
    2. We recommend using the latest from the Release page
  2. Follow the instruction in the repository README to install the FlexSEA Library (copied below for your convenience)
    # Define your own virtual environment
    # this is not required but it helps to keep your environment clean
    python3 -m virtualenv --python=/usr/bin/python3.7 actpack
    # Activate your virtualenv
    source actpack/bin/activate
    # Once the environment is activated, install the package
    python3 -m pip install --upgrade pip 
    python3 -m pip install flexsea
  3. Clone the repo:
    git clone https://github.com/DephyInc/Actuator-Package.git
    cd Actuator_Package
    git update-index --assume-unchanged Python/flexsea_demo/ports.yaml
    1. The command above will download the repository and set it to the master branch.
    2. The second command allows git to ignore your changes to ports.yaml
    3. Optional: To switch to a specific branch use git checkout branchName
  4. Using your text editor of choice, edit /Python/flexsea_demo/ports.yaml by renaming the ports or uncommenting lines.
    1. If connecting to more than one device you can add additional port names following the template
    2. See below for a file example
  5. Plug the device in and turn it ON. If you are using Windows make sure that you have the STM32 Virtual Com Port Driver installed.
  6. From a cmd window or terminal, run the Actuator-Package/Python/flexsea_demo/run_demos.py script
    cd Python/flexsea_demo
  7. Enter the experiment number. Be careful, most of them will make the motor move!
    (actpack_test) carlos@Zef:~/dev/dephy/FlexSEA/Actuator-Package/Python/flexsea_demo$ ./run_demos.py
    	          Beyond Nature™          
    Read our important safety information at https://dephy.com/start/
    before running the scripts for the first time.
    Actuator Package Demo Scripts:
    [0] Read Only
    [1] Open Control
    [2] Current Control
    [3] Position Control
    [4] Impedance Control
    [5] Two Positions Control
    [6] High Speed Test
    [7] High Stress Test
    [8] Two Devices Position Control
    [9] Two Devices Leader Follower Control
    Advanced Utilities:
    [10] Bootloader Check
    [11] Find Poles
    Choose experiment number [q to quit]:

Launching the Demos Directly

All scripts can be run individually by calling them and passing arguments. Use –help to see usage information. See the example below using high_speed_test.py.

$ ./high_speed_test.py --help
usage: high_speed_test.py [-h] [-b B] Ports [Ports ...]
FlexSEA High Speed Test
positional arguments:
  Ports           Your devices' serial ports.
optional arguments:
  -h, --help      show this help message and exit
  -b B, --baud B  Serial communication baud rate.

The run_demos.py script accepts command line arguments. The first argument is the experiment number and the second (optional) is the number of devices. Calling Read Only directly (default = 1 device):

./run_demos.py 0

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

./run_demos.py 9 2


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

# ports.yaml
# Adjust the baudrate if needed and uncomment or edit the port list.
# Note that commented-out lines start with a `#`
# Also the ports list has dashes `-` before the values to signify a list
# See the sample ports values below depending on your platform
baud_rate: 230400
# Windows
  - COM3
  # - COM4
# Ubuntu WSL
  # - /dev/ttyS3
  # - /dev/ttyS4
# Native Linux (e.g. Ubuntu or Raspbian)
  # - /dev/ttyACM0
  # - /dev/ttyACM1


  • 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. This is not typical!
  • The leading cause of segmentation faults is a Device Spec mismatch between the embedded system and the scripts. This happens when you use old firmware with new scripts.
pythonscripts.txt · Last modified: 2021/01/30 03:52 by casmat