This page has deprecated and moved to the new documentation framework of the main Bitcraze website. Please go to https://www.bitcraze.io/documentation/system/
Using Matlab with the Crazyflie API is easy – you just need to install the python ‘matlab engine’ and then can access all matlab commands directly from python.
Step 3 sometimes fails if you do not have write permission to the default build directory. If this happens:
3a. Create a new directory to store the build directory where you have write permission.
3b. Then set up the python engine with:
python setup.py build --build-base builddir install --user
Here builddir is the path of the directory created in step 3b. Note the double dashes (no space) before ‘build-base’ and ‘user’.
System reqirements: http://www.mathworks.com/help/matlab/matlab_external/system-requirements-for-matlab-engine-for-python.html
Installation: http://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
Installation in non-default locations http://www.mathworks.com/help/matlab/matlab_external/install-matlab-engine-api-for-python-in-nondefault-locations.html
Once you have installed the matlab engine, you can use any matlab commands (or your own matlab scripts) from within the Crazyflie API. To do this:
import matlab.engine
self.eng = matlab.engine.start_matlab()
self.eng.addpath("directory name",nargout=0)
self.matlabout = StringIO.StringIO() self.matlaberr = StringIO.StringIO()
output = self.eng.function_name([argument list],[stdout=self.matlabout],[stderr=self.matlaberr],[nargout=n])
Here ‘output’ is the output from the matlab function (if multiple arguments are returned by the function then output is an array - see the matlab python engine documentation for more information), [argument list] is the input arguments to the matlab function, self.matlabout and self.matlaberr are StringIO objects to capture Matlab errors and console output (optional) and n is the number of output arguments from the MATLAB script (the default is 1).
Matlab engine API documentation from Mathworks: http://www.mathworks.com/help/matlab/matlab-engine-for-python.html
Call MATLAB functions from python http://www.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-python.html
Not all data structures in matlab and python have direct equivalents. You can pass most primitive data types between them, as well as arrays. You can also usually pass matlab data types from one matlab function to another (eg you can save an output variable from a matlab function such as a file handle or plot handle in a python variable, and then pass it to another matlab function).
For speed it is best to minimize communications between python and matlab - i.e. try to do all matlab computations through a single script, instead of calling many matlab functions from inside python.
Pass data to matlab from python http://www.mathworks.com/help/matlab/matlab_external/pass-data-to-matlab-from-python.html