diff --git a/.github/workflows/build_on_commit.yml b/.github/workflows/build_on_commit.yml new file mode 100644 index 0000000..8434f9f --- /dev/null +++ b/.github/workflows/build_on_commit.yml @@ -0,0 +1,41 @@ +name: Build + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + # Get required packages + - uses: actions/checkout@v2 + - uses: fiam/arm-none-eabi-gcc@v1 + with: + release: '9-2019-q4' + + # Build with make + - name: make + env: + VARIANT: VARIANT_ADC + run: make + + # Build with Platformio + - name: PlatformIO Install + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + - name: PlatformIO Run + run: pio run + + - name: 'Upload Build Artifact' + uses: actions/upload-artifact@v3 + with: + path: ${{github.workspace}}/.pio/build/** + name: ${{github.event.repository.name}}_build_${{github.run_number}} + retention-days: 5 + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b0ebc5d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,55 +0,0 @@ -notifications: - email: true - -os: linux - -jobs: - fast_finish: true - include: - - - name: make (gcc-arm-none-eabi-7) - script: make - env: VARIANT=VARIANT_ADC - language: c - addons: - apt: - packages: - - libc6-i386 - install: - - pushd . - - cd ~ - - mkdir arm-gcc-toolchain - - wget -O $HOME/arm-gcc-toolchain/gcc.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2?revision=bc2c96c0-14b5-4bb4-9f18-bceb4050fee7?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,7-2018-q2-update - - cd arm-gcc-toolchain - - tar -jxf gcc.tar.bz2 --strip=1 - - popd - - export PATH=$HOME/arm-gcc-toolchain/bin:$PATH - before_script: arm-none-eabi-gcc --version - - - name: make (gcc-arm-none-eabi-5) - script: make - env: VARIANT=VARIANT_ADC - language: c - addons: - apt: - packages: - - libc6-i386 - install: - - pushd . - - cd ~ - - mkdir arm-gcc-toolchain - - wget -O $HOME/arm-gcc-toolchain/gcc.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/5_4-2016q3/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2?revision=111dee36-f88b-4672-8ac6-48cf41b4d375?product=GNU%20Arm%20Embedded%20Toolchain,32-bit,,Linux,5-2016-q3-update - - cd arm-gcc-toolchain - - tar -jxf gcc.tar.bz2 --strip=1 - - popd - - export PATH=$HOME/arm-gcc-toolchain/bin:$PATH - before_script: arm-none-eabi-gcc --version - - - name: platformio - script: platformio run - language: python - install: - - pip install -U platformio - - platformio update - cache: - - directories: "~/.platformio" diff --git a/Inc/BLDC_controller.h b/Inc/BLDC_controller.h index 73f7876..9d663c2 100644 --- a/Inc/BLDC_controller.h +++ b/Inc/BLDC_controller.h @@ -3,9 +3,9 @@ * * Code generated for Simulink model 'BLDC_controller'. * - * Model version : 1.1296 + * Model version : 1.1297 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - * C/C++ source code generated on : Tue Oct 20 17:29:57 2020 + * C/C++ source code generated on : Sun Mar 6 11:02:11 2022 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex diff --git a/Inc/rtwtypes.h b/Inc/rtwtypes.h index e6b2250..3f68038 100644 --- a/Inc/rtwtypes.h +++ b/Inc/rtwtypes.h @@ -3,9 +3,9 @@ * * Code generated for Simulink model 'BLDC_controller'. * - * Model version : 1.1296 + * Model version : 1.1297 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - * C/C++ source code generated on : Tue Oct 20 17:29:57 2020 + * C/C++ source code generated on : Sun Mar 6 11:02:11 2022 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex diff --git a/README.md b/README.md index 79c77e0..d651857 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # hoverboard-firmware-hack-FOC -[![Build Status](https://app.travis-ci.com/EFeru/hoverboard-firmware-hack-FOC.svg?branch=master)](https://app.travis-ci.com/EFeru/hoverboard-firmware-hack-FOC) +[![Build status](https://github.com/EFeru/hoverboard-firmware-hack-FOC/actions/workflows/build_on_commit.yml/badge.svg)](https://github.com/EFeru/hoverboard-firmware-hack-FOC/actions/workflows/build_on_commit.yml) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=CU2SWN2XV9SCY¤cy_code=EUR&source=url) @@ -8,14 +8,13 @@ This repository implements Field Oriented Control (FOC) for stock hoverboards. C - smooth torque output and improved motor efficiency. Thus, lower energy consumption - field weakening to increase maximum speed range - Table of Contents ======================= +* **Wiki:** please check the wiki pages for [Getting Started](https://github.com/EFeru/hoverboard-firmware-hack-FOC/wiki#getting-started) and for [Troubleshooting](https://github.com/EFeru/hoverboard-firmware-hack-FOC/wiki#troubleshooting) * [Hardware](#hardware) * [FOC Firmware](#foc-firmware) * [Example Variants](#example-variants) -* [Wiki](#wiki) * [Projects and Links](#projects-and-links) * [Contributions](#contributions) @@ -97,6 +96,12 @@ In all FOC control modes, the controller features maximum motor speed and maximu - The controller parameters are given in [this table](https://github.com/EFeru/bldc-motor-control-FOC/blob/master/02_Figures/paramTable.png) +### FOC Webview + +To explore the controller without a Matlab/Simulink installation click on the link below: + +[https://eferu.github.io/bldc-motor-control-FOC/](https://eferu.github.io/bldc-motor-control-FOC/) + --- ## Example Variants @@ -114,11 +119,6 @@ In all FOC control modes, the controller features maximum motor speed and maximu Of course the firmware can be further customized for other needs or projects. ---- -## Wiki -Please check the wiki for [Getting Started](https://github.com/EFeru/hoverboard-firmware-hack-FOC/wiki#getting-started) and for [Troubleshooting](https://github.com/EFeru/hoverboard-firmware-hack-FOC/wiki#troubleshooting) - - --- ## Projects and Links diff --git a/Src/BLDC_controller.c b/Src/BLDC_controller.c index 439c623..ae63bd4 100644 --- a/Src/BLDC_controller.c +++ b/Src/BLDC_controller.c @@ -3,9 +3,9 @@ * * Code generated for Simulink model 'BLDC_controller'. * - * Model version : 1.1296 + * Model version : 1.1297 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - * C/C++ source code generated on : Tue Oct 20 17:29:57 2020 + * C/C++ source code generated on : Sun Mar 6 11:02:11 2022 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex @@ -1019,6 +1019,8 @@ void BLDC_controller_step(RT_MODEL *const rtM) int32_T rtb_Sum1_jt; int16_T rtb_Merge_m; int16_T rtb_Merge1; + uint16_T rtb_Divide14_e; + uint16_T rtb_Divide1_f; int16_T rtb_TmpSignalConversionAtLow_Pa[2]; int32_T rtb_Switch1; int32_T rtb_Sum1; @@ -2116,20 +2118,15 @@ void BLDC_controller_step(RT_MODEL *const rtM) /* End of Switch: '/Switch2' */ - /* Switch: '/Switch2' incorporates: - * Constant: '/z_ctrlTypSel' - * Constant: '/CTRL_COMM2' - * Constant: '/a_phaAdvMax' - * Constant: '/id_fieldWeakMax' - * RelationalOperator: '/Relational Operator1' + /* Product: '/Divide14' incorporates: + * Constant: '/r_fieldWeakHi' + * Constant: '/r_fieldWeakLo' + * Sum: '/Sum1' + * Sum: '/Sum3' */ - if (rtP->z_ctrlTypSel == 2) { - rtb_Saturation1 = rtP->id_fieldWeakMax; - } else { - rtb_Saturation1 = rtP->a_phaAdvMax; - } - - /* End of Switch: '/Switch2' */ + rtb_Divide14_e = (uint16_T)(((int16_T)(DataTypeConversion2 - + rtP->r_fieldWeakLo) << 15) / (int16_T)(rtP->r_fieldWeakHi - + rtP->r_fieldWeakLo)); /* Switch: '/Switch2' incorporates: * Constant: '/n_fieldWeakAuthHi' @@ -2151,25 +2148,53 @@ void BLDC_controller_step(RT_MODEL *const rtM) /* End of Switch: '/Switch2' */ - /* Product: '/Divide3' incorporates: + /* Product: '/Divide1' incorporates: * Constant: '/n_fieldWeakAuthHi' * Constant: '/n_fieldWeakAuthLo' - * Constant: '/r_fieldWeakHi' - * Constant: '/r_fieldWeakLo' - * Product: '/Divide1' - * Product: '/Divide14' - * Product: '/Divide2' - * Sum: '/Sum1' * Sum: '/Sum2' - * Sum: '/Sum3' * Sum: '/Sum4' */ - rtDW->Divide3 = (int16_T)(((uint16_T)(((uint32_T)(uint16_T)(((int16_T) - (DataTypeConversion2 - rtP->r_fieldWeakLo) << 15) / (int16_T) - (rtP->r_fieldWeakHi - rtP->r_fieldWeakLo)) * (uint16_T)(((int16_T) - (rtb_Saturation - rtP->n_fieldWeakAuthLo) << 15) / (int16_T) - (rtP->n_fieldWeakAuthHi - rtP->n_fieldWeakAuthLo))) >> 15) * - rtb_Saturation1) >> 15); + rtb_Divide1_f = (uint16_T)(((int16_T)(rtb_Saturation - + rtP->n_fieldWeakAuthLo) << 15) / (int16_T)(rtP->n_fieldWeakAuthHi - + rtP->n_fieldWeakAuthLo)); + + /* Switch: '/Switch1' incorporates: + * MinMax: '/MinMax1' + * RelationalOperator: '/Relational Operator6' + */ + if (rtb_Divide14_e < rtb_Divide1_f) { + /* MinMax: '/MinMax' */ + if (!(rtb_Divide14_e > rtb_Divide1_f)) { + rtb_Divide14_e = rtb_Divide1_f; + } + + /* End of MinMax: '/MinMax' */ + } else { + if (rtb_Divide1_f < rtb_Divide14_e) { + /* MinMax: '/MinMax1' */ + rtb_Divide14_e = rtb_Divide1_f; + } + } + + /* End of Switch: '/Switch1' */ + + /* Switch: '/Switch2' incorporates: + * Constant: '/z_ctrlTypSel' + * Constant: '/CTRL_COMM2' + * Constant: '/a_phaAdvMax' + * Constant: '/id_fieldWeakMax' + * RelationalOperator: '/Relational Operator1' + */ + if (rtP->z_ctrlTypSel == 2) { + rtb_Saturation1 = rtP->id_fieldWeakMax; + } else { + rtb_Saturation1 = rtP->a_phaAdvMax; + } + + /* End of Switch: '/Switch2' */ + + /* Product: '/Divide3' */ + rtDW->Divide3 = (int16_T)((rtb_Saturation1 * rtb_Divide14_e) >> 15); /* End of Outputs for SubSystem: '/Field_Weakening_Enabled' */ } diff --git a/Src/BLDC_controller_data.c b/Src/BLDC_controller_data.c index 16686aa..626c537 100644 --- a/Src/BLDC_controller_data.c +++ b/Src/BLDC_controller_data.c @@ -3,9 +3,9 @@ * * Code generated for Simulink model 'BLDC_controller'. * - * Model version : 1.1296 + * Model version : 1.1297 * Simulink Coder version : 8.13 (R2017b) 24-Jul-2017 - * C/C++ source code generated on : Tue Oct 20 17:29:57 2020 + * C/C++ source code generated on : Sun Mar 6 11:02:11 2022 * * Target selection: ert.tlc * Embedded hardware selection: ARM Compatible->ARM Cortex diff --git a/docs/pictures/wiki_unlock/download_build.png b/docs/pictures/wiki_unlock/download_build.png new file mode 100644 index 0000000..b673643 Binary files /dev/null and b/docs/pictures/wiki_unlock/download_build.png differ