Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aleksrutins/ctrlcurve
A library for PID control in Java.
https://github.com/aleksrutins/ctrlcurve
Last synced: about 22 hours ago
JSON representation
A library for PID control in Java.
- Host: GitHub
- URL: https://github.com/aleksrutins/ctrlcurve
- Owner: aleksrutins
- License: mit
- Created: 2022-03-19T15:39:53.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-23T18:32:27.000Z (8 months ago)
- Last Synced: 2024-03-24T02:24:11.219Z (8 months ago)
- Language: Kotlin
- Homepage:
- Size: 162 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ctrlcurve
_A library for PID (proportional-integral-derivative) control in Kotlin._## Getting started
I learned the hard way with [station](https://github.com/aleksrutins/station) that GitHub Packages maybe isn't the best idea for Maven/Gradle packages. So, just use JitPack.
```groovy
repositories {
maven { url 'https://jitpack.io' }
}...
dependencies {
implementation 'com.github.aleksrutins:ctrlcurve:0.1.0'
}
```
Please note, though, that the package is `com.farthergate.ctrlcurve`, not `com.github.aleksrutins.ctrlcurve`.## Usage
```java
import com.farthergate.ctrlcurve.PID;// ...
// Initialize constants
// The starting value
double initial = 0.0;
// The target value
double target = 10;
// The PID coefficient
double kp = 100.0;
// Time of integration
double ti = 50;
// Time of differentiation
double td = 50;
// Milliseconds to wait between iterations
double dt = 10;
// The tolerance for floating-point comparisons
double tolerance = 0.01;
// This is the current value; in a real-life situation, this would be written to actuators and read back from sensors.
double current = initial;// Run a PID loop
// The loop ends once it is within `tolerance` of the target position. The value at that point is not necessarily the exact same value as the target position.
for(var pid = new PID(kp, ti, td, dt, tolerance, initial, target); pid.shouldContinue(); pid.update(current)) {// `correction()` does the actual PID math, and returns a correction value to smoothly transition between `target` and `current`.
current += pid.correction();// `sync()` waits for `dt` milliseconds, to allow time for sensors to update.
pid.sync();
}
```