This is a template for creating external algorithm repositories compatible with the CPPModel algorithm loader.
my-algorithms/
├── README.md
├── CONTRIBUTING.md
├── algorithms.json # Registry of all algorithms
├── schema/
│ └── algorithm.schema.json
└── algorithms/
├── my-controller/
│ ├── definition.json
│ ├── cyclic.ts
│ ├── docs.md
│ └── templates/
│ ├── c.template
│ └── cpp.template
└── my-plant/
└── ...
- Fork this repository
- Add your algorithm in
algorithms/your-algorithm-name/ - Register it in
algorithms.json - Submit a pull request
Algorithms can be loaded from GitHub:
import { algorithmRegistry } from '@/algorithms';
// Load from GitHub repository
await algorithmRegistry.loadFromGitHub('username/repo-name');
// Load specific algorithm from URL
await algorithmRegistry.loadFromUrl('https://raw.githubusercontent.com/user/repo/main/algorithms/my-controller/');{
"id": "unique-algorithm-id",
"name": "Algorithm Display Name",
"shortName": "Short",
"description": "Brief description of the algorithm",
"category": "controller",
"complexity": "intermediate",
"simulationMode": "closed-loop",
"plantId": "first-order-plant",
"parameters": [...],
"tags": ["control", "feedback"]
}Must be a pure function with no side effects:
export function cyclic(
params: Record<string, number>,
inputs: { setpoint: number; feedback?: number },
state: { output: number; [key: string]: unknown } | null,
dt: number
): { output: number; [key: string]: unknown } {
// Your algorithm logic here
return { output: computedValue, ...newState };
}Markdown documentation explaining:
- Algorithm theory
- Parameters description
- Usage examples
- References
C and C++ templates for embedded export.
For security, algorithms must:
- ✅ Be pure functions (deterministic, no side effects)
- ✅ Use only basic math operations
- ❌ No
eval,Function,setTimeout,setInterval - ❌ No
fetch,XMLHttpRequest, network access - ❌ No
window,document,localStorageaccess - ❌ No
require,importstatements - ❌ No infinite loops (execution time limited)
Algorithms in this repository are licensed under MIT unless otherwise specified.