#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include "ControlTarget.h"
#include "PID_Controler.h"
#include "SatelliteDynamics.h"
#include "AttitudeDescribe.h"
#include "Constant.h"
using namespace m_Constant;
int main()
{
AttitudeDescribe m_AttitudeDescribe;
array<double, 4> m_q_start;
m_AttitudeDescribe.Euler_to_q(10 * d2r, 10 * d2r, 10 * d2r, m_q_start);
array<double, 14> yn = { 0, 0, 0, 0, 0, 0, 0 * d2r,0 * d2r,0 * d2r, m_q_start[0], m_q_start[1], m_q_start[2], m_q_start[3], 0 };
SatelliteDynamics *m_pSatelliteDynamics = new SatelliteDynamics(yn);
double wnx = 5, wny = 5, wnz = 5;
array<double, 3> kp = { 2 * 1.25 / 0.515 * wnx * wnx * 0.6, 2 * 9.65 / 3.18 * wny * wny * 0.6, 2 * 9.65 / 1.59 * wnz * wnz * 0.6 };
array<double, 3> ki = { 0, 0, 0 };
array<double, 3> kd = { sqrt(0.6) * 2 * wnx * 1.25 / 0.515 * 2, sqrt(0.6) * 2 * wny * 9.65 / 3.18, sqrt(0.6) * 2 * wnz * 9.65 / 1.59 * 2 };
PID_Controler *m_pPID = new PID_Controler(kp, ki, kd, h);
ControlTarget *m_pControlTarget = new ControlTarget(0 * d2r, 0 * d2r, 0 * d2r);
array<double, 3> wob_b_mea;
array<double, 4> q_mea;
array<double, 4> q_error;
array<double, 3> Mc = { 0, 0, 0 };
array<double, 3> Fc = { 0, 0, 0 };
string FileName("Euler_Angle.txt");
ofstream outFile(FileName, ios::out);
if (outFile.fail()) cerr << "打开失败!" << endl;
for (; m_pSatelliteDynamics->Get_Time() < 9.99;)
{
m_pSatelliteDynamics->RungeKuttaGill(yn, Mc, Fc);
wob_b_mea = m_pSatelliteDynamics->Get_wob_b();
q_mea = m_pSatelliteDynamics->Get_Quaternion();
m_pControlTarget->ControlCommand(q_mea, q_error);
m_pPID->AttitudeControl(q_error, wob_b_mea, Mc);
outFile << m_pSatelliteDynamics->Get_Time() << ", "
<< m_pSatelliteDynamics->Get_EulerAngle()[0] * r2d << ", " << m_pSatelliteDynamics->Get_EulerAngle()[1] * r2d << ", " << m_pSatelliteDynamics->Get_EulerAngle()[2] * r2d << ", "
<< m_pSatelliteDynamics->Get_wob_b()[0] * r2d << ", " << m_pSatelliteDynamics->Get_wob_b()[1] * r2d << ", " << m_pSatelliteDynamics->Get_wob_b()[2] * r2d << ", "
<< Mc[0] << ", " << Mc[1] << ", " << Mc[2] << endl;
}
outFile.close();
delete m_pSatelliteDynamics;
delete m_pPID;
delete m_pControlTarget;
return 0;
}
测试数据: 各个模块后续补充ing…
|