/godot_pid_controller

GDNative plugin for simple and fast PID controllers in Godot

Primary LanguageMakefileMIT LicenseMIT

Godot PID Controller plugin

Implements simple, very fast PID and PD controllers as a GDNative plugin.

Installation

Linux

Clone this repo into your Godot project:

$ git clone git@github.com:slavfox/godot_pid_controller.git

Or add it as a submodule:

$ git submodule add git@github.com:slavfox/godot_pid_controller.git

Windows & macOS

See Development and Building

Usage

Preload the class you need:

const PIDController = preload("res://godot_pid_controller/pid_controller.gdns")
# and/or
const PDController = preload("res://godot_pid_controller/pd_controller.gdns")

Initialize the controller and term coefficients (they're set at 1.0 by default, which is probably not what you need!):

var controller: PIDController = PIDController.new()
controller.k_p = 0.5
controller.k_i = 0.05
controller.k_d = 0.1

And then just call PIDController.get_output(error: float, dt: float) with the current error (target value - current value of the variable you want to control) and time since the last call!

The example uses a PID and a PD controller with intentionally detuned term coefficients to make a sprite follow the mouse.

Development and building

(Building on non-Linux platforms is probably broken, pull requests welcome)

Make your changes to the source (in src/), and then run

$ make

There are additional options available for building. Run

$ make help

to see them.

If you want to change the build process, you might need to edit the SConstruct file or the Makefile.

License

godot_pid_controller is licensed MIT.