You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
157 lines
4.5 KiB
157 lines
4.5 KiB
1 year ago
|
#include <QCoreApplication>
|
||
|
|
||
|
#include "config/log_config.h"
|
||
|
#include "config/database_config.h"
|
||
|
#include "config/kafka_config.h"
|
||
|
#include "handler/log_handler.h"
|
||
|
#include "handler/database_handler.h"
|
||
|
#include "handler/kafka_handler.h"
|
||
|
#include "handler/controller_handler.h"
|
||
|
|
||
|
void loadConfig(const QString& filename){
|
||
|
QFile file(filename);
|
||
|
if(!file.exists()){
|
||
|
qFatal("config file %s is not found!" , qPrintable(filename));
|
||
|
}
|
||
|
auto configs = new QSettings(filename, QSettings::IniFormat);
|
||
|
|
||
|
auto logConf = LogConfig::getIns();
|
||
|
configs->beginGroup("log");
|
||
|
logConf->load(configs);
|
||
|
configs->endGroup();
|
||
|
|
||
|
auto kafkaConf = KafkaConfig::getIns();
|
||
|
configs->beginGroup("kafka");
|
||
|
kafkaConf->load(configs);
|
||
|
configs->endGroup();
|
||
|
|
||
|
auto databaseConf = DatabaseConfig::getIns();
|
||
|
configs->beginGroup("database");
|
||
|
databaseConf->load(configs);
|
||
|
configs->endGroup();
|
||
|
}
|
||
|
|
||
|
void init(){
|
||
|
// 初始化日志, 开启会记录日志到文件
|
||
|
LogHandler::init();
|
||
|
// 初始化数据库
|
||
|
DataBaseHandler::init();
|
||
|
// 初始化Kafka
|
||
|
KafkaHandler::init();
|
||
|
// 初始化Controller
|
||
|
ControllerHandler::init();
|
||
|
}
|
||
|
|
||
|
#include <boost/numeric/odeint.hpp>
|
||
|
using namespace std;
|
||
|
using namespace boost::numeric::odeint;
|
||
|
typedef vector<double> State;
|
||
|
typedef vector<double> Control;
|
||
|
double Nx = 3.0;
|
||
|
double Nz = 2.0;
|
||
|
double mu = M_PI / 12.;
|
||
|
Control control = { Nx, Nz, mu };
|
||
|
vector<State> state_list;
|
||
|
// 飞行器的运动学方程
|
||
|
void dmove2(const State& x_input, State& dxdt, const double t) {
|
||
|
double velocity = x_input[0];
|
||
|
double gamma = x_input[1];
|
||
|
double varphi = x_input[2];
|
||
|
double nx = control[0];
|
||
|
double nz = control[1];
|
||
|
varphi = control[2];
|
||
|
// if(varphi == 0){
|
||
|
// varphi = control[2];
|
||
|
// }
|
||
|
double g = 9.81; // 重力加速度
|
||
|
double velocity_ = g * (nx - sin(gamma)); // 米每秒
|
||
|
double gamma_ = (g / velocity) * (nz * cos(varphi) - cos(gamma)); // 米每秒
|
||
|
double varphi_ = g * nz * sin(varphi) / (velocity * cos(gamma));
|
||
|
dxdt[0] = velocity_;
|
||
|
dxdt[1] = gamma_;
|
||
|
dxdt[2] = varphi_;
|
||
|
}
|
||
|
int k = 1;
|
||
|
void write_pendulum(const State &x, const double t)
|
||
|
{
|
||
|
double velocity = x[0];
|
||
|
double gamma = x[1];
|
||
|
double varphi = x[2];
|
||
|
double dx = velocity * cos(gamma) * sin(varphi);
|
||
|
double dy = velocity * cos(gamma) * cos(varphi);
|
||
|
double dz = velocity * sin(gamma);
|
||
|
State new_state(6);
|
||
|
new_state[0] = state_list[k - 1][0] + dx;
|
||
|
new_state[1] = state_list[k - 1][1] + dy;
|
||
|
new_state[2] = state_list[k - 1][2] + dz;
|
||
|
new_state[3] = velocity;
|
||
|
new_state[4] = gamma;
|
||
|
new_state[5] = varphi;
|
||
|
k++;
|
||
|
state_list.push_back(new_state);
|
||
|
}
|
||
|
|
||
|
void boost_test(){
|
||
|
double init_velocity = 260.0;
|
||
|
double init_gamma = M_PI / 10.0;
|
||
|
double init_varphi = 0.0;
|
||
|
double init_x = 0.0;
|
||
|
double init_y = 0.0;
|
||
|
double init_z = 1000.0;
|
||
|
State int_state(6);
|
||
|
int_state[0] = init_x;
|
||
|
int_state[1] = init_y;
|
||
|
int_state[2] = init_z;
|
||
|
int_state[3] = init_velocity;
|
||
|
int_state[4] = init_gamma;
|
||
|
int_state[5] = init_varphi;
|
||
|
state_list.push_back(int_state);
|
||
|
State init_state = { init_velocity, init_gamma, init_varphi };
|
||
|
integrate_const(runge_kutta4<State>(), dmove2, init_state, 0.0 ,10.0 ,0.1, write_pendulum);
|
||
|
string filename = R"(test.csv)";
|
||
|
ofstream ofs(filename);
|
||
|
if(ofs.is_open()){
|
||
|
ofs << "x,y,z,v,g,f\n";
|
||
|
for (const auto& state : state_list) {
|
||
|
int i = 0;
|
||
|
for (const auto& val : state) {
|
||
|
cout << val << ",";
|
||
|
if(i == 5){
|
||
|
ofs << val;
|
||
|
i = 0;
|
||
|
}else{
|
||
|
ofs << val << ",";
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
cout << "\n";
|
||
|
ofs << "\n";
|
||
|
}
|
||
|
ofs.close();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// TODO 当前是将消息广播全部消费者自行判断是否消费,该种机制是否合理后续在进行论证
|
||
|
int main(int argc, char *argv[]) {
|
||
|
QCoreApplication app(argc, argv);
|
||
|
|
||
|
// 加载配置文件
|
||
|
// loadConfig(QCoreApplication::applicationDirPath() + "/application.ini");
|
||
|
|
||
|
// 初始化系统
|
||
|
// init();
|
||
|
|
||
|
/// test -start
|
||
|
// qDebug() << "init";
|
||
|
// QString msg = "{\"name\":\"张三\"}";
|
||
|
// QString key = "loadMap";
|
||
|
// auto headers = RdKafka::Headers::create();
|
||
|
// headers->add("token", "safdasgdagafgafdsghfsjh");
|
||
|
// KafkaHandler::message("test_topic" , msg, key , headers);
|
||
|
|
||
|
boost_test();
|
||
|
/// test -end
|
||
|
|
||
|
return QCoreApplication::exec();
|
||
|
}
|