Projects and papers, in depth

The longer story behind the cards on the main page: what I asked, how I tried to answer, and what the numbers said.

Paper, 2024

Teaching a hybrid car to save fuel

L. Rolando, N. Campanelli, L. Tresca, L. Pulvirenti and F. Millo. "Development of a Soft-Actor Critic Reinforcement Learning Algorithm for the Energy Management of a Hybrid Electric Vehicle". SAE Technical Paper 2024-37-0011, Politecnico di Torino.

Read the paper (DOI)
:) Paywall in the way? If you're interested, just ask and I'll gladly send you the paper. Ask for a copy
See it on the main page
8.6%more fuel than the theoretical best on the WLTC, with the battery ending at the target charge
10reward configurations trained and compared (5 for each of 2 rewards)
3driving cycles: one to train on, two the agent had never seen
5things the agent observes: speed, power demand, gearbox speed, battery charge, trip progress

The problem

A plug-in hybrid has two ways to move: the engine and the electric motor. At every instant, a controller called the Energy Management System (EMS) decides how to split the work. That choice decides how much fuel the car burns.

Dynamic Programming (DP) finds the mathematically best split, but it needs to know the whole trip in advance and a lot of computing time, so a car cannot use it live. Simple rule-based controllers run in real time, but they are usually far from optimal. Reinforcement learning (RL) offers a third way: an agent learns by trial and error, then runs in real time. The question of this paper: how close to the DP optimum can it get?

The vehicle

The test vehicle is a state-of-the-art diesel plug-in hybrid sold in Europe, with a parallel P2 architecture: the engine and the electric motor both feed a 9-speed automatic gearbox that drives the rear axle.

Training an agent takes hundreds of simulated cycles, so the original digital twin was simplified to a fast backward-kinematic model in Python and validated against experimental data from the real car.

Vehicle and powertrain
Curb weight2060 kg
Engine1950 cm³ turbo diesel, 4 cylinders, 143 kW
Electric motorPermanent-magnet synchronous, 90 kW / 440 Nm
Transmission9-speed automatic with torque converter
BatteryLi-NMC, 13.5 kWh, 365 V
LayoutRear-wheel drive, parallel P2

How the agent learns

The agent is a Soft Actor-Critic (SAC). It has two parts: an actor that proposes what to do, and a critic that judges how good that was. Its actor is stochastic: for each situation it outputs a bell curve of possible actions, which keeps it exploring instead of getting stuck. After training, the randomness is switched off and the agent acts deterministically.

The learning loop

SAC agent actor + critic neural networks Digital twin of the hybrid car Python, Gymnasium Action: engine torque (as a share of the maximum) Reward + new state fuel burned, battery charge... The agent sees: vehicle speed · power demand · gearbox speed · battery charge · distance travelled

Trial and error, hundreds of times. Every driving cycle is one episode. The agent tries torque values, receives a reward and slowly learns which ones lead to lower fuel use. The "distance travelled" input needs no connected car: a phone's GPS is enough.

Two ways to reward the agent

In RL the reward is everything: a poorly designed one gives poor results no matter how long you train. The goal is minimum fuel while ending the cycle with the same battery charge it started with (charge sustaining). RL cannot enforce that as a hard constraint like DP does, so the reward has to do it.

Case 1: always nudge towards the target

r = k1 − k2·ṁf·Δt − k3·(SoC − SoCtrg)²Penalizes fuel flow and any distance of the battery charge (SoC) from the target.

Case 2: free inside a band

r = k1 − (k2·ṁf + k3·PSoC)·ΔtThe SoC penalty P_SoC is zero while the charge stays between two boundary lines, and grows only outside them.

Case 2 lets the agent use the battery freely as long as it stays in the band. In the last third of the cycle the band narrows, nudging the agent to end at the target charge. For each reward, the weight k₃ was swept over five values (200 to 400 with k₂ fixed at 200), giving the 10 trained agents.

What came out

All ten agents kept the battery close to the target. The best one, Case 2 with k₃ = 300 (called 2C in the paper), balanced a near-perfect final charge with low fuel use. It was then tested against DP on the training cycle (WLTC) and on two cycles it had never seen: the urban FTP75 and the highway HFET.

Fuel consumption, SAC vs. the optimum

Lower is better. DP is the theoretical best for a perfectly charge-sustaining trip.

Gap versus the optimum

Fuel difference from DP. The HFET "win" comes with a battery that ended 2% below target, so it is not a real gain.

Final battery charge (SoC) at the end of each cycle
ControllerWLTCFTP75HFET
DP (target 0.50)0.500.500.50
SAC agent0.500.520.48
  • Different strategy, similar result. The agent drains the battery more at the start of the cycle and relies more on the electric motor, then uses the engine to recharge later, while DP keeps the charge steadier.
  • Where it loses. The agent's engine operating points are more scattered on the efficiency map, including inefficient low-load points, while DP stays closer to the optimal operating line.
  • The urban cycle is harder. On FTP75 the fuel use was 17.5% above DP and the charge ended 2% high. The extra charge explains part of it, not all.
Honest reading. The agent never saw FTP75 or HFET during training and stayed within about 17.5% of the optimum on both, without perfect charge sustainability. That is encouraging for a first, untuned version, and it is exactly where the next steps start.

Training setup

Main hyperparameters (both networks)
Discount factor0.99
Hidden layers2 × 256 neurons
Learning rate0.0003
Mini-batch size256
Soft-update coefficient0.005

The hyperparameters were kept fixed on purpose, so that any difference in results comes from the reward and not from tuning. A model was saved every 20 episodes.

Tools: a Python environment built to the Gymnasium standard, the SAC implementation from Stable-Baselines3, and an open-source MATLAB Dynamic Programming code from ETH Zurich for the benchmark.

What's next

Tune the hyperparameters of the networks, extend the agent to charge-depleting operation, train it over many driving cycles representing different patterns, and eventually run the approach on a high-fidelity forward-dynamics model of the car.

Paper, 2026

Is a battery storage worth it?

N. Campanelli and M. D'Arpino. "Optimal control and techno-economic analysis of long-duration battery energy storage system applications". Journal of Energy Storage, vol. 164, 2026. The Ohio State University.

Read the paper (DOI)
:) Paywall in the way? If you're interested, just ask and I'll gladly send you the paper. Ask for a copy
See it on the main page
32.4%lower yearly electricity bill with a battery plus wind power
20.4%lower bill with the battery alone, thanks to cheaper charging and fewer demand peaks
5scenarios, all built on real data from a building, a wind turbine and the market
$0.23per kWh to store energy in the standalone case, against a 2030 target of $0.05

The question

Long-duration batteries can hold energy for 10 hours or more. They promise to cut electricity bills, back up renewables and help the grid, but they are expensive. Is the investment worth it?

The usual tool to compare storage costs is the Levelized Cost of Storage (LCOS): the price at which each stored kWh must be sold to repay the project. Traditional calculators assume the battery cycles at a constant rate with a constant efficiency and a fixed energy price. Real batteries do not behave like that: they charge when power is cheap and discharge when it is expensive or when the building peaks.

The contribution of this work is to put the optimal control of the battery inside the cost analysis, so the LCOS is computed from how the battery would actually be operated.

The method, end to end

Real data building load wind, prices Plant model battery cells, limits, losses Optimal control Dynamic Programming Energy bill energy and demand charges LCOS cost of storing each kWh Everything is simulated hour by hour over the whole of 2022, in MATLAB.

The system that was simulated

A "behind the meter" plant: a commercial building, a wind turbine and a long-duration battery connected to the grid. The building and the wind are uncontrollable; the battery is the only thing the optimizer decides.

The battery is modelled cell by cell with an equivalent circuit built on experimental measurements, including its internal resistance and the efficiency of the converter, so charging and discharging are not "free".

Dynamic Programming looks at the whole year and finds the cheapest sequence of charge and discharge decisions. Demand charges are then computed on the resulting grid power peaks.

Case study inputs
Battery752 kWh sodium metal halide, 526 kWh usable (SoC 10 to 80%), up to 10 h discharge
Wind turbine250 kW, wind data for 2022, power bought through a PPA
BuildingResearch building at Ohio State, 882 MWh of grid energy per year
Electricity priceHourly real-time market price for 2022
Demand charge$7.01 per kW of monthly peak, 150 kW threshold
Project life20 years, with a cell replacement after 15

Five scenarios

1A. Arbitrage

The battery supports the building by buying cheap and avoiding expensive hours. Demand charges are not part of the optimization.

1B. Arbitrage + peak shaving

As 1A, but the optimizer also caps the power drawn from the grid to cut demand charges.

1C. Adding wind

As 1B, plus power from a wind turbine under a Power Purchase Agreement.

2. Battery alone

No building: the battery only trades energy with the grid, as a pure arbitrage business.

3. Battery at a wind farm

The battery delays the wind farm's sales to the hours when the price is higher.

What the optimal control does

The optimizer charges when electricity is cheap, discharges when it is expensive, and shaves the building's power peaks. It also plans across days. In the April 2022 example of the paper, it keeps storing energy from day 14 to day 17 so that on day 18 the battery can cover most of the building's demand, avoiding a costly day.

That is the point of long duration: the value is not only in the instant price, but in moving energy through time, and in the demand charge it saves on the way.

Results: the bill goes down

Yearly electricity bill (2022)

Savings: 6.3% in 1A, 20.4% in 1B and 32.4% in 1C. Wind alone accounts for 16.9 points of the last one. Note: in the paper's table the 1B parts add up to $70,203, while its stated total is $71,413; the totals shown here are the stated ones.

A surprise in 1A. Its demand charges ($25,219) are higher than with no battery ($22,131). To exploit very low prices, the optimizer charges at full power and creates a grid peak higher than the building's own. 1B fixes this by limiting the peak.

The catch: storing energy still costs more

With the operation known hour by hour, the LCOS can be computed properly: $0.23 to $0.26 per kWh for the building scenarios. Multiplying it by the energy the battery handles in a year gives what it costs to store that energy. Comparing that with what the battery earns or saves tells you whether the investment pays back.

Benefit versus cost, per year

Green is what the battery brings; red is what storing that energy costs. In every scenario the cost is higher. Scenario 1C comes closest ($29,091 against $35,861), and it assumes the wind turbine is already there for free.

Would another chemistry change the answer?

The same optimal control was applied to the cost data of other battery types for Scenario 2. Lithium-ion (LFP) is the cheapest to store with, at $0.1726 per kWh. But for that scenario to break even, the LCOS would need to fall to about $0.1173 per kWh, roughly half of today's value, and the DOE target for 2030 is lower still.

LCOS by battery chemistry (Scenario 2)

Dollars per stored kWh. No chemistry reaches the break-even line, so pure arbitrage still does not repay the investment.

Takeaways

  • Operationally, it works. A long-duration battery can cut a commercial building's bill by up to 20.4%, and by 32.4% together with wind.
  • Economically, not yet. At current cost assumptions the cost of storage exceeds savings and revenues in every scenario.
  • Method matters. Putting optimal control and real data inside the cost analysis changes the answer compared with a lumped calculation, and shows how scenarios differ.
Personal project, ongoing

How close can we get to energy independence?

A family-owned domestic solar installation, hourly production data and a modelling mindset. This page is still being written.

The installationComing soon: size of the plant, location, orientation and how the data is collected.
The dataComing soon: production versus expected output, consumption profile and market prices.
The findingsComing soon: what the numbers say about self-consumption and energy independence.
What's nextComing soon: adding a battery, a heat pump and, maybe, going off grid.

A first look at the data

A typical day. Energy produced hour by hour: mean, median and percentiles.
Production / Price. Each dot is one hour. When the panels produce more, the electricity price tends to be lower: that's simple supply and demand.

Questions about any of this?

I enjoy talking about the details, and about what I would do differently today.