Skip to content

Add EnergyStartStopState listener to Controller - #32

Open
zacharyclark-Wright wants to merge 2 commits into
OpenDDS:mainfrom
Wright-Electric:feature/controller-energy-state
Open

zacharyclark-Wright wants to merge 2 commits into
OpenDDS:mainfrom
Wright-Electric:feature/controller-energy-state

Conversation

@zacharyclark-Wright

@zacharyclark-Wright zacharyclark-Wright commented Oct 26, 2026 •

Copy link
Copy Markdown

Fixes #28

Summary

Resolves #28 by adding a subscriber for tms::EnergyStartStopState to the Microgrid Controller (controller). This allows MCs to receive and track physical device energy states dynamically and synchronize device readiness during controller election, recovery, or failover.

Background & Root Cause

Per Issue #28:

"When an available MC becomes unavailable and then becomes available again later, the current status of the power devices is not synchronized with this MC."

Per MIL-STD-3071 (TMS), power devices publish their real-time operational status over the EnergyStartStopState topic using the PublishLast QoS profile (TRANSIENT_LOCAL durability, RELIABLE reliability, depth 1).

Previously, the MC implementation:

  1. Hardcoded new device entries to ESSL_OPERATIONAL upon receiving DeviceInfo.
  2. Did not subscribe to EnergyStartStopState.
  3. Only updated its internal state map optimistically as a side effect of receiving a command Reply for an MC-initiated EnergyStartStopRequest.

Consequently, an MC recovering from downtime, resuming heartbeats, or newly started entirely had no mechanism to query or ingest current power device states, leaving its local device registry desynchronized from the actual microgrid state.

Solution

  1. Added EnergyStartStopStateDataReaderListenerImpl:
    • Subscribes to tms::topic::TOPIC_ENERGY_START_STOP_STATE using standard TRANSIENT_LOCAL durability.
    • Configured with multi-partition support ({"*", ""}) to ingest both device-scoped partitions (dev_id) and default global partition traffic.
  2. Controller State Reconciliation:
    • Implemented cached_essl_ caching in Controller to handle discovery race conditions where an EnergyStartStopState sample arrives prior to DeviceInfo registration.
    • Default initial device registration now reflects actual hardware ground truth (or defaults to ESSL_OFF rather than hardcoding ESSL_OPERATIONAL).
  3. Build Configuration:
    • Added listener compilation targets to CMakeLists.txt.

Verification: Multi-MC Failover & State Recovery Test Run
=== Command-Line Interface for Microgrid Controller (MC) ===
list-mc          : list the connected MCs.
list-pd          : list the power devices reported by the connected MCs.
connect-pd       : connect power devices to simulate the power topology of a microgrid.
start   <pd_id>  : start a power device with the given Id.
stop    <pd_id>  : stop a power device with the given Id.
suspend <mc_id>  : suspend the heartbeats of the given MC (simulating an MC becomming unavailable).
resume  <mc_id>  : resume the heartbeats of the given MC (simulating an MC becomming available).
term    <mc_id>  : terminate the given MC's process.
show             : display this list of CLI commands.

ENTER COMMAND:> list-mc
Number of Connected Microgrid Controllers: 2
1. Controller Id: Controller_0 (available)
2. Controller Id: Controller_1 (available)

ENTER COMMAND:> list-pd
Devices connected to Microgrid Controller "Controller_1":

Devices connected to Microgrid Controller "Controller_0":
  1. Id: "Source"       | Type: Source            | Energy Level: Off            | Active Controller: "Controller_0"


ENTER COMMAND:> suspend Controller_1

ENTER COMMAND:> list-mc
Number of Connected Microgrid Controllers: 2
1. Controller Id: Controller_0 (available)
2. Controller Id: Controller_1 (unavailable)

ENTER COMMAND:> start Source

ENTER COMMAND:> list-pd
Devices connected to Microgrid Controller "Controller_0":
  1. Id: "Source"       | Type: Source            | Energy Level: Operational    | Active Controller: "Controller_0"


ENTER COMMAND:> suspend Controller_0

ENTER COMMAND:> resume Controller_1

ENTER COMMAND:> list-mc
Number of Connected Microgrid Controllers: 2
1. Controller Id: Controller_0 (unavailable)
2. Controller Id: Controller_1 (available)

ENTER COMMAND:> list-pd
Devices connected to Microgrid Controller "Controller_1":
  1. Id: "Source"       | Type: Source            | Energy Level: Operational    | Active Controller: "Controller_1"


ENTER COMMAND:> stop Source

ENTER COMMAND:> list-pd
Devices connected to Microgrid Controller "Controller_1":
  1. Id: "Source"       | Type: Source            | Energy Level: Off            | Active Controller: "Controller_1"


ENTER COMMAND:> resume Controller_0

ENTER COMMAND:> suspend Controller_1

ENTER COMMAND:> list-mc
Number of Connected Microgrid Controllers: 2
1. Controller Id: Controller_0 (available)
2. Controller Id: Controller_1 (unavailable)

ENTER COMMAND:> list-pd
Devices connected to Microgrid Controller "Controller_0":
  1. Id: "Source"       | Type: Source            | Energy Level: Off            | Active Controller: "Controller_0"


ENTER COMMAND:>

@zacharyclark-Wright
zacharyclark-Wright marked this pull request as draft October 27, 2026 14:02
@zacharyclark-Wright

Copy link
Copy Markdown
Author

Updated initial comment to reflect that this change fixes #28 and to show the output with the updated source rather than my custom PD implementation.

@zacharyclark-Wright
zacharyclark-Wright marked this pull request as ready for review October 27, 2026 15:39
@mitza-oci
mitza-oci requested a review from sonndinh November 19, 2026 17:16
@mitza-oci mitza-oci changed the title Add EnergyStartStopState lisener to Controller Add EnergyStartStopState listener to Controller Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Synchronize power devices status between MCs

1 participant