本文整理汇总了C++中PIDController::on方法的典型用法代码示例。如果您正苦于以下问题:C++ PIDController::on方法的具体用法?C++ PIDController::on怎么用?C++ PIDController::on使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PIDController
的用法示例。
在下文中一共展示了PIDController::on方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
PIDController* pid = new PIDController(K_P,K_I,K_D);
pid->on(); // Turn PID controller on
pid->targetSetpoint(SETPOINT); // Change desired setpoint to SETPOINT
double t = 0; // Init with time t=0
double T = 0.01; // Period
double controlVariable = 0; // Init with zero actuation
double processVariable = 0; // Init with zero position
cout << "Simulation running..." << endl;
ofstream writeToCsv;
writeToCsv.open("PIDexample.csv");
writeToCsv << "Time,Setpoint,Output" << endl;
while(t < 20) {
writeToCsv << t << "," << pid->getSetpoint() << "," << processVariable << endl;
controlVariable = pid->calc(processVariable); // Calculate next controlVariable
processVariable = LaplaceInversion(xferFn, t, 1e-8); // Simulate plant with TF 1/((s+a)(s+b))
usleep(T*pow(10,6)); // 100ms delay to simulate actuation time
t += T; // Increment time variable by 100ms
}
writeToCsv.close();
cout << "Simulation complete! Output saved to PIDexample.csv." << endl;
return 0;
}