diff --git a/algorithms/src/GroundControlStation/README.md b/algorithms/src/GroundControlStation/README.md index ae1feecb..f4e1eb8a 100644 --- a/algorithms/src/GroundControlStation/README.md +++ b/algorithms/src/GroundControlStation/README.md @@ -5,3 +5,11 @@ ##### Each station contains some small hexagons. Each hexagon contains multiple layers with different height. ##### When a vehicle try to plan its path: the stations in this path are involved, and hexagons with a certain altitude(in other words, 3d cellulars) are distributed to this vehicle by these stations. If path is generated successfully by stations, these 3d cellulars are set status "occupied", which will be maintained by these stations. + +# 自动飞行汽车地面控制站 + +### 这些地面被蜂窝状放置.如同你的手机使用的基站一样. + +##### 每个站负责一块小六边形区域.每个区域有多个层 + +##### 当空中载具尝试规划路径时,经过的基站参与这一过程.小六边形块对应的高度层被分配给这些空中载具.如果路径生成成功,这些带高度的小六边形块在地面基站里被标记为已占据. diff --git a/algorithms/src/SystemManagement/README.md b/algorithms/src/SystemManagement/README.md index 5a8a0c3a..445b5cc2 100644 --- a/algorithms/src/SystemManagement/README.md +++ b/algorithms/src/SystemManagement/README.md @@ -2,8 +2,12 @@ 主要负责机上飞行状态切换,与地面站通信,飞行前申请空域,宏观上规划/协商飞行器的最优路径,监控飞行器自身状态并向地面汇报;是连接机上状态和地面站通信的桥梁. +使用http传递json的方式向地面站服务器发送自身状态. + System Management module. In charge of flight status management(FSM), communication with ground control station, negotiation of best path and surveillance of vehicle state. This module is the bridge between vehicle and ground control station. + +This module reports vehicle's state with http request to the http server set on ground control station. diff --git a/algorithms/src/SystemManagement/basic_state_libs/src/FlightStatus.h b/algorithms/src/SystemManagement/basic_state_libs/src/FlightStatus.h index 1505979a..e47182d7 100644 --- a/algorithms/src/SystemManagement/basic_state_libs/src/FlightStatus.h +++ b/algorithms/src/SystemManagement/basic_state_libs/src/FlightStatus.h @@ -3,11 +3,13 @@ #include "FlightStage.h" #include "location_and_coordinates/LocationT.h" +#include "../../json_request_response_lib/src/JSONSerializableAbstract.h" namespace GAASManagement { -struct GAASFlightStatusT//用于和地面同步飞行状态. +class GAASFlightStatusT:public JSONSerializableAbstract//用于和地面同步飞行状态. { +public: string current_map_name; FlightStageT current_mode = FlightStage::IDLE_STAGE; LocationT currentLocation,TargetLocation; @@ -19,6 +21,7 @@ struct GAASFlightStatusT//用于和地面同步飞行状态. LocationT getTargetLocation(); void serialize(); void deserialize(); + json getJSONObject(); }; diff --git a/algorithms/src/SystemManagement/basic_state_libs/src/VehicleStaticInfo.h b/algorithms/src/SystemManagement/basic_state_libs/src/VehicleStaticInfo.h index 25c4e513..1b91f85b 100644 --- a/algorithms/src/SystemManagement/basic_state_libs/src/VehicleStaticInfo.h +++ b/algorithms/src/SystemManagement/basic_state_libs/src/VehicleStaticInfo.h @@ -1,12 +1,13 @@ #ifndef GAAS_VEHICLE_STATIC_INFO_HEADER #define GAAS_VEHICLE_STATIC_INFO_HEADER +#include "../../json_request_response_lib/src/JSONSerializableAbstract.h" - -struct VehicleStaticInfo; -struct VehicleStaticInfo +class VehicleStaticInfo; +class VehicleStaticInfo:public JSONSerializableAbstract { +public: string vehicle_name;//飞行器名称 double vehicle_size_x,vehicle_size_y,vehicle_size_z;// 尺寸 bool isVTOL = true;//支持垂直起降. @@ -15,5 +16,6 @@ struct VehicleStaticInfo void serialize(); void deserialize(); void loadFromConfigFile();//从配置文件加载. + json getJSONObject(); }; #endif diff --git a/algorithms/src/SystemManagement/json_request_response_lib/CMakeLists.txt b/algorithms/src/SystemManagement/json_request_response_lib/CMakeLists.txt index b6b71ed7..6e1719e8 100644 --- a/algorithms/src/SystemManagement/json_request_response_lib/CMakeLists.txt +++ b/algorithms/src/SystemManagement/json_request_response_lib/CMakeLists.txt @@ -2,14 +2,14 @@ cmake_minimum_required(VERSION 2.8.3) project(json_request_response_lib) ## Compile as C++11, supported in ROS Kinetic and newer -add_compile_options(-std=c++17 -O0) -#add_compile_options(-std=c++17 -O3) +#add_compile_options(-std=c++17 -O0) +add_compile_options(-std=c++17 -O3) ## Find catkin macros and libraries ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## is used, also find other catkin packages -set(CMAKE_BUILD_TYPE DEBUG) -#set(CMAKE_BUILD_TYPE RELEASE) +#set(CMAKE_BUILD_TYPE DEBUG) +set(CMAKE_BUILD_TYPE RELEASE) #find_package(OpenCV 3.4.5 REQUIRED) find_package(Glog REQUIRED) find_package(catkin REQUIRED COMPONENTS diff --git a/algorithms/src/SystemManagement/json_request_response_lib/src/EncryptedJSON.h b/algorithms/src/SystemManagement/json_request_response_lib/src/EncryptedJSON.h index 67cbeb86..9f628823 100644 --- a/algorithms/src/SystemManagement/json_request_response_lib/src/EncryptedJSON.h +++ b/algorithms/src/SystemManagement/json_request_response_lib/src/EncryptedJSON.h @@ -37,13 +37,13 @@ struct EncryptedJSONResponse std::shared_ptr pResponse_json; }; -static std::string request_function(const json& j_)//,std::promise& promise) +static std::string request_function(const json& j_,const string& api_url)//,std::promise& promise) { try{ httplib::Client cli("localhost", 8080); std::string json_str = j_.dump(4); httplib::Headers header; - auto res = cli.Post("/api/fetchJSONObjectResponse",header,json_str,"text/plain; charset=utf-8"); + auto res = cli.Post(api_url.c_str(),header,json_str,"text/plain; charset=utf-8"); if(res) { LOG(INFO) << "Received HTTP response with status:"<< res->status << endl; @@ -78,15 +78,15 @@ class EncryptedJSONRequest { public: typedef std::chrono::time_point ChronoTimeT; - void start_request(const json& request_json) + void start_request(const json& request_json,const string& api_url) { // this->request_future = this->request_promise.get_future(); // //this->pThread = std::shared_ptr(new std::thread(request_function,std::cref(request_json),std::ref(this->request_promise))); // this->pAsync = std::shared_ptr( new std::async(std::launch::async,request_function,std::cref(request_json))//,std::ref(this->request_promise)) // ); - + this->api_url = api_url; this->t_start = std::chrono::system_clock::now(); - this->request_future = std::async(std::launch::async,request_function,std::cref(request_json)); + this->request_future = std::async(std::launch::async,request_function,std::cref(request_json),std::cref(api_url)); } bool getResponseSafe(EncryptedJSONResponse::Ptr& ptr_output) @@ -115,9 +115,14 @@ class EncryptedJSONRequest } return false; } + std::string getCurrentApiUrl() + { + return this->api_url; + } private: + std::string api_url; std::future request_future; ChronoTimeT t_start; //std::shared_ptr pAsync; @@ -125,7 +130,7 @@ class EncryptedJSONRequest { std::future_status status; status = this->request_future.wait_for(std::chrono::seconds(0)); - if (status == std::future_status::deferred) + if(status == std::future_status::deferred) { return false;//未开始. } @@ -133,7 +138,8 @@ class EncryptedJSONRequest { return false;//尚未结束. } - else if (status == std::future_status::ready) { + else if(status == std::future_status::ready) + { return true; } diff --git a/algorithms/src/SystemManagement/json_request_response_lib/src/JSONSerializableAbstract.h b/algorithms/src/SystemManagement/json_request_response_lib/src/JSONSerializableAbstract.h new file mode 100644 index 00000000..6c8fe8e5 --- /dev/null +++ b/algorithms/src/SystemManagement/json_request_response_lib/src/JSONSerializableAbstract.h @@ -0,0 +1,15 @@ +#ifndef JSON_SERIALIZABLE_ABSTRACT_H +#define JSON_SERIALIZABLE_ABSTRACT_H +#include +#include +#include "third_party/nlohmann_json/single_include/nlohmann/json.hpp" +using json = nlohmann::json; + +class JSONSerializableAbstract{ + +public: + virtual json getJSONObject() = 0; +}; + + +#endif diff --git a/algorithms/src/SystemManagement/json_request_response_lib/src/test_json_client.cpp b/algorithms/src/SystemManagement/json_request_response_lib/src/test_json_client.cpp index 5bdff43e..130aaff3 100644 --- a/algorithms/src/SystemManagement/json_request_response_lib/src/test_json_client.cpp +++ b/algorithms/src/SystemManagement/json_request_response_lib/src/test_json_client.cpp @@ -28,7 +28,7 @@ int main(int argc,char** argv) json j; std::stringstream ss("{\"function\": \"query\"}"); ss>>j; - json_req.start_request(j); + json_req.start_request(j,"/api/ping"); EncryptedJSON::EncryptedJSONResponse::Ptr pRes; while(!json_req.getResponseSafe(pRes)&&!json_req.everTimeout()) { diff --git a/algorithms/src/SystemManagement/json_request_response_lib/src/test_json_server.cpp b/algorithms/src/SystemManagement/json_request_response_lib/src/test_json_server.cpp index 1024467d..0c9e2c94 100644 --- a/algorithms/src/SystemManagement/json_request_response_lib/src/test_json_server.cpp +++ b/algorithms/src/SystemManagement/json_request_response_lib/src/test_json_server.cpp @@ -13,8 +13,8 @@ int start_server() svr.Get("/hi", [](const httplib::Request& req, httplib::Response& res) { res.set_content("Hello World!", "text/plain"); }); - svr.Post("/api/fetchJSONObjectResponse",[](const httplib::Request& req, httplib::Response& res){ - res.set_content("{\"state\":\"correct\"}", "text/plain"); + svr.Post("/api/ping",[](const httplib::Request& req, httplib::Response& res){ + res.set_content("{\"state\":\"correct\",\"data\":\"pong!\" }", "text/plain"); }); cout<<"Server start..."< + +class FlightControllerModule:SurveillanceModuleAbstract +{ + int runPipelineAndGetState(const gaas_msgs::GAASSystemManagementFlightControllerStateConstPtr& pFCState) + //int runPipelineAndGetState(const geometry_msgs::PoseStampedConstPtr& pFCPose) + { + if(!this->ever_init) + { + this->lastFCState = *pFCPose; + this->current_status = this->STATUS_NOT_SURE; + this->ever_init = true; + return this->current_status; + } + //已初始化: + //bool speed_and_angular_rate_correct = checkSpeedAndAngularRate(); + //if(!speed_and_angular_rate_correct) + //{ + // this->current_status = this->STATUS_ERROR; + //} + //else + //{ + // this->current_status = this->STATUS_CORRECT; + //} + return this->current_status; + + } + void initSurveillanceModule() + { + setModuleName("Flight Controller Module"); + } + int checkStateLegal() + { + return this->current_status; + } +private: + bool ever_init = false; + gaas_msgs::GAASSystemManagementFlightControllerState lastFCState; + geometry_msgs::PoseStamped lastPose;//手动计算.... + bool checkSpeedAndAngularRate(const geometry_msgs::PoseStamped& pose1,const geometry_msgs::PoseStamped& pose2); + +}; + + + +#endif