A lightweight and extensible PID controller library written in Kotlin Multiplatform (KMP) — designed to bring precise control algorithms to Android, iOS, and desktop systems with minimal effort.
This project is a refactored and extended version of the original Simple PID Controller by Mark Lundberg.
While the core logic was inspired by Lundberg’s work, this implementation was rebuilt from scratch in Kotlin, focusing on cross-platform performance, type safety, and developer experience.
- 🧠 Clean, lightweight, and multiplatform-ready.
- ⚙️ Fully customizable PID gains (
kp,ki,kd). - 🕒 Supports time-based integration and derivative control.
- 🧩 Designed for easy embedding in control loops (motors, sensors, processes, etc.).
- 🔄 Built-in support for anti-windup, output limits, and auto-mode.
- 📱 Works seamlessly across Android, iOS, and JVM targets.
Available on Maven Central:
<dependency>
<groupId>io.github.murilo-migliati</groupId>
<artifactId>controllerPidKmp</artifactId>
<version>1.0.1</version>
</dependency>implementation "io.github.murilo-migliati:controllerPidKmp:1.0.1"implementation("io.github.murilo-migliati:controllerPidKmp:1.0.1")✅ Note: Always check the latest version on Maven Central.
// The correct import (based on your 'namespace')
import com.murilomigliati.pid.PIDController
fun main() {
val pid = PIDController(
kp = 1.2,
ki = 0.8,
kd = 0.4,
setpoint = 100.0
)
var humidity = 80.0
// Simulates a control loop
repeat(5) {
val output = pid.call(humidity)
println("PID output: $output")
// Simulates humidity changing based on the output
if (output != null) {
humidity += output / 10.0
}
}
}This project is licensed under the MIT License.
It includes conceptual work derived from Mark Lundberg’s Simple PID Controller.
MIT License
Copyright (c) 2025 Murilo Migliati
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files ...
| Platform | Status | Notes |
|---|---|---|
| Android | ✅ | Fully supported |
| JVM | ✅ | Compatible with any JVM project |
| iOS | ✅ | Build with KMM native targets |
| macOS / Linux | ✅ | Via Kotlin/Native |
This library focuses on:
- Cross-platform compatibility through KMM.
- Type safety using
Double. - Deterministic math, for predictable control behavior.
- Modular architecture, enabling extensions or custom backends.
- Unit tests for all platforms
- Add time-based tuning utilities
- Integrate simulation helpers for embedded systems
- Provide Compose multiplatform demo
Original idea by Mark Lundberg — Simple PID Controller
Refactored and modernized for Kotlin Multiplatform by Murilo Migliati
Contributions are welcome!
Feel free to open issues or submit pull requests to improve performance, portability, or API clarity.