FlexSEA Wiki

A WEARABLE ROBOTICS TOOLKIT

User Tools

Site Tools


actpackpython

Actuator Package: Python scripts (Deprecated)

Table of Contents

Description

These scripts have been replaced by the Python Interface 2.0. Do not use these for new development.

This document describes Python 3 scripts to demonstrate control of the FlexSEA-Rigid electronic controller & motor. These scripts are acompanied by and are dependent upon C based libraries for both Windows (.dll) and for the Rasbian OS (.so). A preliminary version of the C library for Ubuntu operating systems can be available upon request.

These scripts are written in Python 3 and have been tested on Python version 3.6 32 bit and 64 bit Windows 10 Pro, as well as 32 bit Rasbian on a Raspberry Pi 3.

Contact Information

Both the electronics hardware and accompanying firmware & software are developed by Dephy Inc. Specifically by:
JF Duval, email: jduval at dephy dot com

Quick Installation and Setup

Requirements:

  • Python version 3.X 32 bit
  • Pyserial version 3.4
  • STM32 Virtual Com Port Driver (for windows only)
  • Clone or download the code repository

Windows only pre setup

Windows and Rasbian setup

  1. Connect the FlexSEA board to your computer via a USB cable using the micro USB connection labelled 'Mn' mounted closest to the main processor. Note: on Rigid 0.2 there is only 1 USB connector; it's the one you need.
  2. Turn on the FlexSEA. Your computer should see the board and assign it a COM port number. Make sure that the name in com.txt matches the COM number your computer assigned. findPorts.py can help you find available ports.
    For Windows this will be something like 'COM2', or 'COM3', or 'COM4', etc.
    For Rasbian this will probably be '/dev/ttyACM1' or '/dev/ttyACM0'
  3. To power the motor connect the main power leads to a 20V power supply. Sensor readings will all work even when the motor isn't powered, but any commands sent to move the motor won't work.
    Note: the supported voltage range is 15-48V. 20V is a good, safe value for initial testing.
  4. Run the Python script of your choice. A description of each script's behavior is given at the top of each python file.

Detailed Installation and Setup for Windows

Install Python version 3.x 32 bit(most current version is 3.6 as of this writing)

  1. Go to python.org/downloads and download a recent version if you don't already have it on your computer. be sure to get the 32 bit distribution as the FlexSEA libraries are made for 32 bit.
  2. Follow the Python installer instructions and they should guide you through the process rather painlessly. Agree to have Python and its modules be added to your PATH.
  3. Open a command prompt and verify that Python is installed and is on your PATH by typing: python –version from your command prompt window. You should see: »> Python 3.6.1 :: (32-bit) or something similar.

Install the Pyserial library

  1. Versions of Python 3.4 and later come with a built-in Python library installer called pip. Assuming you agreed to have Python modules added to your PATH during installation you will now be able to call pip directly from your command prompt.In your command prompt type: pip install pyserial This starts the download and configuring process.
    If pip is not on your PATH you can still call it from within a Python session or script. From your command prompt type: python -m pip install pyserial more details can be found at: 'https://pyserial.readthedocs.io/en/latest/index.html'

Install the Virtual Com Port driver

In order for your computer to be able to connect to the STM32 chip you'll need a special driver. Install the STM32 Virtual Com Port Driver.

Connect FlexSEA to your computer

  1. Connect the FlexSEA board to your computer via a USB cable using the micro USB connection labelled 'Mn' mounted closest to the main processor, not 'Ex' or 'Reg'.
    Note: on Rigid 0.2 there is only 1 USB connector; it's the one you need.
  2. Your computer should see the board and assign it a COM port number. Make sure that the name in com.txt matches the COM number your computer assigned. findPorts.py can help you find available ports. For Windows this will be something like 'COM4', or 'COM5'. You can see your computer port names using Windows Device Manager and checking the 'Ports (COM & LPT)' section.
  3. Power the motor by connecting the main power leads to a 20V power supply. Sensor readings will all work even when the motor isn't powered, but any commands sent to move the motor won't work.
    Note: the supported voltage range is 15-48V. 20V is a good, safe value for initial testing.

Run your first program

  1. Run the script FlexSEA_Demo_ReadOnly.py by calling it from your command prompt. Type: python FlexSEA_Demo_ReadOnly.py Into your command prompt. If everything is working then you should be seeing realtime readings from the FlexSEA board.
  2. To start off with simple interaction with the FlexSEA you can run and modify FlexSEA_Demo_UserDefined.py, which currently defines two main functions, a main_loop_fuction() hat is executed every iteration and an exiting() function that is called once when you end the program.

Detailed Installation and Setup for Raspbian

Python3 32-bit

  1. Raspbian comes pre-installed with Python versions 2.7.x and Python 3.x 32-bit. Because of potential name conflicts you have to specify the version you want each time you call it. To verify your Python3 installation type: python3 –version in your terminal

Install the Pyserial library

  1. Versions of Python 3.4 and later come with a built-in Python library installer called pip. You will be able to call pip directly from your terminal to install common Python libraries. Unlike the Windows setup the default pip on Raspbian is configured for version 2.7. As in Step 1 we must specify python3. From your command terminal type: python3 -m pip install pyserial This starts the download and configuring process.
    more details can be found at 'https://pyserial.readthedocs.io/en/latest/index.html'

Connect FlexSEA to your computer

  1. Connect the FlexSEA board to your computer via a USB cable using the micro USB connection labeled 'Mn' mounted closest to the main processor, not 'Ex' or 'Reg'.
    Note: on Rigid 0.2 there is only 1 USB connector; it's the one you need.
  2. Your computer should see the board and assign it a port number. Each Python script has a 'COM' variable defined near the top. Make sure this variable matches the port name your computer assigned to FlexSEA. For Raspbian this will be something like '/dev/ttyACM0', or '/dev/ttyACM1'. You can see your computer port names by typing: ls /dev/tty* with your FlexSEA board disconnected and then while connected to see which port is added. To power the motor connect the main power leads to a 20V power supply. Sensor readings will all work even when the motor isn't powered, but any commands sent to move the motor won't work.

Run your first program

  1. Run the script FlexSEA_Demo_ReadOnly.py by calling it from the terminal: python3 FlexSEA_Demo_ReadOnly.py If everything is working then you should be seeing realtime readings from the FlexSEA board.
  2. Start off with simple interaction with the FlexSEA by running and modifying FlexSEA_Demo_UserDefined.py, which currently defines two main functions, a main_loop_fuction() hat is executed every iteration and an exiting() function that is called once when you end the program.

Files in This Package

Several files are included along with your FlexSEA actuator. Here is a brief description of each one for your referece

FlexSEA_Demo_ReadOnly.py

This is the simplest script as it does not activate the motor at all. All the major sensors will be displayed in the terminal. Run this script as a first 'Hello World' to ensure that your FlexSEA environment is properly configured and your board is streaming readings to your computer.
To exit the script while it's running press Ctrl+C.

FlexSEA_Demo_OpenSpeed.py

This script demonstrates speed control of the FlexSEA. The Motor will ramp up, spin at a constant speed, then ramp down and stop. This cycle will repeat forever. All the major sensors will be displayed in the terminal.
To exit the script while it's running press Ctrl+C.

FlexSEA_Demo_Impedance.py

This script demonstrates an impedance controller operating on the FlexSEA. The motor will toggle between two equilibrium positions, forever.
All the major sensors will be displayed in the terminal. The controller gains when moving to the first and second position are set by the impedance gain values Z_K_a, Z_B_a, Z_K_b, and Z_B_b in the script. These values can be adjusted to tune performance when the motor is under different loads, or is unloaded.
For this example the positions that the FlexSEA oscillates between are absolute positions defined when the board is powered on, and are not related to the motor position when the script is run. It's a good idea to run this script only directly after the FlexSEA board is powered on and before the motor is moved.
It is important to use a high quality power supply when running this demo as the control can become unstable with a switch-mode power supply or any power supply with too low of a current limit.
To exit the script while it's running press Ctrl+C.

FlexSEA_Demo_PositionControl.py

This script demonstrates a position controller operating on the FlexSEA. The motor will hold the starting position and return to it after perturbation.
All the major sensors will be displayed in the terminal. The controler feedback gain values pos_KP and pos_KI are specified in the script. These values can be adjusted to tune performance when the motor is under different loads, or is unloaded.
For this example the position that the FlexSEA holds is defined as the starting postion when the script is run.
It is important to use a high quality power supply when running this demo as the control can become unstable with a switch-mode power supply or any power supply with too low of a current limit.
To exit the script while it's running press Ctrl+C.

FlexSEA_Demo_TwoPositionControl.py

This script demonstrates a position controller operating on the FlexSEA. The motor will toggle between two equilibrium positions, forever.
All the major sensors will be displayed in the terminal. The controller gains when moving to the first and second position are set by the feedback gain values pos_KP and pos_Ki in the script. These values can be adjusted to tune performance when the motor is under different loads, or is unloaded.
For this example the positions that the FlexSEA oscillates between are the initial position defined when the script is run and a postion approximately 90 degrees from this.
It is important to use a high quality power supply when running this demo as the control can become unstable with a switch-mode power supply or any power supply with too low of a current limit.
To exit the script while it's running press Ctrl+C.

FlexSEA_Demo_CurrentControl.py

This script demonstrates a current controller operating on the FlexSEA. The motor will attempt to draw a constant current from the connected power supply.
All the major sensors will be displayed in the terminal. The current controller gains are set by the feedback gain values I_KP and I_Ki in the script. These values can be adjusted to tune performance when the motor is under different loads, or is unloaded.
It is important to use a high quality power supply when running this demo as the control can become unstable with a switch-mode power supply or any power supply with too low of a current limit.
To exit the script while it's running press Ctrl+C.

FlexSEA_Demo_UserDefined.py

This script is meant to be an easy starting template for getting familiar with the FlexSEA actuator.
Currently the motor will not move and all the major sensors will be displayed in the terminal. When the script ends some tracked values are displayed in the terminal. An easy way to start developing on the FlexSEA is to modify the MAIN_LOOP_FUNCTION in this file with your own code
To exit the script while it's running press Ctrl+C.

pyFlexSEA.py

This file contains the Python wrappers for the C library that is used to communicate with the FlexSEA board. The function named 'readActPack()' has as parameter named 'displayFlexSEA'. You can set this to True or False to control whether or not you want the sensor information printed to the terminal window. You shouldn't need to modify anything else in here.

pyFlexSEA_Def.py

This file contains necessary structures used in the FlexSEA environment. You shouldn't need to modify anything in here.

Trouble Shooting

“I can't connect to FlexSEA over USB”

This is probably one of three issues: you have the wrong Python distribution. Check that it is version 3.4 or newer and 32-bit you have the wrong pyserial library. Check that you have the correct one for python3, not python2 you're trying to connect to the wrong COM port. Check that you have the right port listed in com.txt, probably 'COM4' or 'COM5' for Windows, and '/dev/ttyACM0', or '/dev/ttyACM1' for Raspbian.

“The refresh rate on my scripts is fluctuating a lot”

The frequency we are displaying is an estimate of how quickly the Python script is running, but it's not perfect. Especially at higher speeds it's more subject to error because of imprecision in your system's clock.

“There's some error about not finding or loading a library”

There are three libraries sent in this package, a .dll for Windows a .so for Linux, and a different .so for Rasbian. In the script pyFlexSEA.py in the function initPyFLexSEA() one of these libraries is being loaded in a try-except block. If this is causing problems you can replace the block with one of the following: flexsea = cdll.LoadLibrary('lib/FlexSEA-Stack-Plan') #Windows or flexsea = cdll.LoadLibrary('lib/libFlexSEA-Stack-Plan.so') #Linux or flexsea = cdll.LoadLibrary('lib/rpiFlexSEA-Stack-Plan.so') #Raspbian The correct library should be loaded automatically, but if it is not, then removing the try- except block and hardcoding a specific library should be fool proof, so long as you don't switch operating systems.

“The sensor values in the display are flickering or not refreshing often enough”

The rate at which we communicate with the FlexSEA is not the same rate at which we print values on the display for you to see. The easiest way to adjust the display frequency is to change the displayDiv value defined near the top of each Python script. Lowering the value will print sensor readings more frequently. Feel free to adjust this as you please, just know that refreshing the display too often can slow down calculations. The parameter displayDiv does need to be an integer greater than 1.

“I can't speed up the scripts beyond ~400 Hz”

This is the maximum we have been able to reach too.

“I have a problem that isn't one the four described here”

Send us an email!
actpackpython.txt · Last modified: 2018/11/15 15:01 by dtscbs