Walabot API
All you need to know to create a Walabot Application
|
The Walabot library now supports Python, with its own Python API module for both Python 2 and 3, and makes it incredibly easy to take your first steps in developing Walabot applications. Importing WalabotAPI To use the WalabotAPI module in your Python code, you must import the module. You have two options for this: you can install WalabotAPI as a Python package, or you can import the Python file WalabotAPI.py into your specific script, using its file location.
You must have both Python and pip installed.
In the Command Prompt, enter:
Once you have installed the package, simply import the package in your Python code using: import WalabotAPI
It is recommended to use the built-in imp.load_source() to load the module easily.
Before using any other Walabot calls, you must call WalabotAPI.Init(). The Python API is using the ‘low-level’ library for C++ (WalabotAPIWindows.dll on Windows and libWalabotAPI.so on Linux).
In order to direct the Python API to the library you need to use the WalabotAPI.Init() function and pass it the path to the library. Moving the library file is not recommended. In case you do move it, you can pass Init() the new path to the library, e.g.:
Every function in the C++ API has a corresponding function in the Python API module which is designed to match the Python language flow. It is advised to look at the Python examples to fully understand how to use them. A detailed documentation about all available functions is given below, and can also be found using Python’s help() function.
As an example, the original Walabot_GetStatus() function which is implemented as such in the C++ example code:
Should be written in Python as such:
Unlike the C++ functions, the functions in Python does not return WALABOT_RESULT. The Python module will raise WalabotError in case it encounters one. You can catch those errors and act accordingly. A table of the possibles WalabotError’s is given below.
message: A short generic description of the occurred error. code: The occurred error code, can simplify the debugging process. extended: A code used internally, for Walabot developers. Available Errors And Codes
The following example can be used in order to test that there is a connected Walabot: try:
except WalabotError as err:
The C++ enums are available as simply ‘constants’ variables and are corresponding to them. For example: PROF_SENSOR is accessible in Python simply as WalabotAPI.PROF_SENSOR. Available ‘Constants’