From 9da872d928602ab3c7d7850eed3337860a709af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=98=E4=B8=8D=E5=A6=82=E4=B8=80=E5=8F=AA=E7=8C=AA?= =?UTF-8?q?=E5=A8=81=E6=AD=A6?= Date: Wed, 8 Nov 2023 08:36:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B7=A8=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 9 +++ CMakeLists.txt | 29 ++++++--- application.ini | 6 +- compute/three.cpp | 49 ++++++++++++++ compute/three.h | 127 +++++++++++++++++++++++++++++++++++++ entity/map_entity.h | 5 +- handler/database_handler.h | 3 +- main.cpp | 106 +++---------------------------- 8 files changed, 222 insertions(+), 112 deletions(-) create mode 100644 .gitmodules create mode 100644 compute/three.cpp create mode 100644 compute/three.h diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a0e4964 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "third_party/QxOrm"] + path = third_party/QxOrm + url = https://github.com/QxOrm/QxOrm.git +[submodule "third_party/librdkafka"] + path = third_party/librdkafka + url = https://github.com/confluentinc/librdkafka.git +[submodule "third_party/boost"] + path = third_party/boost + url = https://github.com/boostorg/boost.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 98fa485..fa30057 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,13 +6,20 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) -set(CMAKE_PREFIX_PATH $ENV{QT_5_MINGW64}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_CURRENT_BINARY_DIR}") +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_CURRENT_BINARY_DIR}") -set(BOOST_INCLUDES third_party/boost-1_83/include) +if(WIN32) + set(CMAKE_PREFIX_PATH $ENV{QT_5_MINGW64}) + set(BOOST_INCLUDES third_party/boost-1_83/include) + set(BOOST_LIBRARIES third_party/boost-1_83/lib) +endif () -# 添加QxOrm配置 -include(third_party/QxOrm/QxOrm.cmake) +if(APPLE) + set(BOOST_ROOT "/usr/local/Cellar/boost/1.83.0") + find_package(Boost 1.83.0 COMPONENTS system) + set(BOOST_INCLUDES ${Boost_INCLUDE_DIRS}) + set(BOOST_LIBRARIES ${Boost_LIBRARIES}) +endif () add_executable(${PROJECT_NAME} main.cpp) @@ -60,14 +67,18 @@ target_link_libraries(${PROJECT_NAME} PUBLIC rdkafka rdkafka++ QxOrm + ${BOOST_LIBRARIES} ) +include(third_party/QxOrm/QxOrm.cmake) +add_subdirectory(third_party/librdkafka) + # 拷贝依赖库 file(COPY application.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝QxOrm -file(COPY lib/kafka/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝kafka -file(GLOB LIB "lib/*.dll") -file(COPY ${LIB} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝mysql -file(COPY lib/sqldrivers DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝QT mysql驱动 +#file(COPY lib/kafka/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝kafka +#file(GLOB LIB "lib/*.dll") +#file(COPY ${LIB} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝mysql +#file(COPY lib/sqldrivers DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝QT mysql驱动 file(COPY third_party/QxOrm/lib/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝QxOrm if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) diff --git a/application.ini b/application.ini index f6e472e..95c2389 100644 --- a/application.ini +++ b/application.ini @@ -1,9 +1,9 @@ [database] host=localhost port=3306 -database=csci -username=csci -password=csci@1234 +database=sim +username=root +password=root123 driver=QMYSQL [kafka] diff --git a/compute/three.cpp b/compute/three.cpp new file mode 100644 index 0000000..2cec5b3 --- /dev/null +++ b/compute/three.cpp @@ -0,0 +1,49 @@ +// +//#include "three.h" +// +//vector Tree::run(const State &init_state, double start, double end, double t) { +//// integrate_const(runge_kutta4(), dmove2, init_state, start ,end ,t, write_pendulum); +// return _stateList; +//} +// +//void Tree::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_; +//} +// +//void Tree::setController(const State &control) { +// _k = 1; +// _control = control; +//} +// +//void Tree::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] = _stateList[_k - 1][0] + dx; +// new_state[1] = _stateList[_k - 1][1] + dy; +// new_state[2] = _stateList[_k - 1][2] + dz; +// new_state[3] = velocity; +// new_state[4] = gamma; +// new_state[5] = varphi; +// _k++; +// _stateList.push_back(new_state); +//} diff --git a/compute/three.h b/compute/three.h new file mode 100644 index 0000000..34b4489 --- /dev/null +++ b/compute/three.h @@ -0,0 +1,127 @@ +// +//#ifndef CSCI_THREE_H +//#define CSCI_THREE_H +// +///* +//typedef vector State; +//typedef vector Control; +//double Nx = 3.0; +//double Nz = 2.0; +//double mu = M_PI / 12.; +//Control control = { Nx, Nz, mu }; +//vector 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(), 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(); +// } +//} +// +// */ +// +//#include +// +//using namespace std; +//using namespace boost::numeric::odeint; +// +//typedef vector State; +//typedef vector Control; +// +//class Tree { +// +//private: +// static int _k; +// +// static Control _control; +// +// static vector _stateList; +// +//private: +// +// static void dmove2(const State& x_input, State& dxdt, const double t); +// +// static void write_pendulum(const State &x, const double t); +// +//public: +// +// static void setController(const State &control); +// +// static vector run(const State& init_state, double start, double end, double dt); +// +// +//}; +// +// +//#endif //CSCI_THREE_H diff --git a/entity/map_entity.h b/entity/map_entity.h index b4853e5..0da56d7 100644 --- a/entity/map_entity.h +++ b/entity/map_entity.h @@ -2,7 +2,10 @@ #ifndef CSCI_MAP_ENTITY_H #define CSCI_MAP_ENTITY_H -#include +//#ifndef _MSC_VER +//#include +//#endif +#include #include class MapEntity{ diff --git a/handler/database_handler.h b/handler/database_handler.h index ba681d9..554e0cb 100644 --- a/handler/database_handler.h +++ b/handler/database_handler.h @@ -3,7 +3,8 @@ #define CSCI_DATABASE_HANDLER_H #include -#include +//#include +#include #include #include "../config/database_config.h" diff --git a/main.cpp b/main.cpp index 0f607d4..46d254b 100644 --- a/main.cpp +++ b/main.cpp @@ -33,116 +33,26 @@ void loadConfig(const QString& filename){ void init(){ // 初始化日志, 开启会记录日志到文件 - LogHandler::init(); +// LogHandler::init(); // 初始化数据库 - DataBaseHandler::init(); +// DataBaseHandler::init(); // 初始化Kafka KafkaHandler::init(); // 初始化Controller ControllerHandler::init(); } -#include -using namespace std; -using namespace boost::numeric::odeint; -typedef vector State; -typedef vector Control; -double Nx = 3.0; -double Nz = 2.0; -double mu = M_PI / 12.; -Control control = { Nx, Nz, mu }; -vector 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(), 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(); - } -} - #include "./compute/bessel.h" void bessel_test(){ - - vector points = {{0.0,0.0,0.0}, {20.0, 80.0,70.0},{40.0,120.0,68.0},{80.0,240.0,68.0}}; - - vector res = Bessel::run(points, 0.02); - + // 轨迹关键点 + vector points = {{0.0,0.0,0.0}, {200.0, 800.0,7000.0},{400.0,0.0,6800.0},{800.0,800.0,8000.0}}; + // 计算步长 + vector res = Bessel::run(points, 0.001); + // 计算结果存储到文件 string filename = R"(test_1.csv)"; ofstream ofs(filename); ofs << "x,y,z" << endl; - for (const auto &item: res){ ofs << item.x << "," << item.y << "," << item.z << endl; } @@ -166,9 +76,9 @@ int main(int argc, char *argv[]) { // auto headers = RdKafka::Headers::create(); // headers->add("token", "safdasgdagafgafdsghfsjh"); // KafkaHandler::message("test_topic" , msg, key , headers); - // boost_test(); bessel_test(); + qDebug() << "sds"; /// test -end return QCoreApplication::exec();