Skip to content

Repository files navigation

CSPID

CSPID (pronounced "speedy") is a C# PID (proportional-integral-derivative) controller targeting .NET Standard 2.0.

It doesn't work right. You shouldn't use it unless you know more about control theory than I do, which isn't much, and you've confirmed it is (or patched it to be) adequate for your needs, which it probably isn't.

Contents

Installation

Clone the repo with git clone https://github.com/w-bonelli/CSPID.git or pull the package from Nuget.org with PowerShell: Install-Package CSPID.

Usage

There's one class: PIDController. It has one method: double Next(double error, double elapsed = 1). CSPID doesn't care how you measure your error or the passage of time. To construct a controller, provide:

  • errorRange: the range you expect your error values to take
  • controlRange: the range of values your control variable may take

You can tune gain in real time:

  • ProportionalGain
  • IntegralGain
  • DerivativeGain

You can also impose a MaximumStep (the largest permissible change between successive control values).

// create a controllervarcontroller=newPIDController(errorRange:newRange<double>(-5,5),// Range<T> models an inclusive rangecontrolRange:newRange<double>(0,10)){MaximumStep=double.MaxValue,ProportionalGain=1,IntegralGain=1,DerivativeGain=1}asIPIDController;// interface is handy if you need to mock// or do it the old-fashioned waycontroller=newPIDController(minimumError:-5,maximumError:5,minimumControl:0,maximumControl:10){MaximumStep=double.MaxValue,ProportionalGain=1,IntegralGain=1,DerivativeGain=1}asIPIDController;// get a control valuevarvalue1=controller.Next(error:1);// elapsed defaults to 1// get another onevarvalue2=controller.Next(error:-1,elapsed:0.5);

About

broken toy C# PID controller

Resources

Stars

10 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages