pid

command module
v0.0.0-...-4e856a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 6 Imported by: 0

README

Go

pid is a PID controller (as you might have guessed by the name). If you need more information on what a PID contorller is, Wikipedia is your friend.

Quickstart

Super straight-forward:

  var controller controllers.Controller = pid.New(0.01, 0.01, 0.5, 1)
	controller.SetTarget(500)

	file, err := os.OpenFile("output.csv", os.O_CREATE|os.O_WRONLY, os.ModePerm)
	defer file.Close()

	writer := csv.NewWriter(file)
	writer.Write([]string{"Iteration", "Value"})

	lastValue := 0.0
	for i := 0; i < 1000; i++ {
		delta := controller.Update(lastValue)
		lastValue += delta
		valueString := fmt.Sprintf("%f", lastValue)
		iteration := fmt.Sprintf("%d", i)

		writer.Write([]string{iteration, valueString})
	}
	writer.Flush()

The above snippet will create a PID controller and iterate for 1000 times until the target number converges creating a CSV with all the iterations.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL