# hggshiwo/dankong architecture

> Architecture diagram of the GitHub repository hggshiwo/dankong, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hggshiwo/dankong
- Repository: https://github.com/hggshiwo/dankong

## Overview

Dankong is a modular robot-control system built around a `dk` event-driven hierarchical state machine. Its principal workflow is external commands entering through adapters, being converted to events, handled by listeners and scheduled as state/mission actions; states read shared context, invoke tracking or landing logic, and command a robot abstraction. The README documents the adapter, robot, feature and HSM layers; the source index confirms selected assembly, state, control and MAVLink relationships. Some feature internals and adapter bindings were not sampled, so those links are documented rather than inferred from names.

Main entry points: [`include/targets`](https://github.com/hggshiwo/dankong/tree/master/include/targets) (Robot context), [`src/adapters`](https://github.com/hggshiwo/dankong/tree/master/src/adapters) (Protocol adapters), [`include/states`](https://github.com/hggshiwo/dankong/tree/master/include/states) (Robot behavior states), [`include/robot/irobot.hpp`](https://github.com/hggshiwo/dankong/blob/master/include/robot/irobot.hpp) (Robot abstraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Startup and adapters"]
  node_node["Dankong node<br/>[dankong_node.cpp]"]
  node_adapters["Protocol adapters"]
end

subgraph group_runtime["Control runtime"]
  node_listener["Control listener<br/>[event_listener.cpp]"]
  node_engine["Event HSM engine<br/>[engine.hpp]"]
  node_states["Robot behavior states"]
  node_context["Robot context"]
end

subgraph group_features["Robot capabilities"]
  node_tracker["Motion tracker<br/>[tracker.hpp]"]
  node_landing["Precision landing"]
  node_algo["Algorithm features"]
  node_ntrip["RTK corrections<br/>[ntrip_client.hpp]"]
  node_report["State reporting"]
end

subgraph group_hardware["Robot and protocols"]
  node_robot["Robot abstraction<br/>[irobot.hpp]"]
  node_vehicle["Vehicle implementations"]
  node_mavlink["MAVLink interface<br/>[imavlink.hpp]"]
  node_mavsdk["MAVSDK transport<br/>[mavsdk_drone.cpp]"]
end

subgraph group_shared["Shared services"]
  node_config["Configuration manager<br/>[global_config.hpp]"]
  node_registry["State registry<br/>[state_registry.hpp]"]
  node_dirty["Shared state values<br/>[dirty_var.hpp]"]
end

node_operator(("External command"))

node_operator -->|"sends commands"| node_adapters
node_adapters -->|"bind observations"| node_context
node_adapters -->|"bind events"| node_listener
node_node -->|"assembles target"| node_context
node_listener -->|"returns actions"| node_engine
node_engine -->|"dispatches actions"| node_states
node_states -->|"reads state"| node_context
node_states -->|"sends position commands"| node_tracker
node_states -->|"issues control"| node_robot
node_landing -->|"uses observations"| node_context
node_context -->|"provides tracker context"| node_tracker
node_context -->|"provides landing context"| node_landing
node_context -->|"includes feature context"| node_algo
node_context -->|"includes feature context"| node_ntrip
node_context -->|"includes feature context"| node_report
node_report -->|"registers values"| node_registry
node_registry -->|"reads dirty values"| node_dirty
node_vehicle -->|"implements interface"| node_robot
node_robot -->|"forwards commands"| node_mavlink
node_mavsdk -->|"implements transport"| node_mavlink
node_config -->|"supplies settings"| node_context
node_adapters -.->|"optional transport binding"| node_mavlink

click node_node "https://github.com/hggshiwo/dankong/blob/master/src/dankong_node.cpp"
click node_adapters "https://github.com/hggshiwo/dankong/tree/master/src/adapters"
click node_listener "https://github.com/hggshiwo/dankong/blob/master/src/features/control/event_listener.cpp"
click node_engine "https://github.com/hggshiwo/dankong/blob/master/include/core/engine.hpp"
click node_states "https://github.com/hggshiwo/dankong/tree/master/include/states"
click node_context "https://github.com/hggshiwo/dankong/tree/master/include/targets"
click node_tracker "https://github.com/hggshiwo/dankong/blob/master/include/features/tracker/tracker.hpp"
click node_landing "https://github.com/hggshiwo/dankong/blob/master/include/features/pland/landing_controller.hpp"
click node_algo "https://github.com/hggshiwo/dankong/tree/master/include/features/algo"
click node_ntrip "https://github.com/hggshiwo/dankong/blob/master/include/features/ntrip/ntrip_client.hpp"
click node_report "https://github.com/hggshiwo/dankong/tree/master/include/features/report"
click node_robot "https://github.com/hggshiwo/dankong/blob/master/include/robot/irobot.hpp"
click node_vehicle "https://github.com/hggshiwo/dankong/tree/master/include/robot"
click node_mavlink "https://github.com/hggshiwo/dankong/blob/master/include/mavlink/imavlink.hpp"
click node_mavsdk "https://github.com/hggshiwo/dankong/blob/master/src/mavlink/mavsdk_drone.cpp"
click node_config "https://github.com/hggshiwo/dankong/blob/master/include/core/global_config.hpp"
click node_registry "https://github.com/hggshiwo/dankong/blob/master/include/utils/state_registry.hpp"
click node_dirty "https://github.com/hggshiwo/dankong/blob/master/include/utils/dirty_var.hpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node,node_adapters toneBlue
class node_listener,node_engine,node_states,node_context toneAmber
class node_tracker,node_landing,node_algo,node_ntrip,node_report toneMint
class node_robot,node_vehicle,node_mavlink,node_mavsdk toneRose
class node_config,node_registry,node_dirty,node_operator toneIndigo
```

## Components

### Startup and adapters

- [Dankong node](https://github.com/hggshiwo/dankong/blob/master/src/dankong_node.cpp): `src/dankong_node.cpp`
- [Protocol adapters](https://github.com/hggshiwo/dankong/tree/master/src/adapters): `src/adapters`

### Control runtime

- [Control listener](https://github.com/hggshiwo/dankong/blob/master/src/features/control/event_listener.cpp): `src/features/control/event_listener.cpp`
- [Event HSM engine](https://github.com/hggshiwo/dankong/blob/master/include/core/engine.hpp): `include/core/engine.hpp`
- [Robot behavior states](https://github.com/hggshiwo/dankong/tree/master/include/states): `include/states`
- [Robot context](https://github.com/hggshiwo/dankong/tree/master/include/targets): `include/targets`

### Robot capabilities

- [Motion tracker](https://github.com/hggshiwo/dankong/blob/master/include/features/tracker/tracker.hpp): `include/features/tracker/tracker.hpp`
- [Precision landing](https://github.com/hggshiwo/dankong/blob/master/include/features/pland/landing_controller.hpp): `include/features/pland/landing_controller.hpp`
- [Algorithm features](https://github.com/hggshiwo/dankong/tree/master/include/features/algo): `include/features/algo`
- [RTK corrections](https://github.com/hggshiwo/dankong/blob/master/include/features/ntrip/ntrip_client.hpp): `include/features/ntrip/ntrip_client.hpp`
- [State reporting](https://github.com/hggshiwo/dankong/tree/master/include/features/report): `include/features/report`

### Robot and protocols

- [Robot abstraction](https://github.com/hggshiwo/dankong/blob/master/include/robot/irobot.hpp): `include/robot/irobot.hpp`
- [Vehicle implementations](https://github.com/hggshiwo/dankong/tree/master/include/robot): `include/robot`
- [MAVLink interface](https://github.com/hggshiwo/dankong/blob/master/include/mavlink/imavlink.hpp): `include/mavlink/imavlink.hpp`
- [MAVSDK transport](https://github.com/hggshiwo/dankong/blob/master/src/mavlink/mavsdk_drone.cpp): `src/mavlink/mavsdk_drone.cpp`

### Shared services

- [Configuration manager](https://github.com/hggshiwo/dankong/blob/master/include/core/global_config.hpp): `include/core/global_config.hpp`
- [State registry](https://github.com/hggshiwo/dankong/blob/master/include/utils/state_registry.hpp): `include/utils/state_registry.hpp`
- [Shared state values](https://github.com/hggshiwo/dankong/blob/master/include/utils/dirty_var.hpp): `include/utils/dirty_var.hpp`

### Other components

- **External command**

## Connections

- External command → Protocol adapters: sends commands
- Protocol adapters → Robot context: bind observations
- Protocol adapters → Control listener: bind events
- Dankong node → Robot context: assembles target (evidence: `include/targets/car/robot_context.hpp`)
- Control listener → Event HSM engine: returns actions
- Event HSM engine → Robot behavior states: dispatches actions
- Robot behavior states → Robot context: reads state (evidence: `include/states/posvel_state.hpp`)
- Robot behavior states → Motion tracker: sends position commands (evidence: `include/states/posvel_state.hpp`)
- Robot behavior states → Robot abstraction: issues control (evidence: `include/states/state_utils.hpp`)
- Precision landing → Robot context: uses observations (evidence: `include/features/pland/landing_controller.hpp`)
- Robot context → Motion tracker: provides tracker context (evidence: `include/targets/car/robot_context.hpp`)
- Robot context → Precision landing: provides landing context (evidence: `include/targets/drone/robot_context.hpp`)
- Robot context → Algorithm features: includes feature context (evidence: `include/targets/drone/robot_context.hpp`)
- Robot context → RTK corrections: includes feature context (evidence: `include/targets/drone/robot_context.hpp`)
- Robot context → State reporting: includes feature context (evidence: `include/targets/car/robot_context.hpp`)
- State reporting → State registry: registers values (evidence: `include/features/report/context.hpp`)
- State registry → Shared state values: reads dirty values (evidence: `include/utils/state_registry.hpp`)
- Vehicle implementations → Robot abstraction: implements interface (evidence: `include/robot/car.hpp`)
- Robot abstraction → MAVLink interface: forwards commands (evidence: `include/robot/irobot.hpp`)
- MAVSDK transport → MAVLink interface: implements transport
- Configuration manager → Robot context: supplies settings (evidence: `include/core/global_config.hpp`)
- Protocol adapters → MAVLink interface: optional transport binding
