diff --git a/armor/include/armor_finder/armor_finder.h b/armor/include/armor_finder/armor_finder.h index c13a60e..9a02838 100644 --- a/armor/include/armor_finder/armor_finder.h +++ b/armor/include/armor_finder/armor_finder.h @@ -6,13 +6,13 @@ #define _ARMOR_FINDER_H_ #include -#include +#include #include #include #include -#include +#include #include -#include +#include #define BLOB_RED ENEMY_RED #define BLOB_BLUE ENEMY_BLUE @@ -111,7 +111,7 @@ private: INCREASE, DECREASE, NOCHANGE } BoxRatioChangeType; - timeval frame_time; // 当前帧对应时间; + systime frame_time; // 当前帧对应时间; const uint8_t &enemy_color; // 敌方颜色,引用外部变量,自动变化 State state; // 自瞄状态对象实例 ArmorBox armor_box; // 当前目标装甲板 @@ -123,7 +123,7 @@ private: const uint8_t &use_classifier; // 标记是否启用CNN分类器,引用外部变量,自动变化 RoundQueue top_periodms; RoundQueue box_ratioes; - timeval last_front_time; // 上一次发生装甲板方向切换的时间 + systime last_front_time; // 上一次发生装甲板方向切换的时间 BoxRatioChangeType last_ratio_type; int anti_top_cnt; // 满足条件的装甲板方向切换持续次数,用于反陀螺 AntiTopState anti_top_state; // 当前是否识别到陀螺 diff --git a/armor/src/armor_finder/anti_top/anti_top.cpp b/armor/src/armor_finder/anti_top/anti_top.cpp index fac5fbe..ea12515 100644 --- a/armor/src/armor_finder/anti_top/anti_top.cpp +++ b/armor/src/armor_finder/anti_top/anti_top.cpp @@ -3,7 +3,7 @@ // #include -#include +#include #include static double boxDistance(const cv::Rect2d &a, const cv::Rect2d &b) { @@ -53,8 +53,8 @@ void ArmorFinder::antiTop() { if (anti_top_state == ANTI_TOP) { top_periodms.push(interval); LOGM(STR_CTR(WORD_LIGHT_GREEN, "top period: %.1lf ms"), interval); - timeval curr_time; - gettimeofday(&curr_time, nullptr); + systime curr_time; + getsystime(curr_time); auto calculate_time = getTimeIntervalms(curr_time, frame_time); shoot_delay = mean(top_periodms) - calculate_time; } else if (anti_top_state == NORMAL) { diff --git a/armor/src/armor_finder/armor_finder.cpp b/armor/src/armor_finder/armor_finder.cpp index d9a45d0..2b90d35 100644 --- a/armor/src/armor_finder/armor_finder.cpp +++ b/armor/src/armor_finder/armor_finder.cpp @@ -17,11 +17,10 @@ #define LOG_LEVEL LOG_NONE #include -#include +#include #include #include #include -#include std::map id2name = { //装甲板id到名称的map {-1, "OO"},{ 0, "NO"}, @@ -58,7 +57,7 @@ ArmorFinder::ArmorFinder(uint8_t &color, Serial &u, const string ¶s_folder, } void ArmorFinder::run(cv::Mat &src) { - gettimeofday(&frame_time, nullptr); + getsystime(frame_time); // stateSearchingTarget(src); // for debug // goto end; switch (state) { diff --git a/armor/src/armor_finder/find/find_armor_box.cpp b/armor/src/armor_finder/find/find_armor_box.cpp index 039ba3f..1e9f1ae 100644 --- a/armor/src/armor_finder/find/find_armor_box.cpp +++ b/armor/src/armor_finder/find/find_armor_box.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #define DO_NOT_CNT_TIME #include diff --git a/armor/src/armor_finder/find/find_light_blobs.cpp b/armor/src/armor_finder/find/find_light_blobs.cpp index ba7326a..71937cc 100644 --- a/armor/src/armor_finder/find/find_light_blobs.cpp +++ b/armor/src/armor_finder/find/find_light_blobs.cpp @@ -3,7 +3,7 @@ // #include -#include +#include #include static double lw_rate(const cv::RotatedRect &rect) { diff --git a/armor/src/armor_finder/searching_state/searching_state.cpp b/armor/src/armor_finder/searching_state/searching_state.cpp index 2920293..5049093 100644 --- a/armor/src/armor_finder/searching_state/searching_state.cpp +++ b/armor/src/armor_finder/searching_state/searching_state.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include bool ArmorFinder::stateSearchingTarget(cv::Mat &src) { diff --git a/armor/src/armor_finder/tracking_state/tracking_state.cpp b/armor/src/armor_finder/tracking_state/tracking_state.cpp index 3fb0d93..9a05d6b 100644 --- a/armor/src/armor_finder/tracking_state/tracking_state.cpp +++ b/armor/src/armor_finder/tracking_state/tracking_state.cpp @@ -2,7 +2,7 @@ // Created by xinyang on 19-3-27. // #include -#include +#include #include #include diff --git a/armor/src/show_images/show_images.cpp b/armor/src/show_images/show_images.cpp index c92d9b8..039c0ec 100644 --- a/armor/src/show_images/show_images.cpp +++ b/armor/src/show_images/show_images.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include using namespace cv; diff --git a/energy/include/energy/constant.h b/energy/include/energy/constant.h index bdb82cf..27a6807 100644 --- a/energy/include/energy/constant.h +++ b/energy/include/energy/constant.h @@ -1,20 +1,20 @@ -// -// Created by xixiliadorabarry on 1/24/19. -// -#ifndef CONSTANT_H -#define CONSTANT_H - -#include "additions/additions.h" -const int BIG = 1; -const int SMALL = 0; -const int SRC_WIDTH = 320; -const int SRC_HEIGHT = 240; -const int CLOCKWISE = 1; -const int ANTICLOCKWISE = -1; -//const float ATTACK_DISTANCE = 718.0;//cm -const float ATTACK_DISTANCE = 750.0;//cm -const double ARMOR_CENTER_TO_CYCLE_CENTER = 75.0;//cm - - -#endif //CONSTANT_H - +// +// Created by xixiliadorabarry on 1/24/19. +// +#ifndef CONSTANT_H +#define CONSTANT_H + +#include "additions.h" +const int BIG = 1; +const int SMALL = 0; +const int SRC_WIDTH = 320; +const int SRC_HEIGHT = 240; +const int CLOCKWISE = 1; +const int ANTICLOCKWISE = -1; +//const float ATTACK_DISTANCE = 718.0;//cm +const float ATTACK_DISTANCE = 750.0;//cm +const double ARMOR_CENTER_TO_CYCLE_CENTER = 75.0;//cm + + +#endif //CONSTANT_H + diff --git a/energy/include/energy/energy.h b/energy/include/energy/energy.h index a26afc6..a9e25f0 100644 --- a/energy/include/energy/energy.h +++ b/energy/include/energy/energy.h @@ -13,12 +13,12 @@ #include #include #include -#include +#include #include "energy/constant.h" #include "energy/param_struct_define.h" -#include "serial/serial.h" -#include "additions/additions.h" -#include "options/options.h" +#include "serial.h" +#include "additions.h" +#include "options.h" using std::vector; @@ -87,7 +87,7 @@ private: float shoot;//若为2,则要求主控板发弹 float sum_yaw, sum_pitch;//yaw和pitch的累计误差,即PID中积分项 - timeval time_start_guess; + systime time_start_guess; cv::RotatedRect centerR;//风车中心字母R的可能候选区 cv::RotatedRect flow_strip;//图像中所有流动条(理论上只有一个) diff --git a/energy/src/energy/judge/judge_shoot.cpp b/energy/src/energy/judge/judge_shoot.cpp index cbc2660..d9b9aa3 100644 --- a/energy/src/energy/judge/judge_shoot.cpp +++ b/energy/src/energy/judge/judge_shoot.cpp @@ -19,7 +19,7 @@ void Energy::judgeShootInWorld() { // is_predicting = false; // is_guessing = true; // start_guess = true; -// gettimeofday(&time_start_guess, NULL); +// getsystime(time_start_guess); LOGM(STR_CTR(WORD_LIGHT_RED, "Start Guessing!")); } else shoot = 2; @@ -35,7 +35,7 @@ void Energy::judgeShootInGimbal() { // is_predicting = false; // is_guessing = true; // start_guess = true; -// gettimeofday(&time_start_guess, NULL); +// getsystime(time_start_guess); // LOGM(STR_CTR(WORD_LIGHT_RED, "Start Guessing!")); } else shoot = 2; diff --git a/energy/src/energy/judge/judge_time.cpp b/energy/src/energy/judge/judge_time.cpp index 2fde1ce..78fd9c1 100644 --- a/energy/src/energy/judge/judge_time.cpp +++ b/energy/src/energy/judge/judge_time.cpp @@ -14,8 +14,7 @@ using namespace cv; // 此函数用于判断guess模式是否超时 // --------------------------------------------------------------------------------------------------------------------- bool Energy::isGuessingTimeout() { - timeval cur_time; - gettimeofday(&cur_time, NULL); - return (cur_time.tv_sec - time_start_guess.tv_sec) * 1000.0 + - (cur_time.tv_usec - time_start_guess.tv_usec) / 1000.0 > 1000; + systime cur_time; + getsystime(cur_time); + return getTimeIntervalms(cur_time, time_start_guess) > 1000; }; \ No newline at end of file diff --git a/energy/src/energy/run.cpp b/energy/src/energy/run.cpp index 549d29b..85a90c6 100644 --- a/energy/src/energy/run.cpp +++ b/energy/src/energy/run.cpp @@ -4,8 +4,7 @@ #include "energy/energy.h" #include "log.h" #include "config/setconfig.h" -#include "options/options.h" -#include +#include "options.h" using namespace std; using namespace cv; diff --git a/main.cpp b/main.cpp index e0a6565..7aea291 100644 --- a/main.cpp +++ b/main.cpp @@ -10,14 +10,14 @@ #include #include #include -#include +#include #include #include #include #include #include -#include -#include +#include +#include #include #define DO_NOT_CNT_TIME diff --git a/others/include/additions/additions.h b/others/include/additions.h similarity index 93% rename from others/include/additions/additions.h rename to others/include/additions.h index 787cb6f..f51fdac 100644 --- a/others/include/additions/additions.h +++ b/others/include/additions.h @@ -6,8 +6,8 @@ #define _ADDITIONS_H_ #include -#include -#include +#include +#include #include struct mcu_data { @@ -41,7 +41,7 @@ void extract(cv::Mat &gimbal_src, cv::Mat &chassis_src); void extract(cv::Mat &gimbal_src); -double getTimeIntervalms(const timeval &now, const timeval &last); +float getTimeIntervalms(const systime &now, const systime &last); template class RoundQueue { diff --git a/others/include/camera/camera_wrapper.h b/others/include/camera/camera_wrapper.h index 2506a08..a9bed24 100644 --- a/others/include/camera/camera_wrapper.h +++ b/others/include/camera/camera_wrapper.h @@ -7,7 +7,7 @@ #ifndef VIDEO_TEST1_CAMERA_WRAPPER_H #define VIDEO_TEST1_CAMERA_WRAPPER_H -#include +#include #include #include diff --git a/others/include/options/options.h b/others/include/options.h similarity index 100% rename from others/include/options/options.h rename to others/include/options.h diff --git a/others/include/serial/serial.h b/others/include/serial.h similarity index 100% rename from others/include/serial/serial.h rename to others/include/serial.h diff --git a/others/include/systime.h b/others/include/systime.h new file mode 100644 index 0000000..195f0b1 --- /dev/null +++ b/others/include/systime.h @@ -0,0 +1,23 @@ +// +// Created by xinyang on 19-7-31. +// + +#ifndef _PLATFORM_H_ +#define _PLATFORM_H_ + +typedef struct{ + int second; + int millisecond; +} systime; + +void getsystime(systime &t); + +#if defined(Linux) + #include +#elif defined(Windows) + #include +#else + #error "nonsupport platform." +#endif + +#endif /* _PLATFORM_H_ */ diff --git a/others/src/additions/additions.cpp b/others/src/additions.cpp similarity index 96% rename from others/src/additions/additions.cpp rename to others/src/additions.cpp index d6dabc7..ea030c6 100644 --- a/others/src/additions/additions.cpp +++ b/others/src/additions.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -170,6 +170,6 @@ void extract(cv::Mat &gimbal_src) {//图像预处理,将视频切成640×480 } } -double getTimeIntervalms(const timeval& now, const timeval &last){ - return (now.tv_sec-last.tv_sec)*1000.0 + (now.tv_usec-last.tv_usec)/1000.0; +float getTimeIntervalms(const systime &now, const systime &last){ + return (now.second-last.second)*1000.0 + (now.millisecond-last.millisecond); } diff --git a/others/src/camera/camera_wrapper.cpp b/others/src/camera/camera_wrapper.cpp index 99809d5..963586d 100644 --- a/others/src/camera/camera_wrapper.cpp +++ b/others/src/camera/camera_wrapper.cpp @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include using namespace std; @@ -86,35 +86,7 @@ bool CameraWrapper::init() { CameraLoadParameter(h_camera, PARAMETER_TEAM_A); CameraSetAeState(h_camera, false); CameraSetExposureTime(h_camera, CAMERA_EXPOSURE * 1000); -#ifndef WITH_TIME_BASED_CAMERA_GAIN CameraSetAnalogGain(h_camera, gain); -#else - -#include - - timeval tv; - int gain; - gettimeofday(&tv, nullptr); - float hour = (tv.tv_sec % (3600 * 24)) / 3600.0; - if (6 <= hour && hour < 10) { - gain = 20; - LOGM("Set gain to morning 20"); - } else if (10 <= hour && hour < 16) { - gain = 10; - LOGM("Set gain to day 10"); - } else if (16 <= hour && hour < 17) { - gain = 20; - LOGM("Set gain to early evening 20"); - } else if (17 <= hour && hour < 18) { - gain = 40; - LOGM("Set gain to evening 40"); - } else { - gain = 50; - LOGM("Set gain to early night 50"); - } - CameraSetAnalogGain(h_camera, gain); -#endif - #endif double t; int g; @@ -204,10 +176,10 @@ bool CameraWrapper::readProcessed(cv::Mat &src) { } bool CameraWrapper::readCallback(cv::Mat &src) { - timeval ts, te; - gettimeofday(&ts, NULL); + systime ts, te; + getsystime(ts); while(src_queue.empty()){ - gettimeofday(&te, NULL); + getsystime(te); if(getTimeIntervalms(te, ts) > 500){ return false; } diff --git a/others/src/options/options.cpp b/others/src/options.cpp similarity index 99% rename from others/src/options/options.cpp rename to others/src/options.cpp index ab2542c..d5a98b5 100644 --- a/others/src/options/options.cpp +++ b/others/src/options.cpp @@ -2,7 +2,7 @@ // Created by xinyang on 19-3-27. // -#include +#include #include #include diff --git a/others/src/serial/serial.cpp b/others/src/serial.cpp similarity index 99% rename from others/src/serial/serial.cpp rename to others/src/serial.cpp index 46b9ff6..6abfc75 100644 --- a/others/src/serial/serial.cpp +++ b/others/src/serial.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include //#define LOG_LEVEL LOG_NONE