Using Instrumentino v02
Using Instrumentino v02
Using Instrumentino v02
(04/2014)
Instruction Manual
Written By:
- Joel Koenka
- Roland Fuiko
1. Description
Instrumentino is a graphical user interface (GUI) program, written in Python
(version 2.7), which allows control of experimental settings, using controllers
such as Arduino. It also includes a lean software package for the Arduino itself
for the communication protocol (Controlino).
2. Motivation
The motivation to develop this program was to create an easy-to-use powerful
way to control purpose made systems. Programming is not something that
most people are comfortable with, so Instrumentino is built to minimize the
programming efforts required, while giving a comfortable uniform way to
control and run experiments. Python is well suited for that purpose, being a
very popular high-end language, which is easily learned and for which plenty of
online help exists in forums (just google how to do this and that using
Python).
3. Features
A single system dependent file describes system components (e.g. valves,
pumps, pressure and voltage controllers) with their relevant system variables
(e.g. valve state, plunger location, pressure, voltage and current) and basic
actions, which change these variables in order to achieve something (e.g. flush
interface, flush capillary, perform a HV separation); each action can receive
parameters (such as pressure, time, voltage).
These actions can be then added in a list to create methods (can be saved as a
.mtd files and loaded later), and saved methods can be added to a list to create
sequences (can be saved as .seq files and loaded as well). A method or a
sequence can be run by the user and stopped when needed, using the big
STOP button. During each run, each action is logged to a file for future
reference.
After initial connection to the relevant hardware controller (such as an Arduino),
system variables are monitored and their values are periodically updated on
the left panel, as well as graphically plotted in the log panel.
4. Requirements
In order to use Instrumentino, you should know Python to some extent and
install some programs in order to create and run the project.
Download and untar the instrumentino package from the CPC Program
Library.
Install Python 2.7, 32 bit (e.g. from
https://www.python.org/download/releases/2.7)
Install (using easy_install) the Instrumentino egg file (supplementary
material/Instrumentino/dist).
Install the following Python packages:
o pySerial
o wxPython (agw might be necessary as well)
o matplotlib
Create a system description file (e.g. supplementary material/example
run (container.py)/container.py) See section 5.
Execute the file this will start the software
There are several ways of installing the necessary Python software, the one I
prefer is Enthought Canopy. Canopy is a Python distribution that includes
(among other things) a visual way to install python packages.
In order to edit and run python programs, we recommend the open source
Eclipse integrated development environment (IDE).
5. Install on Mac OS
Following are the steps for starting to use Instrumentino on a Mac, using
Canopy and Eclipse.
Install Canopy:
https://www.enthought.com/downloads/
This will install Python and some common packages in the computer. You
need to register first with an academic email address and request an
academic license (this takes only a few minutes to complete). Only then
can you download the Canopy Full Installer, please use the 32 bit version.
To check if the installation was done properly, open a Terminal and type
python. Check that the Python version is 2.7.X, as Instrumentino was
written using python 2.7
Open Canopy, and choose Package manager. Install the following
packages: wxPython, matplotlib, pyserial
To write and test your code, an IDE (Integrated Development
Environment) would come in handy. A good free option is Eclipse:
http://www.eclipse.org/downloads/
Install either the Standard version or the Java version of the newest
stable release. If it gives you error (from unidentified user) then go to
system preferences and Tick window, which allows you to open Eclipse.
Eclipse is an IDE that supports many programming languages, and the
program became so big that the developers decided to release different
versions of Eclipse. In order to develop Python programs in Eclipse, an
additional plugin named PyDev (described next) is needed. From my
experience, this works for Eclipse versions supporting Java but not for
Eclipse versions for C/C++.
Open Eclipse, and install PyDev. To install plugins in Eclipse:
o Go to the Help menu and choose Install New Software.
o Click the Add button and enter these details:
Name: PyDev (This doesnt really matter)
Location: http://pydev.org/updates
o Uncheck the 'Contact all update sites during install to find required
software, as
o Tick everything in the window and continue according to the
instructions. Agree when asked to trust the certificates.
o Restart Eclipse
Install the Instrumentino framework egg by running the following
command in the directory where it is stored (supplementary
material/Instrumentino/dist):
easy_install instrumentino-1.0-py2.7.egg (replace the filename if
needed).
Test if its installed by running python in the terminal and typing import
instrumentino
Create a workspace directory for code projects e.g.
Documents/workspace/Instruments/mySystem might be a good choice.
Start a PyDev project. It should have one python file for the system
description (e.g. mySystem.py). For an easy start, use a ready file from
another system (e.g. supplementary material/example run
(container.py)/container.py) and change it, according to your systems
requirements.
To run the code, open the file mySystem.py and while in PyDev view,
choose the menu Run>Run. Alternatively, you can open a terminal,
navigate to where mySystem.py is and type python mySystem.py
6. Install on Windows 7
Following are the steps for starting to use Instrumentino on Windows 7 (32bit or
64bit), using Canopy and Eclipse.
Install Canopy 1.5.1:
https://www.enthought.com/downloads/
This will install Python and some common packages in the computer. You
need to register first with an academic email address and request an
academic license (this takes only a few minutes to complete). Only then
can you download the Canopy Full Installer, please use the 32 bit version.
To check if the installation was done properly, open a Terminal (cmd.exe)
and type C:\python. Check that the Python version is 2.7.X, as
Instrumentino was written using python 2.7
Open Canopy 1.5.1 and uninstall the wxPython 2.8.10.1-7 package with
the Package Manager. Further check the versions of the following
packages:
o Matplotlib 1.4.2-2
o Pyserial 2.6-1
If the versions differ, the appropriate versions can be installed via the
package manager, or downloaded at the according website.
Download and install the wxPython 3.0.2 package for 32bit and Python
2.7
http://downloads.sourceforge.net/wxpython/wxPython3.0-win32-3.0.2.0py27.exe
To write and test your code, an IDE (Integrated Development
Environment) would come in handy. A good free option is Eclipse:
http://www.eclipse.org/downloads/
Install the Eclipse IDE for Java EE Developers (LUNA 4.4.1)
Eclipse is an IDE that supports many programming languages, and the
program became so big that the developers decided to release different
versions of Eclipse. In order to develop Python programs in Eclipse, an
additional plugin named PyDev (described next) is needed.
Open Eclipse, and install PyDev. To install plugins in Eclipse:
o Go to the Help menu and choose Install New Software.
o Click the Add button and enter these details:
Name: PyDev (This doesnt really matter)
Location: http://pydev.org/updates
o Uncheck the 'Contact all update sites during install to find required
software, as
o Tick everything in the window and continue according to the
instructions. Agree when asked to trust the certificates.
o Restart Eclipse
A big advantage of Eclipse is the handling of the PYTHONPATH
environment. If any errors occur during the install process of the
packages mentioned above, start eclipse and navigate to: Window
Preference Pydev Interpreter Python menu. Here you have the
possibility to change the path to the python interpreter and the installed
packages. Usually the Eclipse IDE handle that for your needs. The result
Systems constants
This may include Arduino pin assignments (e.g. pinAnalInParkerP = 5)
or any other number which needs to be used in the rest of the code. Its
always good practice while coding to give meaningful names to numbers,
so the code becomes readable and understandable.
System components
This section describes the components in the system. Each component is
represented by a Python class from the Instrumentino package. To check
what hardware components are supported, browse the Instrumentino
code and look in the path instrumentino/controllers/. There are some
components already defined there, but if yours isnt, you need to create
it; this will not be covered in this manual.
As an example, here is a definition line for a Parker pressure controller:
pressureController = ParkerPressureController('Pressure',
(0,100), pinAnalInParkerP, pinPwmOutParkerP, highFreqPWM=True)
The first given argument is the display name on the screen. The second
is the allowed pressure range. The third and fourth are the input and
output Arduino pins, used to control it. The fifth modifies the PWM
frequency used for the analog output signal.
The order of these parameters can be checked in the Instrumentino code
at instrumentino/controllers/arduino.parker.py
System actions
This section lists the possible basic actions to be defined for the system.
Here is an example for an action fills a container, using a pressure
controller (see Instumentino release article):
class SysActionFillContainer(SysAction):
def __init__(self):
self.seconds = SysActionParamTime()
self.psi = SysActionParamFloat(pressureController.vars['P'])
SysAction.__init__(self, 'Fill Container', (self.seconds, self.psi))
def Command(self):
# Connect container to pressure controller
valves.vars['V1'].Set(valvePortPressure)
# Start pressure
pressureController.vars['P'].Set(self.psi.Get())
# Wait some time
cfg.Sleep(self.seconds.Get())
# Close container
valves.vars['V1'].Set('closed')
System definition
In this section, the former components and actions are wrapped up by a
single class called System, which inherits from instrumentino.Instrument.
Here is an example:
class System(Instrument):
def __init__(self):
comps = (pressureController, valves)
actions = (SysActionFillContainer(),
SysActionEmptyContainer())
name = 'Example System'
description = 'A container connected to a pressure controller'
version = '1.0'
Instrument.__init__(self, comps, actions, version, name, description)
Once this is defined, the Instrumentino framework will use this class to
create the appropriate control program.
Program run
This section shows how to make the python file runnable. The only thing
needed is to initiate a System class, as defined in the last section. This
starts the program.
if __name__ == '__main__':
# run the program
System()
When the system is online, the system components pane is updated with
values for the system variables and the signal log can be seen as well. Now its
possible to run methods or scripts
http://irwinkwan.com/2013/04/29/Python-executables-pyinstaller-and-a48-hour-game-design-compo/
For Windows:
In order to make a stand-alone executable, to be transferred to another
windows PC (which doesnt have Python installed on it), its necessary to
download PyInstaller:
http://www.pyinstaller.org/.
Download it to your PC, lets say to C:\programs\pyinstaller-2.0\
Then, while in the directory of your system description file, type in the terminal:
C:\programs\pyinstaller-2.0\pyinstaller.py mySystem.py
This creates a new directory Instrumentino\dist\mySystem, in which theres an
executable file to run the program. Because of a bug in PyInstaller, it is
necessary to copy the Instrumentino code to this directory.