Skip to content

Commit 37cc01e

Browse files
committed
Merge branch 'main' into ev
2 parents a9f5479 + 150e65f commit 37cc01e

33 files changed

Lines changed: 628 additions & 186 deletions

.gitignore

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ devices.yaml
2424
lnbits.yaml
2525
influxdb_mapping.yaml
2626
custom
27-
node_modules/
28-
__pycache__/
29-
*.pyc
27+
28+
# Personal analysis and planning documents (untracked)
29+
EV_TECHNICAL_ANALYSIS.md
30+
EV_ROADMAP.md
31+
HEATING_TECHNICAL_ANALYSIS.md
32+
CHANGE_LOG_HEATING.md
33+
MOCK_DEPENDENCIES_LESSON.md
34+
BUGS_TO_SOLVE.md
35+
RAMPING_MATHEMATICAL_ANALYSIS.md
36+
RAMPING_VALIDATION_SUMMARY.md
37+
CHANGE_LOG_EV.md
38+
39+
# Local test files (untracked)
40+
test_ev_actual.py
41+
test_ev_complete.py
42+
test_ev_real_optimization.py
43+
test_final_ramping.py
44+
test_ramping_standalone.py
45+
test_heating_complete.py
46+
47+
# Generated test images and results (untracked)
48+
ev_optimization_results_*.png
49+
ramping_constraint_demonstration.png
50+
forced_ramping_activation.png
51+
realistic_ramping_scenarios.png
52+
ev_ramping_validation_results.png
53+
heating_optimization_analysis.png

.vscode/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
"module": "cold_pickup_mpc.app",
99
"cwd": "${workspaceFolder}/",
1010
"envFile": "${workspaceFolder}/local-dev.env"
11+
},
12+
{
13+
"name": "Building Intelligence Connector",
14+
"type": "debugpy",
15+
"request": "launch",
16+
"program": "${workspaceFolder}/src/building_intelligence_connector.py",
17+
"console": "integratedTerminal",
18+
"cwd": "${workspaceFolder}",
19+
"env": {
20+
"LOGLEVEL": "DEBUG"
21+
}
1122
}
1223
],
1324
}
28 KB
Binary file not shown.

docs/docusaurus/docs/Devices/electric_vehicle_v1g_mpc.md

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ sidebar_position: 4
44

55
# Electric Vehicle V1G MPC
66

7-
The electric vehicle (EV) is an important component of modern residential energy systems, contributing to power demand during charging, especially in highly electrified homes subject to Demand Response (DR) events. The Model Predictive Control (MPC) formulation for the EV optimizes charging to maintain a desired State of Charge (SoC) while respecting grid power constraints and user preferences, such as EV availability for charging. This section presents the EV MPC formulation in V1G mode (charging only), which uses a binary switch to control charging based on a branched profile indicating when the EV is connected. This approach enables efficient power allocation during service restoration, enhancing grid stability and integration with Home Energy Management Systems (HEMS).
7+
The electric vehicle (EV) is an important component of modern residential energy systems, contributing to power demand during charging, especially in highly electrified homes subject to Demand Response (DR) events. The Model Predictive Control (MPC) formulation for the EV optimizes charging to maintain a desired State of Charge (SoC) while respecting grid power constraints and user preferences, such as EV availability for charging. This section presents the EV MPC formulation in V1G mode (charging only), which uses a continuous control variable to modulate charging power based on a branched profile indicating when the EV is connected. This approach enables efficient and flexible power allocation during service restoration, enhancing grid stability and integration with Home Energy Management Systems (HEMS).
88

9-
The EV formulation uses a binary control variable to model the charging state (on/off), combined with a branched profile reflecting EV availability (e.g., when plugged in). This design balances user comfort by minimizing SoC deviations and ensures computational efficiency through a mixed-integer linear programming framework. The integration of charging efficiency and self-discharge improves model accuracy, while the branched profile allows the controller to adapt to user schedules, making it practical for residential applications.
9+
The EV formulation uses a continuous control variable (0-1) to model the charging power modulation, combined with a branched profile reflecting EV availability (e.g., when plugged in). This design balances user comfort by minimizing SoC deviations and ensures computational efficiency through a linear programming framework, while providing precise power control. The integration of charging efficiency and self-discharge improves model accuracy, while the branched profile allows the controller to adapt to user schedules, making it practical for residential applications.
1010

1111
### Optimization Formulation
1212

@@ -32,12 +32,12 @@ where:
3232
- $ S^{EV-C}_{k} $ is the charging power at time $ k $.
3333
- $ \Delta t $ is the duration of the time step (in hours).
3434

35-
Charging power is controlled by a binary switch and EV availability:
35+
Charging power is controlled by a continuous variable and EV availability:
3636
$$
3737
S^{EV-C}_{k} = U^{EV}_{k} B_{k} S^{EV,\max}, \quad \forall k
3838
$$
3939
where:
40-
- $ U^{EV}_{k} \in \{0, 1\} $ is the binary variable controlling the charging state at time $ k $.
40+
- $ U^{EV}_{k} \in [0, 1] $ is the continuous variable controlling the charging power level at time $ k $.
4141
- $ B_{k} \in \{0, 1\} $ is the branched profile indicating EV availability (1 if connected, 0 otherwise).
4242
- $ S^{EV,\max} $ is the maximum charging power.
4343

@@ -62,15 +62,52 @@ $$
6262
X^{EV}_{T} \geq X^{EV}_{\text{final}}
6363
$$
6464
where $ X^{EV}_{\text{final}} $ is the required state of charge at the end of the horizon.
65+
- **Power Ramping Constraints** (optional, for smoother transitions):
66+
$$
67+
|U^{EV}_{k+1} - U^{EV}_{k}| \leq R^{EV}_{\max}, \quad \forall k \in [1, T-1]
68+
$$
69+
where $ R^{EV}_{\max} $ is the maximum allowed rate of change in the control variable between consecutive time steps. This constraint can be enabled or disabled via the `enable_ramping` parameter and helps ensure smoother power transitions, reducing stress on the battery and improving grid stability. The ramping rate typically ranges from 0.1 to 0.5 per time step.
6570

6671
The power allocated to the EV, which contributes to the global power constraint, is:
6772
$$
6873
S^{EV}_{k} = S^{EV-C}_{k}, \quad \forall k
6974
$$
7075

76+
### Ramping Constraints for Smooth Power Transitions
77+
78+
The EV MPC implementation includes optional power ramping constraints that limit the rate of change in charging power between consecutive time steps. These constraints provide several benefits:
79+
80+
**Benefits of Ramping Constraints:**
81+
- **Battery Health**: Gradual power changes reduce stress on the battery system
82+
- **Grid Stability**: Smooth transitions minimize sudden load changes that could affect grid stability
83+
- **User Comfort**: Reduced electrical noise and smoother operation
84+
- **Hardware Protection**: Prevents rapid switching that could stress charging infrastructure
85+
86+
**Mathematical Implementation:**
87+
The ramping constraints are implemented by limiting the change in the continuous control variable $ U^{EV}_{k} $ between consecutive time steps:
88+
$$
89+
U^{EV}_{k+1} - U^{EV}_{k} \leq R^{EV}_{\max}
90+
$$
91+
$$
92+
U^{EV}_{k} - U^{EV}_{k+1} \leq R^{EV}_{\max}
93+
$$
94+
95+
**Configuration Parameters:**
96+
- `enable_ramping`: Boolean flag to enable/disable ramping constraints (default: `True`)
97+
- `max_power_ramp_rate`: Maximum allowed rate of change per time step (default: `0.2`)
98+
99+
**Validation Results:**
100+
Extensive testing has demonstrated that ramping constraints:
101+
- Shape the entire optimization trajectory, not just individual transitions
102+
- Work seamlessly with continuous control to provide precise power management
103+
- Allow fractional switch values that represent optimal power modulation
104+
- Maintain optimization effectiveness while ensuring smoother operation
105+
106+
The ramping constraints are particularly valuable in scenarios with frequent charging schedule changes or when grid stability is a priority. They can be easily disabled for applications where maximum charging flexibility is preferred over smooth transitions.
107+
71108
### Justification of the Formulation
72109

73-
The EV formulation uses a binary control variable to model the charging state (on/off), which reflects the practical reality that EVs typically charge at a fixed power when active. The branched profile $ B_{k} $ accounts for user schedules, ensuring that charging only occurs when the EV is connected—a critical aspect for residential applications where the vehicle may be unplugged during the day. The comfort penalty favors maintaining a desired residual energy state, ensuring the vehicle is ready for use while reducing demand peaks during DR events. The integration of charging efficiency and self-discharge improves model accuracy, while the mixed-integer linear formulation balances computational complexity with the need for precise control. This approach is well-suited for real-time optimization on embedded devices and facilitates integration with HEMS by respecting user priorities and grid constraints.
110+
The EV formulation uses a continuous control variable (0-1) to model the charging power modulation, which provides flexible power allocation while maintaining computational efficiency through a linear programming framework. This continuous approach allows for precise power control and better integration with grid-level optimization, especially during demand response events where partial charging may be more beneficial than simple on/off control. The branched profile $ B_{k} $ accounts for user schedules, ensuring that charging only occurs when the EV is connected—a critical aspect for residential applications where the vehicle may be unplugged during the day. The comfort penalty favors maintaining a desired residual energy state, ensuring the vehicle is ready for use while reducing demand peaks during DR events. The integration of charging efficiency and self-discharge improves model accuracy, while the linear formulation ensures computational efficiency and fast convergence. This approach is well-suited for real-time optimization on embedded devices and facilitates integration with HEMS by respecting user priorities and grid constraints while providing smooth power modulation capabilities.
74111

75112
### Variable Definitions
76113

@@ -82,8 +119,9 @@ Variables and parameters specific to the EV formulation are summarized in the fo
82119
| $ S^{EV}_{k} $ | Power allocated to the EV at time $ k $ | W |
83120
| $ X^{EV}_{k} $ | Residual energy (SoC) at time $ k $ | Wh |
84121
| $ X^{d}_{EV} $ | Desired state of charge (constant) | Wh |
85-
| $ U^{EV}_{k} $ | Binary variable for charging state at time $ k $ | - |
122+
| $ U^{EV}_{k} $ | Continuous variable for charging power level at time $ k $ (0-1) | - |
86123
| $ B_{k} $ | Branched profile (0 or 1) indicating EV availability at time $ k $ | - |
124+
| $ R^{EV}_{\max} $ | Maximum allowed ramping rate for control variable | - |
87125
| $ P_{EV} $ | Priority weight for the EV | - |
88126
| $ \Delta \alpha_{EV} $ | Normalization factor (typically energy capacity) | Wh |
89127
| $ \gamma $ | Degradation factor (self-discharge) | - |

0 commit comments

Comments
 (0)