Skip to main content
emobility.academy
B.Tech / BEAUTOSAR ClassicIntermediate About 6 weeksADAS & AUTOSAR

AUTOSAR Composition for an EV Battery Management Function

Build an AUTOSAR Classic composition for an EV battery management function, cell monitoring, SOC estimation, protection and contactor control components, in an AUTOSAR architecture model, simulate it with a battery plant and export the composition ARXML.

Tools: Simulink · AUTOSAR Blockset

AUTOSAR Composition for an EV Battery Management Function: Students programming embedded EV hardware with a DIYguru mentor
Representative photo from DIYguru's EV lab, not of this specific project.

The problem

A BMS function is not one block of code but several components developed and tested separately, then connected in a composition. AUTOSAR describes this structure explicitly, with component prototypes, connectors and delegation ports. Learning to design and integrate such a composition is a core skill for EV software engineers.

Objectives

  • Design a BMS function as several AUTOSAR software components.
  • Build an AUTOSAR architecture model with a composition and connectors.
  • Implement each component in Simulink.
  • Simulate the composition with a simple battery plant.
  • Export composition and component ARXML and generate code per component.

What you need

Tools and toolboxes

  • AUTOSAR Blockset — AUTOSAR architecture model, compositions, components and ARXML export.
  • System Composer — The architecture editing environment used by AUTOSAR architecture models.
  • Simulink and Stateflow — Behaviour models for each component and the battery plant.
  • Embedded Coder — Code generation for each component.
  • Simscape Battery — Optional: a more detailed battery pack plant model.

Software

  • MATLAB, Simulink, Stateflow, AUTOSAR Blockset, System Composer and Embedded Coder
  • Simscape Battery (optional)

Extra parts and data

None beyond the software above.

Key concepts

Composition
An AUTOSAR component that contains other component prototypes connected together. It has its own ports, which delegate to ports of inner components.
Assembly and delegation connectors
Assembly connectors link ports of components inside a composition; delegation connectors link an inner component's port to the composition's outer port.
Contactor sequencing
Closing the pre-charge contactor first, waiting for the DC link to charge, then closing the main contactor, to avoid an inrush current that would damage contacts.
Architecture model
A model that describes components and their connections before or alongside their implementation, from which composition ARXML can be exported.

Step-by-step guide

  1. 1

    Define the BMS function and split

    Specify a simplified BMS for a 96-cell pack: read cell voltages and temperatures, estimate SOC, check limits for over-voltage, under-voltage, over-temperature and over-current, decide on contactor states and report status to the vehicle. Split it into components: CellMonitor, SocEstimator, Protection and ContactorCtrl, with a composition BmsApp around them. Write a short responsibility statement and the inputs and outputs for each component.

    Checkpoint: A component list with responsibilities, inputs and outputs, and a draft composition diagram.

  2. 2

    Define interfaces and data types

    Define sender-receiver interfaces such as IfCellData with arrays of cell voltages and temperatures, IfPackState with pack voltage, current and SOC, IfFaultStatus with fault flags, and IfContactorCmd. Choose data types and units, including fixed-size arrays and a structure where helpful. Add a mode or request interface from the vehicle with a drive or charge request. Keep the interface list in a table that will drive the model.

    Checkpoint: An interface table with data elements, types, units and ranges.

  3. 3

    Create the architecture model

    Create an AUTOSAR architecture model, for example with autosar.arch.createModel or from the Simulink start page. Add the BmsApp composition and inside it the four components. Add ports to each component, typed by the interfaces, and draw assembly connectors between them. Add outer ports on the composition for sensor inputs, vehicle requests, contactor outputs and status, with delegation connectors to the inner ports.

    Checkpoint: The architecture model shows the composition with typed ports and every connection drawn.

  4. 4

    Implement the components

    Link each component to a Simulink implementation model. CellMonitor computes minimum, maximum and average cell voltage and temperature. SocEstimator uses coulomb counting with an OCV-based reset at rest. Protection compares values against limits with debounce timers and latches faults. ContactorCtrl is a Stateflow chart with open, pre-charge, closed and fault-open states and a pre-charge timeout. Test each model alone with a small harness.

    Checkpoint: Each component passes its unit tests in isolation.

  5. 5

    Build the battery plant

    Model a simple plant: a pack of cells with an OCV-SOC table and a series resistance, a temperature model with a single thermal mass, a current profile from a drive cycle and a DC-link capacitor that charges through a pre-charge resistor when the contactors close. Optionally use Simscape Battery for a more detailed pack. Add fault injection inputs: a high cell voltage, a sensor dropout and a temperature rise.

    Checkpoint: The plant runs a drive cycle with plausible pack voltage, SOC and temperature and supports fault injection.

  6. 6

    Simulate the composition

    Connect the composition to the plant in a top-level simulation and run scenarios: start-up with pre-charge and contactor close, a drive cycle, a charge session, an over-temperature fault that opens contactors, and a pre-charge failure. Log signals at the composition boundary and between components. Check the order of events, such as pre-charge first and main contactor closed only after the DC link reaches the threshold.

    Checkpoint: Each scenario produces the expected sequence of states and signals, checked against the specification.

  7. 7

    Export ARXML and generate code

    Export the composition from the architecture model to ARXML and inspect the COMPOSITION-SW-COMPONENT-TYPE with its SW-COMPONENT-PROTOTYPE elements and ASSEMBLY-SW-CONNECTOR and DELEGATION-SW-CONNECTOR elements. Generate code for each component and review the Rte calls. Check that each component's ARXML ports match the composition's connectors. This is the hand-off package an integrator would use to build the ECU. Check the package with a script or by re-importing it, so no connector refers to a missing port.

    Checkpoint: Exported ARXML containing the composition, all prototypes and connectors, plus generated code per component.

  8. 8

    Integration tests

    Write integration tests in Simulink Test against the composition: requirement-based checks on contactor sequencing timing, fault reaction time from limit exceedance to contactors open, and SOC estimate error on the drive cycle against the plant's true SOC. Change one component, such as the debounce time in Protection, and rerun the tests to show how integration tests catch interface or timing effects that unit tests miss.

    Checkpoint: Integration test results with timing and accuracy figures and a demonstrated regression catch.

  9. 9

    Document the composition

    Write up the BMS function, component split and reasoning, interfaces, architecture diagram, implementation summaries, simulation results and ARXML structure. Discuss the remaining steps for a real ECU: mapping components to tasks, RTE generation, configuring COM for CAN signals and basic software such as diagnostics and NvM. Point out the safety aspects, noting that a real BMS needs an ISO 26262 safety concept beyond this exercise.

    Checkpoint: A composition document with diagrams, test results and the exported ARXML.

Testing & validation

  • Unit tests for each component in isolation.
  • Composition scenarios matching the specified event sequences.
  • Fault reaction time and SOC accuracy from integration tests.
  • Composition ARXML containing every prototype and connector.

Expected results

An AUTOSAR BMS composition with four tested components, a battery plant for closed-loop simulation and an exported ARXML package ready for ECU integration.

Take it further

  • Replace coulomb counting with an EKF-based SOC estimator component.
  • Add a cell balancing component with its own interface.
  • Map the composition onto a two-ECU system with CAN communication.
  • Add DEM diagnostic events for each protection fault.

Viva and review questions

Why split the BMS into several components?

Each part can be developed, tested and reused separately, and the interfaces between them make responsibilities and data flow explicit.

What is a delegation connector?

It connects a port of an inner component to a port on the composition's boundary, so the composition exposes that port to the outside.

Why is pre-charge needed before closing the main contactor?

The DC-link capacitors would otherwise draw a very large inrush current from the pack, which can weld contactors and stress components.

Learn it at DIYguru

These DIYguru courses and programmes teach what this project needs.

Related EV projects

All 100 ADAS & AUTOSAR projects