Is it possible to command the EPOS4 (or EPOS2) by Python?
maxon does not provide documentation, specific libraries, sample code, or support to command the EPOS controllers by Python. Anyway it is easily possible to use the "Epos Command library" by Python to command an EPOS4 (resp. EPOS2).
Based on user's feedback there are two solutions mainly in use to command an EPOS by Python.
- Solution 1: ctypes
A solution which is favored by most users is the "ctypes" library for Python.
The "ctypes" library is installed by most Python environment by default. "ctypes" offers "C" compatible data types conversions and enables calling up of DLL functions (like in use by the "EPOS Command Library").
The usage of "ctypes" is explained below, see section "Solution: ctypes library".
The attached sample code was shared by a EPOS4 and Python user.
- Solution 2: pythonnet
Another possible solution is the usage of "pythonnet" (which might be mainly intended for Windows based systems).
The usage of "pythonnet" is explained by the following article:
EPOS2 / EPOS4: Commanding by Python -> pythonnet
Solution: "ctypes" library
The only thing which is needed to command the EPOS4 (or EPOS2) by Python is the "ctypes" library and the "EPOS Command library".
The ctypes library is a foreign function library which provides C compatible data types and allows calling functions in DLLs (like maxon "EPOS Command library"). It is installed as one part of most Python programming environments by default.
Detailed documentation about the usage of the "ctypes" Library can be found on the Internet, e.g. ...
The attached two sample programs (for RaspberryPi 3) show nicely how to use ctypes. The keypoints are:
- Import ctypes:
- from ctypes import *
- from ctypes import *
- Copy the "EPOS Command library" into your Python environment and configure the path information properly, e.g.
- Load the library
- Define a variable NodeID and configure it according to your EPOS4 node ID setting, e.g.
- NodeID = 1
- NodeID = 1
- Define the data type of return pointers of "EPOS Command library" function calls properly matching the ctypes data types, e.g.
- Find "ctypes" documentation dealing with data types here:
- Use the ctypes "byref" for return pointers of "EPOS Command library" function calls, e.g.
- keyhandle=epos.VCS_OpenDevice('EPOS4', 'MAXON SERIAL V2', 'USB', 'USB0', byref(pErrorCode) )
- ret=epos.VCS_GetPositionIs(keyhandle, NodeID, byref(pPositionIs), byref(pErrorCode))
- ret=epos.VCS_MoveToPosition(keyhandle, NodeID, 20000, 0, 0, byref(pErrorCode))
- Find "ctypes" documentation dealing with "byref" here:
2.) "EPOS Command library"
The "EPOS Command library" is installed by the "EPOS Setup" package on your local drive automatically too. The library as well as its documentation "EPOS Command Library.pdf" is part of the following directories by default:
- C:\Program Files (x86)\maxon motor ag\EPOS IDX\EPOS4\04 Programming\Linux Library
- C:\Program Files (x86)\maxon motor ag\EPOS IDX\EPOS4\04 Programming\Windows DLL
- Please note that maxon cannot provide support or training for Python, ctypes, or any application specific adaptation of the program example.
- The sample program code can be shared, modified, and used for free without any restrictions.
- maxon disclaims any liability and warranty based on the usage of the sample code.
- We are pleased about your feedback if this information was helpful and you managed to command the EPOS4 by Python.