線形制御系設計
モーションコントロール
モータドライブ
システム同定
階層システムの管理
設計例
モータドライブシステムのクラス設計
lib/motor.h
class motor { private: double Ts; // Time step double J; // Inertia double x; // Angle double dx; // Angular velocity double ddx; // Angular acceleration public: motor(double SmplTime, double Jn); ~motor(); void InitializeState(double InitValue); void UpdateState(double torque); void ClearState(void); double GetState(void); };
lib/motor.cpp
#include <math.h> #include "motor.h" motor::motor(double SmplTime, double Jn) : J(Jn), Ts(SmplTime) { x = 0.0; dx = 0.0; ddx = 0.0; } motor::~motor() {}; void motor::InitializeState(double InitValue) { x = InitValue; dx = 0.0; ddx = 0.0; }; void motor::UpdateState(double torque) { const int div = 100; const double Tp = Ts / 100; for (int i = 0; i < div; i++) { x += dx * Tp; dx += ddx * Tp; ddx = torque / J; } }; void motor::ClearState() { x = 0.0; dx = 0.0; ddx = 0.0; }; double motor::GetState() { return x; };
運動制御器のクラス設計
lib/PDcontroller.h
class PDcontroller { private: double Ts; // Time step double Cp; // P gain double Cd; // D gain double e; // Error double eZ1; // Error at 1 step before double de; // Derivative of error public: PDcontroller(double SmplTime, double nCp, double nCd); ~PDcontroller(); void setGain(double nCp, double nCd); double GenerateReference(double xcmd, double xsen); void ClearState(void); };
lib/PDcontroller.cpp
#include <math.h> #include "PDcontroller.h" PDcontroller::PDcontroller(double SmplTime, double nCp, double nCd) : Cp(nCp), Cd(nCd), Ts(SmplTime) { e = 0.0; de = 0.0; } PDcontroller::~PDcontroller() {}; void PDcontroller::setGain(double nCp, double nCd) { Cp = nCp; Cd = nCd; }; double PDcontroller::GenerateReference(double xcmd, double xsen) { e = xcmd - xsen; de = (e - eZ1) / Ts; eZ1 = e; return Cp * e + Cd * de; }; void PDcontroller::ClearState(void) { e = 0.0; de = 0.0; };
システム制御系の設計
main.cpp
#include "motor.h" #include "PDcontroller.h" int main (void) { // Setting const double Ts = 1e-3; // Sampling time const int motorNum = 5; const double Jn [motorNum] = { 1.2, 2.1, 3.2, 4.6, 5.2}; // Variables double t = 0.0; double x[motorNum] = { 0.0 }; double xcmd[motorNum] = { 0.0 }; double tau[motorNum] = { 0.0 }; // Controller setting double nCp[5] = { 0.0 }; double nCd[5] = { 0.0 }; const double wn = 20.0; // Natural frequency const double dn = 1.0; // Damping coefficient for (int j = 0; j < motorNum; j++) { nCp[j] = Jn[j] * wn * wn; nCd[j] = Jn[j] * 2.0 * dn * wn; } // Instance static motor* motors[motorNum]; static PDcontroller* controllers[motorNum]; for (int j = 0; j < motorNum; j++) { motors[j] = new motor(Ts, Jn[j]); controllers[j] = new PDcontroller(Ts, nCp[j], nCd[j]); } for (int i = 0; i < 5e4; i++) { // Observe for (int j = 0; j < motorNum; j++) x[j] = motors[j] -> GetState(); // Set reference for (int j = 0; j < motorNum; j++) xcmd[j] = (t > 1.0)? 1.0 : 0.0; // Calculate input for (int j = 0; j < motorNum; j++) tau[j] = controllers[j] -> GenerateReference(xcmd[j], x[j]); // Update for (int j = 0; j < motorNum; j++) motors[j] -> UpdateState(tau[j]); t += Ts; } for (int j = 0; j < motorNum; j++) { delete motors[j]; delete controllers[j]; } return 0; }
設計上の注意
© DigitalServo