|
SBB Micro
Source code for the self-balancing-bike microcontroller unit (Teensy 4.1-based). 🚀️
|
This repository contains the source code for the self-balancing-bike micro-controller unit (Teensy 4.1-based 🚀️). The introduction shows the files and folders contained in this repository and how they are organized, the prerequisites necessary, and the procedures to be used in order to build and upload the code, to generate the documentation, and to automatically generate the control-algorithm code from the Simulink model (using matlab tools).
Windows is officially supported, although compilation is also implemented for Linux. MacOS is NOT supported.
Files:
controlModel.slx: control model implementation in Simulinkgencode.m: MATLAB function for code generation from Simulink modelparams.sldd: Simulink parameters used in controlModel.slxbuild_linux.sh: build shell script for Linuxbuild_win.bat: build shmell script for WindowsDoxyfile: configuration file for documentation generation from source code using doxygenMakefile: makefile for building, uploading and documentation generation using makestartup.m: startup file for MATLAB (just to add necessary path)INSTALL_PREREQ.md: guide for the installation of the pre-requisitesREADME.md: readme fileCode folders:
./include: contains .h files included in source code./src: contains source .c or .cpp files, including main file main.cpp./lib: contains a folder for each used library, with file library.properties for defining the library properties (mandatory for arduino compiling) and .h and .cpp files (possibly contained in folder ./src/)./tools/teensy: contains the core code for the Teensy microcontrollerAdditional folders:
./tools/teensy-windows: build tools for Windows./tools/teensy-linux: build tools for Linux./docs/html: contains the documentation in html (generated automatically from source code using doxygen)./docs/extra: contains extra documentation (user-written), which is included using doxygen./matlab-tools: contains matlab tools usefull for code generation and other stuff./hardware: contains the kicad project files./.vscode: contains VS code property file(s)./.build and .cache: hidden folders created only during compilationNo other dependecies are necessary: all used libraries are already included in ./lib/.
Additional utilities (only recommended):
Makefile; alternativelly, shell or MATLAV scripts can be used./hardwareSee the installation guide for the pre-requisites for details.
Documentation for the source code and the user-defined libraries (but not for other third-party libraries) can be generated from the source using Doxygen with
or using make
Generated documentation includes only a html version in ./docs/html, with main file index.html. Documentation is also available on https://stefphd.github.io/SBBMicro/. A latex documentation may be also generated by setting
in Doxyfile. The latex version will be in ./docs/latex, and can be compiled using latex with
which generates the pdf file ./doc/latex/refman.pdf.
Code generation of the control algorithm is performed via MATLAB/Simulink with the Embedded Coder Toolbox. Other toolboxes may be required. Code generation can be launch with MATLAB using
The general usage of this function is
where modelname is the name of the Simulink model (without the *.slx extension included), while dest_dir is the destination directory: generated code is placed in ./dest_dir/modelname/src. If no modelname is given, the function uses the first *.slx file found in the current directory. If no destination directory is given, the functions uses ./lib. Code generation may be also performed using make, however this may take some time.
./matlab-tools/.Compilation is performed using the arduino-builder. Bash scripts provide simple usage depending on the operative system:
Linux:
or
Windows:
Alternatively, one can use ctrl+shift+B to build the code in Visual Studio Code with both Linux and Windows (this makes use of build_linux.sh or build_win.sh depending on the operative system). One may also use make the building and uploading.
One may also use make for the building, uploading and the documentation generation. This allows several operations using similar syntax, so as to perform single operations at a time:
make or make all to build and upload the code.make build to build the code onlymake upload to upload code onlymake clean to clean the build and cache directoriesmake remake to clean, build and upload the codemake rebuild to clean and rebuildmake doc to build the documentationmake cleandoc to clean the documentationmake help to print the Makefile helpmake build doc to build and generate the documentation.As an alternative to make and gencode, the code generation, buiding, uploading and documentation generation may be also performed at the same time from within the MATLAB command window. This employs a MATLAB function name make in ./matlab-tool/. The function must be used inside MATLAB with the following syntax:
make all or just make to generate code from the Simulink model, build and uploadmake gencode to generate the code only from the Simulink model. Note that this corresponds to call gencode with no input arguments, i.e. the first *.slx file found is usedmake build to build the codemake upload to upload the codemake clean to clean the build and cache directoriesmake remake to clean, build and upload the codemake rebuild to clean and rebuildmake doc to build the documentationmake cleandoc to clean the documentationmake help to print the help.gencode and the standard make commands. However, it does not require having make installed but only doxygen for the generation of the documentation.make build doc to build and generate the documentation.Undefined identifiers found by Visual Studio Code, however this is only a C/C++ IntelliSense issue (compilation works fine)
Doc: Documentaton for Simuling and code generation???
Make Arduino functions working in Simulink when compiling (maybe declare Arduino functions as external in Simulink, so as the linker links them)
To implement brake motor