samsta / BatteryController

GNU General Public License v3.0
0 stars 0 forks source link

BatteryController

BatteryController is an interpreter package to integrate EV batteries & inverters. Specifically (at a high level):

• Translate communications

• Control power connections

• Report status to other systems

It is written in C++

Operation

On initial commissioning the battery’s voltages are manually matched and then connected to the 400V DC bus.

Central Controller

The Central Controller receives battery information from the Module Controllers. It aggregates & processes this information then passes it to the inverter. If the aggregated status is OK and the inverter requests it, then it connects the inverter to the 400V DC bus via a pre-charge process. If a battery is not OK the Central Controller commands that battery to be disconnected by communicating with the appropriate Module Controller. The system can continue running with batteries offline If necessary the Central Controller can command a power cycle to an individual Battery’s computer.

Module Controller

The Module Controller receives battery information from up to three batteries. It passes this information on to the Central Controller. If commanded by the Central Controller it can disconnect a battery from the 400V DC bus &/or power cycle an individual battery’s computer.

Building the Code

This is a CMake project. CMake is great when it comes to cross-compiling and compiling code on different platforms. Currently, we can build on the Raspberry Pi (on the command line) or Linux and macOS (on the command line or using an IDE like Eclipse or Xcode). In theory, we could build under Windows too (e.g. using Visual Studio) but I have not bothered providing the support in the source code which I'm happy to leave as an exercise to an interested party. The unit tests and all units should just work on Windows, but the top-level files stitching it all together will need to be different as Windows' way to deal with files and the CAN bus etc. are different - unless you choose to use Cygwin.

Eclipse on Ubuntu

Currently, we can only build for the native platform under Eclipes (i.e. no cross-compiling to create code for the Pi). This is good for unit tests, but you can also run the other applications given you provide either real or virtual CAN interfaces.

First, let's install the prerequisites. In a terminal, run:

sudo apt -y install build-essential cmake git libgtk-3-0 libsocketcan-dev libgpiod-dev can-utils

Download the installer from https://www.eclipse.org/downloads/download.php?file=/oomph/epp/2020-12/R/eclipse-inst-jre-linux64.tar.gz , then unpack and run eclipse-inst. Note that your browser might download it to a different directory, but we'll assume the default here:

cd ~/Downloads
tar xvf eclipse-inst-jre-linux64.tar.gz  
cd eclipse-installer/  
./eclipse-inst  

Then check the 'C/C++ Development Tools' are installed:

If you can't find the C/C++ Development Tools in there let me know and I'll dig up some instructions.

Then download the CMake Editor plugin:

Then, go to a a directory of your choice (I'll assume ~/Projects, which is short for /home/<username>/Projects):

cd ~/Projects
git clone --recurse-submodules https://github.com/samsta/BatteryController.git
mkdir BatteryController-build
cd BatteryController-build
cmake ../BatteryController -G 'Eclipse CDT4 - Unix Makefiles'

Do not despair - this only needs to be done once to create the .project file Eclipse wants.

Now import the project into Eclipse:

You have now imported the project into Eclipse. You should not have to do that again, it should still be there the next time you open Eclipse.

Some useful views to Open:

Note: If you add source files to Eclipse, you have to add them to the CMakeLists.txt in the same directory too. This is so we can build stuff outside of Eclipse, e.g. on the Pi where we just use CMake and make and no IDE.

Rough structure and description of key softare objects:

Monitor

Contactor

Inverter (SunnyBoyStorage)

Auxiliary blocks:

FrameAggregator

GroupPoller