This plugin has been updated for MADS v2
Note that on linux this must be compiled with Clang, not with GCC. Be sure to sudo apt install clang and then set clang as default with sudo update-alternatives --config c++ and select /usr/bin/clang++, then repeat with sudo update-alternatives --config cc and select /usr/bin/clang.
You need to have python3 and python3-dev installed. Then:
python3 -m venv .venv
source .venv/bin/activate
pip install numpy
# also install other necessary Python libs
cmake -Bbuild"
cmake --build build -j6
sudo cmake --install buildThe above is tested on MacOS and Ubuntu 22.04.
Run the following from project root:
python -m venv .venv
.venv\Scripts\activate.ps1
pip install numpyThen:
cmake -Bbuild
cmake --build build --config Release
sudo cmake --install buildOr, if you have Ninja:
cmake -Bbuild -G Ninja
cmake --build build -j6
cmake --install buildThen you can just type mads-python -h.
Note: for sudo to work on Windows, you need to enable it on Settings > System > For Developers and set Enable sudo to On.
Typically, to launch an agent named python_source, that gets its settings from a python_source section in mads.ini, and uses the Python module named source defined in the source.py file and that runs every 100 ms, the command is:
mads python -n python_source -m source -p100The Python modules are searched for in the following folders:
./python./scripts../python../scripts../../python../../scriptsINSTALL_PREFIX + /pythonINSTALL_PREFIX + /scripts
plus any path listed in the mads.ini file under the search_path key (an array or a single string).
The following fields are typically used:
[python_source]
period = 200
venv = "/path/to/.venv"
python_module = "my_source"
search_paths = ["/path/to/python/folder"]Python modules can be of type source, filter, or sink. The module type is defined by setting a top level variable like this, typically at the beginning of the script, just after the various imports:
agent_type = "sink"All the modules must implement a setup() function, which is expected to use the dictionary available in the module variable params (a dictionary) to do initial setup (opening ports or files, etc.)
Source modules must implement a get_output() function, that produces the JSON string that will be published.
Filter modules must implement a process() function, that is supposed to operate on the last received data dictionary (available as data, a module variable) and produce a JSON string that will be published.
Sink modules must implement a deal_with_data() function, that operates on the data dictionary, a module variable.
See examples in the python folder.