diff --git a/energy/include/energy/energy.h b/energy/include/energy/energy.h index 14f27cb..867a12c 100644 --- a/energy/include/energy/energy.h +++ b/energy/include/energy/energy.h @@ -66,6 +66,7 @@ private: int send_cnt;//向主控板发送的数据总次数 int camera_cnt;//摄像头数量 + int fans_cnt;//扇叶个数 int last_fans_cnt;//上一帧的扇叶个数 int guess_devide;//刚进入猜测状态时,猜测目标点在极坐标中的分区 int energy_rotation_direction;//风车旋转方向 diff --git a/energy/src/energy/clear/energy_init.cpp b/energy/src/energy/clear/energy_init.cpp index aaa6327..80caba9 100644 --- a/energy/src/energy/clear/energy_init.cpp +++ b/energy/src/energy/clear/energy_init.cpp @@ -30,6 +30,7 @@ void Energy::initEnergy() { send_cnt = 0; camera_cnt = 1; + fans_cnt = 0; last_fans_cnt = 0; guess_devide = 0; energy_rotation_direction = ANTICLOCKWISE; @@ -86,15 +87,15 @@ void Energy::initEnergyPartParam() { gimbal_energy_part_param_.FAN_GRAY_THRESH = 75; gimbal_energy_part_param_.ARMOR_GRAY_THRESH = 80; - gimbal_energy_part_param_.FAN_CONTOUR_AREA_MAX = 6600; - gimbal_energy_part_param_.FAN_CONTOUR_AREA_MIN = 0; - gimbal_energy_part_param_.FAN_CONTOUR_LENGTH_MIN = 80; - gimbal_energy_part_param_.FAN_CONTOUR_LENGTH_MAX = 100; + gimbal_energy_part_param_.FAN_CONTOUR_AREA_MAX = 3000; + gimbal_energy_part_param_.FAN_CONTOUR_AREA_MIN = 500; + gimbal_energy_part_param_.FAN_CONTOUR_LENGTH_MIN = 55; + gimbal_energy_part_param_.FAN_CONTOUR_LENGTH_MAX = 95; gimbal_energy_part_param_.FAN_CONTOUR_WIDTH_MIN = 20; gimbal_energy_part_param_.FAN_CONTOUR_WIDTH_MAX = 52; - gimbal_energy_part_param_.FAN_CONTOUR_HW_RATIO_MAX = 4; - gimbal_energy_part_param_.FAN_CONTOUR_HW_RATIO_MIN = 1; - gimbal_energy_part_param_.FAN_CONTOUR_AREA_RATIO_MIN = 0.65; + gimbal_energy_part_param_.FAN_CONTOUR_HW_RATIO_MAX = 3.5; + gimbal_energy_part_param_.FAN_CONTOUR_HW_RATIO_MIN = 1.2; + gimbal_energy_part_param_.FAN_CONTOUR_AREA_RATIO_MIN = 0.6; gimbal_energy_part_param_.FAN_NON_ZERO_RATE_MAX = 0.8; gimbal_energy_part_param_.FAN_NON_ZERO_RATE_MIN = 0.48; // gimbal_energy_part_param_.FAN_NON_ZERO_RATE_MAX = 0.3; diff --git a/energy/src/energy/find/energy_finder.cpp b/energy/src/energy/find/energy_finder.cpp index c81a34f..9827d7c 100644 --- a/energy/src/energy/find/energy_finder.cpp +++ b/energy/src/energy/find/energy_finder.cpp @@ -39,14 +39,13 @@ int Energy::findFans(const cv::Mat src) { // float length = cur_size.height > cur_size.width ? cur_size.height : cur_size.width; // float width = cur_size.height < cur_size.width ? cur_size.height : cur_size.width; // double cur_contour_area = contourArea(fan_contour); -// double non_zero_rate = nonZeroRateOfRotateRect(src_bin, cur_rect); -// if (length > 60 && width > 20) { -// fans.emplace_back(cv::minAreaRect(fan_contour)); -// cout << cur_rect.center << endl; -// cout << "fan area: " << length << '\t' << width << endl; -// cout << "non zero: " << nonZeroRateOfRotateRect(src_bin, cur_rect) << endl; -// cout << "rate: " << cur_contour_area / cur_size.area() << endl; -// } +// float length_width_ratio = length / width; +// cout << "area: " << cur_contour_area << '\t' << endl; +// cout << "length: " << length << '\t' << "width: " << width << '\t' << cur_rect.center << endl; +// cout << "HW: " << length_width_ratio << '\t' << cur_rect.center << endl; +// cout << "area ratio: " << cur_contour_area / cur_size.area() << '\t' << cur_rect.center << endl; +// cout<= 4) { + if (fans_cnt >= 4) { FILE *fp_delta = fopen(PROJECT_DIR"/Mark/delta.txt", "w"); if (fp_delta) { fprintf(fp_delta, "delta_x: %d, delta_y: %d\n", mcuData.delta_x + manual_delta_x, diff --git a/energy/src/energy/run.cpp b/energy/src/energy/run.cpp index 0eaa6e2..9cf3006 100644 --- a/energy/src/energy/run.cpp +++ b/energy/src/energy/run.cpp @@ -89,6 +89,8 @@ void Energy::runBig(cv::Mat &gimbal_src) { if (show_energy)showFlowStrip("strip", gimbal_src); if (!findCenterR(gimbal_src))return; if (show_energy)showCenterR("R", gimbal_src); + fans_cnt = findFans(gimbal_src); + if (show_energy)showFans("fans", gimbal_src); // getCenter(); // sendEnergy(); @@ -127,7 +129,9 @@ void Energy::runSmall(cv::Mat &gimbal_src) { if (!findTargetInFlowStripFan()) return; if (!findFlowStrip(gimbal_src))return; } - if(show_energy)showTarget("target", gimbal_src); + if (show_energy)showTarget("target", gimbal_src); + fans_cnt = findFans(gimbal_src); + if (show_energy)showFans("fans", gimbal_src); // getCenter(); // sendEnergy(); diff --git a/energy/src/energy/send/send.cpp b/energy/src/energy/send/send.cpp index 36d0476..c140ae8 100644 --- a/energy/src/energy/send/send.cpp +++ b/energy/src/energy/send/send.cpp @@ -38,11 +38,14 @@ void Energy::sendEnergy() { pitch_rotation = SMALL_PITCH_AIM_KP * pitch_rotation + SMALL_PITCH_AIM_KD * (pitch_rotation - last_pitch); } + if (change_target) { sendTarget(serial, yaw_rotation, pitch_rotation, 5, 0); } else if (is_guessing) { sendTarget(serial, yaw_rotation, pitch_rotation, 6, 0); - } else { + } /*else if (fans_cnt >= 4) { + sendTarget(serial, yaw_rotation, pitch_rotation, 7, 0); + }*/ else { sendTarget(serial, yaw_rotation, pitch_rotation, shoot, 0); } diff --git a/main.cpp b/main.cpp index 590ead8..0826b70 100644 --- a/main.cpp +++ b/main.cpp @@ -30,7 +30,7 @@ using namespace std; mcu_data mcuData = { // 单片机端回传结构体 0, // 当前云台yaw角 0, // 当前云台pitch角 - SMALL_ENERGY_STATE, // 当前状态,自瞄-大符-小符 + BIG_ENERGY_STATE, // 当前状态,自瞄-大符-小符 0, // 云台角度标记位 1, // 是否启用数字识别 ENEMY_RED, // 敌方颜色 @@ -66,8 +66,8 @@ int main(int argc, char *argv[]) { video_gimbal = new CameraWrapper(ARMOR_CAMERA_GAIN, 2/*, "armor"*/); video_chassis = new CameraWrapper(ENERGY_CAMERA_GAIN, 2/*, "energy"*/); } else { - video_gimbal = new VideoWrapper("/home/sun/项目/energy_video/new/18.avi"); - video_chassis = new VideoWrapper("/home/sun/项目/energy_video/new/18.avi"); + video_gimbal = new VideoWrapper("/home/sun/项目/energy_video/new/79.avi"); + video_chassis = new VideoWrapper("/home/sun/项目/energy_video/new/79.avi"); } if (video_gimbal->init()) { LOGM("video_gimbal source initialization successfully."); diff --git a/others/include/config/setconfig.h b/others/include/config/setconfig.h index f831bbd..7a7c34e 100644 --- a/others/include/config/setconfig.h +++ b/others/include/config/setconfig.h @@ -44,19 +44,19 @@ #define SMALL_PITCH_AIM_KP (2.4) #endif #ifndef BIG_YAW_AIM_KD - #define BIG_YAW_AIM_KD (0.7) + #define BIG_YAW_AIM_KD (1) #endif #ifndef BIG_YAW_AIM_KP - #define BIG_YAW_AIM_KP (4.5) + #define BIG_YAW_AIM_KP (5.5) #endif #ifndef BIG_YAW_AIM_KI #define BIG_YAW_AIM_KI (0.1) #endif #ifndef BIG_PITCH_AIM_KD - #define BIG_PITCH_AIM_KD (0.7) + #define BIG_PITCH_AIM_KD (1) #endif #ifndef BIG_PITCH_AIM_KP - #define BIG_PITCH_AIM_KP (4.5) + #define BIG_PITCH_AIM_KP (5.5) #endif #ifndef BIG_PITCH_AIM_KI #define BIG_PITCH_AIM_KI (0.1)