Skip to content

A pid controller implementation featuring several transfer functions, backward euler or tustin integration, two anti-windup methods and a test simulation.

License

Notifications You must be signed in to change notification settings

corraid/cmon-pid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cmon-pid

A implementation of several common PID controller transfer functions in C++, header only, without dependencies.

Usage:

#include <cmon-pid.h>
extern double GetActuator();
extern double Setpoint();
extern double SensorReading();
extern void SetActuator(double);
extern void Sleep(double);

void PidTask()
{

	// Select a pid object of class pid_bwe (backward euler)
	// or pid_bil (tustin) and
	// a anti-windup template class backcalculation_t
	// or clamping_t
	clamping_t<pid_bwe> pid;

	// Set PID parameters
	constexpr double samplingTime = 0.1;
	constexpr double gain = 10;
	constexpr double T1 = 10;
	constexpr double T2 = 3;
	pid.SerialPid(samplingTime, gain, T1, T2, samplingTime / 2);

	// Set clamping range
	pid.Clamping(-2, 10);

	// Initialize it
	pid.SteadyStateInit(GetActuator());

	// Control loop
	for (;;)
	{
		double e = Setpoint() - SensorReading();
		double y = pid.Update(e);
		SetActuator(y);
		Sleep(samplingTime);
	}
}

About

A pid controller implementation featuring several transfer functions, backward euler or tustin integration, two anti-windup methods and a test simulation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published