A public repository for BMS algorithms for a NUCLEO BOARD.

Dependencies:   mbed

Hi Everyone!

Welcome to this repository from Howey's Research Group at the University of Oxford.

The code published here incorporates BMS algorithms for diagnosis functions such as SOC, SOH and Power estimation on a Kokam 53Ah Li-ion battery. This code was designed to work with a NUCLEO F401-RE board and to be tested with a dSPACE HIL Simulator. A short guide on how the set up works is available at https://bitbucket.org/ff95/bms .

The code is made up of three key parts. "Headers" and "Source" folders and the "main.cpp" file. As the code was generated by converting a Simulink model ( available on the BitBucket page), the headers and source code files generated by the conversion are in the corresponding "Headers" and "Source" folders. The "main.cpp" file sets up the ADC, the USB data transmission and starts the estimation (once a character "y" has been received by the computer it is connected to). It also transmits the data from the estimation via USB. Explanation on how to set up the communication with the board is available at BitBucket webpage, from where a MATLAB file can be downloaded which allows real time communication.

For any questions you can contact the author at federicomariaferrari@gmail.com .

The Simulink and Matlab files, together with a short guide, are all available at: https://bitbucket.org/ff95/bms.

Thanks for trying this out!

Federico

Committer:
fmferrari
Date:
Thu Dec 08 18:46:51 2016 +0000
Revision:
8:339dd9885af3
Parent:
7:e0be546a9112
Child:
9:17c258c67c33
First Successfully compiled of the EKF

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fmferrari 6:cb71171a7108 1 //
fmferrari 6:cb71171a7108 2 // Academic License - for use in teaching, academic research, and meeting
fmferrari 6:cb71171a7108 3 // course requirements at degree granting institutions only. Not for
fmferrari 6:cb71171a7108 4 // government, commercial, or other organizational use.
fmferrari 6:cb71171a7108 5 //
fmferrari 6:cb71171a7108 6 // File: EKF.h
fmferrari 6:cb71171a7108 7 //
fmferrari 6:cb71171a7108 8 // Code generated for Simulink model 'EKF'.
fmferrari 6:cb71171a7108 9 //
fmferrari 8:339dd9885af3 10 // Model version : 1.6
fmferrari 6:cb71171a7108 11 // Simulink Coder version : 8.11 (R2016b) 25-Aug-2016
fmferrari 8:339dd9885af3 12 // C/C++ source code generated on : Thu Dec 8 19:03:07 2016
fmferrari 6:cb71171a7108 13 //
fmferrari 6:cb71171a7108 14 // Target selection: ert.tlc
fmferrari 7:e0be546a9112 15 // Embedded hardware selection: STMicroelectronics->ST10/Super10
fmferrari 6:cb71171a7108 16 // Code generation objectives: Unspecified
fmferrari 6:cb71171a7108 17 // Validation result: Not run
fmferrari 6:cb71171a7108 18 //
fmferrari 6:cb71171a7108 19 #ifndef RTW_HEADER_EKF_h_
fmferrari 6:cb71171a7108 20 #define RTW_HEADER_EKF_h_
fmferrari 8:339dd9885af3 21 #include <cmath>
fmferrari 6:cb71171a7108 22 #include <string.h>
fmferrari 6:cb71171a7108 23 #include <stddef.h>
fmferrari 6:cb71171a7108 24 #ifndef EKF_COMMON_INCLUDES_
fmferrari 6:cb71171a7108 25 # define EKF_COMMON_INCLUDES_
fmferrari 6:cb71171a7108 26 #include "rtwtypes.h"
fmferrari 6:cb71171a7108 27 #endif // EKF_COMMON_INCLUDES_
fmferrari 6:cb71171a7108 28
fmferrari 6:cb71171a7108 29 #include "EKF_types.h"
fmferrari 8:339dd9885af3 30 #include "rtGetNaN.h"
fmferrari 8:339dd9885af3 31 #include "rt_nonfinite.h"
fmferrari 8:339dd9885af3 32 #include "rtGetInf.h"
fmferrari 6:cb71171a7108 33
fmferrari 6:cb71171a7108 34 // Macros for accessing real-time model data structure
fmferrari 6:cb71171a7108 35 #ifndef rtmGetErrorStatus
fmferrari 6:cb71171a7108 36 # define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
fmferrari 6:cb71171a7108 37 #endif
fmferrari 6:cb71171a7108 38
fmferrari 6:cb71171a7108 39 #ifndef rtmSetErrorStatus
fmferrari 6:cb71171a7108 40 # define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
fmferrari 6:cb71171a7108 41 #endif
fmferrari 6:cb71171a7108 42
fmferrari 8:339dd9885af3 43 // Block states (auto storage) for system '<Root>'
fmferrari 8:339dd9885af3 44 typedef struct {
fmferrari 8:339dd9885af3 45 real_T xhat[2]; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 46 real_T P0[4]; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 47 real_T I_prev; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 48 uint32_T method; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 49 uint32_T state[2]; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 50 uint32_T method_c; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 51 uint32_T state_p; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 52 uint32_T state_g[2]; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 53 uint32_T state_pv[625]; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 54 boolean_T method_not_empty; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 55 boolean_T state_not_empty; // '<Root>/MATLAB Function'
fmferrari 8:339dd9885af3 56 } DW_EKF_T;
fmferrari 8:339dd9885af3 57
fmferrari 6:cb71171a7108 58 // External inputs (root inport signals with auto storage)
fmferrari 6:cb71171a7108 59 typedef struct {
fmferrari 6:cb71171a7108 60 real_T Voltage; // '<Root>/Voltage'
fmferrari 6:cb71171a7108 61 real_T Current; // '<Root>/Current'
fmferrari 6:cb71171a7108 62 } ExtU_EKF_T;
fmferrari 6:cb71171a7108 63
fmferrari 6:cb71171a7108 64 // External outputs (root outports fed by signals with auto storage)
fmferrari 6:cb71171a7108 65 typedef struct {
fmferrari 6:cb71171a7108 66 real_T SOC; // '<Root>/SOC'
fmferrari 6:cb71171a7108 67 } ExtY_EKF_T;
fmferrari 6:cb71171a7108 68
fmferrari 6:cb71171a7108 69 // Real-time Model Data Structure
fmferrari 6:cb71171a7108 70 struct tag_RTM_EKF_T {
fmferrari 6:cb71171a7108 71 const char_T * volatile errorStatus;
fmferrari 6:cb71171a7108 72 };
fmferrari 6:cb71171a7108 73
fmferrari 8:339dd9885af3 74 // Block states (auto storage)
fmferrari 8:339dd9885af3 75 extern DW_EKF_T EKF_DW;
fmferrari 8:339dd9885af3 76
fmferrari 6:cb71171a7108 77 #ifdef __cplusplus
fmferrari 6:cb71171a7108 78
fmferrari 6:cb71171a7108 79 extern "C" {
fmferrari 6:cb71171a7108 80
fmferrari 6:cb71171a7108 81 #endif
fmferrari 6:cb71171a7108 82
fmferrari 7:e0be546a9112 83 // External inputs (root inport signals with auto storage)
fmferrari 7:e0be546a9112 84 extern ExtU_EKF_T EKF_U;
fmferrari 7:e0be546a9112 85
fmferrari 7:e0be546a9112 86 // External outputs (root outports fed by signals with auto storage)
fmferrari 7:e0be546a9112 87 extern ExtY_EKF_T EKF_Y;
fmferrari 7:e0be546a9112 88
fmferrari 6:cb71171a7108 89 #ifdef __cplusplus
fmferrari 6:cb71171a7108 90
fmferrari 6:cb71171a7108 91 }
fmferrari 6:cb71171a7108 92 #endif
fmferrari 6:cb71171a7108 93
fmferrari 7:e0be546a9112 94 #ifdef __cplusplus
fmferrari 6:cb71171a7108 95
fmferrari 7:e0be546a9112 96 extern "C" {
fmferrari 6:cb71171a7108 97
fmferrari 7:e0be546a9112 98 #endif
fmferrari 6:cb71171a7108 99
fmferrari 7:e0be546a9112 100 // Model entry point functions
fmferrari 7:e0be546a9112 101 extern void EKF_initialize(void);
fmferrari 7:e0be546a9112 102 extern void EKF_step(void);
fmferrari 7:e0be546a9112 103 extern void EKF_terminate(void);
fmferrari 6:cb71171a7108 104
fmferrari 7:e0be546a9112 105 #ifdef __cplusplus
fmferrari 6:cb71171a7108 106
fmferrari 7:e0be546a9112 107 }
fmferrari 7:e0be546a9112 108 #endif
fmferrari 6:cb71171a7108 109
fmferrari 7:e0be546a9112 110 // Real-time Model object
fmferrari 7:e0be546a9112 111 #ifdef __cplusplus
fmferrari 7:e0be546a9112 112
fmferrari 7:e0be546a9112 113 extern "C" {
fmferrari 6:cb71171a7108 114
fmferrari 7:e0be546a9112 115 #endif
fmferrari 7:e0be546a9112 116
fmferrari 7:e0be546a9112 117 extern RT_MODEL_EKF_T *const EKF_M;
fmferrari 7:e0be546a9112 118
fmferrari 7:e0be546a9112 119 #ifdef __cplusplus
fmferrari 7:e0be546a9112 120
fmferrari 7:e0be546a9112 121 }
fmferrari 7:e0be546a9112 122 #endif
fmferrari 6:cb71171a7108 123
fmferrari 6:cb71171a7108 124 //-
fmferrari 6:cb71171a7108 125 // The generated code includes comments that allow you to trace directly
fmferrari 6:cb71171a7108 126 // back to the appropriate location in the model. The basic format
fmferrari 6:cb71171a7108 127 // is <system>/block_name, where system is the system number (uniquely
fmferrari 6:cb71171a7108 128 // assigned by Simulink) and block_name is the name of the block.
fmferrari 6:cb71171a7108 129 //
fmferrari 6:cb71171a7108 130 // Use the MATLAB hilite_system command to trace the generated code back
fmferrari 6:cb71171a7108 131 // to the model. For example,
fmferrari 6:cb71171a7108 132 //
fmferrari 6:cb71171a7108 133 // hilite_system('<S3>') - opens system 3
fmferrari 6:cb71171a7108 134 // hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
fmferrari 6:cb71171a7108 135 //
fmferrari 6:cb71171a7108 136 // Here is the system hierarchy for this model
fmferrari 6:cb71171a7108 137 //
fmferrari 6:cb71171a7108 138 // '<Root>' : 'EKF'
fmferrari 7:e0be546a9112 139 // '<S1>' : 'EKF/MATLAB Function'
fmferrari 6:cb71171a7108 140
fmferrari 6:cb71171a7108 141 #endif // RTW_HEADER_EKF_h_
fmferrari 6:cb71171a7108 142
fmferrari 6:cb71171a7108 143 //
fmferrari 6:cb71171a7108 144 // File trailer for generated code.
fmferrari 6:cb71171a7108 145 //
fmferrari 6:cb71171a7108 146 // [EOF]
fmferrari 6:cb71171a7108 147 //