marlinarnz / eVCU

ESP32-based electric vehicle control unit for flexible interplay of analogue and CAN-bus based devices
MIT License
7 stars 2 forks source link

electric Vehicle Control Unit

This library allows the control of diverse components - from simple analogue switches to complex CAN-bus driven MCUs - within a vehicle or any other entity that depends on various devices. In the case of electric vehicle conversions, this flexibility allows including quality components from scrapped OEM vehicles, which saves resources and money.

The library is based on the ESP32 microcontroller, which is easily available for small expenses. The code is fully compatible with the open source Arduino IDE and developed test-driven (unit tests found in test/). It follows a multi-threading Service-Oriented Architecture - event-driven and thread safe.

Installation

This is an Arduino-style library and thus, available in the Arduino library manager (coming soon). You need the ESP32 Arduino library, which implements all ESP32 functionalities (many tutorials available). Note, that you need the official stable release link, not the one posted in most tutorials. Official documentation: https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html

Overview

Save and efficient operation of a vehicle requires two class types:

At program start, Devices subscribe to value changes of Parameters, which they are interested in (by unique ID). This way, Devices don't know each other, and communicate solely via Parameters. They execute a routine when notified of value changes. Both, reaction to value changes and observation of own inputs happens in seperate threads.

In the background operates the VehicleController: It registers Parameters and subscriptions from Devices that observe their value changes. It distributes the information that a Parameter's value changed to the Devices that subscribed for it.

Semaphores, queues, and threads are based on FreeRTOS (the operating system of the ESP32). Hardware drivers like interrupts, timers, or serial communication use the ESP32 API.

Start an own project

When starting a project with this library, you must define your hardware-specific Devices and Parameters:

  1. Define Parameters with unique IDs that are relevant to more than one Device. Best practice is to declare them extern in a header file (e.g. GlobalParamteres.h) and instantiate them in the corresponding source file (GlobalParamteres.cpp). You can then include them where needed.
  2. Write classes for your Devices. See below for a programming guide and classes that are already implemented.
  3. Instantiate your Devices in your main file (*.ino in Arduino-style).
  4. Start operation of all Devices by calling their begin() function in the setup() of your program.

Own Devices

There are some pre-defined classes that can used in your project as-is:

Please refer to the code documentation for further details.

All custom Devices must inherit the library functionality from a Device class. There are several base classes ready for use:

Further information is to be found in the corresponding code documentation.

There are some functions, which must be defined in every custom Device:

Testing

The core components of this library are unit tested. Currently, there is no test framework under use. Unit testing happens with the AUnit library for the Arduino IDE.