energy changed

This commit is contained in:
sun
2019-08-04 14:02:59 +08:00
parent 04c7eea9e0
commit 886109e3cd
8 changed files with 33 additions and 25 deletions

View File

@@ -66,6 +66,7 @@ private:
int send_cnt;//向主控板发送的数据总次数 int send_cnt;//向主控板发送的数据总次数
int camera_cnt;//摄像头数量 int camera_cnt;//摄像头数量
int fans_cnt;//扇叶个数
int last_fans_cnt;//上一帧的扇叶个数 int last_fans_cnt;//上一帧的扇叶个数
int guess_devide;//刚进入猜测状态时,猜测目标点在极坐标中的分区 int guess_devide;//刚进入猜测状态时,猜测目标点在极坐标中的分区
int energy_rotation_direction;//风车旋转方向 int energy_rotation_direction;//风车旋转方向

View File

@@ -30,6 +30,7 @@ void Energy::initEnergy() {
send_cnt = 0; send_cnt = 0;
camera_cnt = 1; camera_cnt = 1;
fans_cnt = 0;
last_fans_cnt = 0; last_fans_cnt = 0;
guess_devide = 0; guess_devide = 0;
energy_rotation_direction = ANTICLOCKWISE; energy_rotation_direction = ANTICLOCKWISE;
@@ -86,15 +87,15 @@ void Energy::initEnergyPartParam() {
gimbal_energy_part_param_.FAN_GRAY_THRESH = 75; gimbal_energy_part_param_.FAN_GRAY_THRESH = 75;
gimbal_energy_part_param_.ARMOR_GRAY_THRESH = 80; gimbal_energy_part_param_.ARMOR_GRAY_THRESH = 80;
gimbal_energy_part_param_.FAN_CONTOUR_AREA_MAX = 6600; gimbal_energy_part_param_.FAN_CONTOUR_AREA_MAX = 3000;
gimbal_energy_part_param_.FAN_CONTOUR_AREA_MIN = 0; gimbal_energy_part_param_.FAN_CONTOUR_AREA_MIN = 500;
gimbal_energy_part_param_.FAN_CONTOUR_LENGTH_MIN = 80; gimbal_energy_part_param_.FAN_CONTOUR_LENGTH_MIN = 55;
gimbal_energy_part_param_.FAN_CONTOUR_LENGTH_MAX = 100; 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_MIN = 20;
gimbal_energy_part_param_.FAN_CONTOUR_WIDTH_MAX = 52; 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_MAX = 3.5;
gimbal_energy_part_param_.FAN_CONTOUR_HW_RATIO_MIN = 1; gimbal_energy_part_param_.FAN_CONTOUR_HW_RATIO_MIN = 1.2;
gimbal_energy_part_param_.FAN_CONTOUR_AREA_RATIO_MIN = 0.65; 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_MAX = 0.8;
gimbal_energy_part_param_.FAN_NON_ZERO_RATE_MIN = 0.48; gimbal_energy_part_param_.FAN_NON_ZERO_RATE_MIN = 0.48;
// gimbal_energy_part_param_.FAN_NON_ZERO_RATE_MAX = 0.3; // gimbal_energy_part_param_.FAN_NON_ZERO_RATE_MAX = 0.3;

View File

@@ -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 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; // float width = cur_size.height < cur_size.width ? cur_size.height : cur_size.width;
// double cur_contour_area = contourArea(fan_contour); // double cur_contour_area = contourArea(fan_contour);
// double non_zero_rate = nonZeroRateOfRotateRect(src_bin, cur_rect); // float length_width_ratio = length / width;
// if (length > 60 && width > 20) { // cout << "area: " << cur_contour_area << '\t' << endl;
// fans.emplace_back(cv::minAreaRect(fan_contour)); // cout << "length: " << length << '\t' << "width: " << width << '\t' << cur_rect.center << endl;
// cout << cur_rect.center << endl; // cout << "HW: " << length_width_ratio << '\t' << cur_rect.center << endl;
// cout << "fan area: " << length << '\t' << width << endl; // cout << "area ratio: " << cur_contour_area / cur_size.area() << '\t' << cur_rect.center << endl;
// cout << "non zero: " << nonZeroRateOfRotateRect(src_bin, cur_rect) << endl; // cout<<endl;
// cout << "rate: " << cur_contour_area / cur_size.area() << endl;
// }
} }
// showFans("fan", src_bin); // showFans("fan", src_bin);
if (fans.size() < last_fans_cnt) { if (fans.size() < last_fans_cnt) {

View File

@@ -12,7 +12,7 @@ using namespace cv;
// 此函数用于记录操作手的微调dx和dy // 此函数用于记录操作手的微调dx和dy
// --------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------------
void Energy::writeDownSlightChange(cv::Mat &src) { void Energy::writeDownSlightChange(cv::Mat &src) {
if (findFans(src) >= 4) { if (fans_cnt >= 4) {
FILE *fp_delta = fopen(PROJECT_DIR"/Mark/delta.txt", "w"); FILE *fp_delta = fopen(PROJECT_DIR"/Mark/delta.txt", "w");
if (fp_delta) { if (fp_delta) {
fprintf(fp_delta, "delta_x: %d, delta_y: %d\n", mcuData.delta_x + manual_delta_x, fprintf(fp_delta, "delta_x: %d, delta_y: %d\n", mcuData.delta_x + manual_delta_x,

View File

@@ -89,6 +89,8 @@ void Energy::runBig(cv::Mat &gimbal_src) {
if (show_energy)showFlowStrip("strip", gimbal_src); if (show_energy)showFlowStrip("strip", gimbal_src);
if (!findCenterR(gimbal_src))return; if (!findCenterR(gimbal_src))return;
if (show_energy)showCenterR("R", gimbal_src); if (show_energy)showCenterR("R", gimbal_src);
fans_cnt = findFans(gimbal_src);
if (show_energy)showFans("fans", gimbal_src);
// getCenter(); // getCenter();
// sendEnergy(); // sendEnergy();
@@ -127,7 +129,9 @@ void Energy::runSmall(cv::Mat &gimbal_src) {
if (!findTargetInFlowStripFan()) return; if (!findTargetInFlowStripFan()) return;
if (!findFlowStrip(gimbal_src))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(); // getCenter();
// sendEnergy(); // sendEnergy();

View File

@@ -38,11 +38,14 @@ void Energy::sendEnergy() {
pitch_rotation = SMALL_PITCH_AIM_KP * pitch_rotation + SMALL_PITCH_AIM_KD * (pitch_rotation - last_pitch); pitch_rotation = SMALL_PITCH_AIM_KP * pitch_rotation + SMALL_PITCH_AIM_KD * (pitch_rotation - last_pitch);
} }
if (change_target) { if (change_target) {
sendTarget(serial, yaw_rotation, pitch_rotation, 5, 0); sendTarget(serial, yaw_rotation, pitch_rotation, 5, 0);
} else if (is_guessing) { } else if (is_guessing) {
sendTarget(serial, yaw_rotation, pitch_rotation, 6, 0); 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); sendTarget(serial, yaw_rotation, pitch_rotation, shoot, 0);
} }

View File

@@ -30,7 +30,7 @@ using namespace std;
mcu_data mcuData = { // 单片机端回传结构体 mcu_data mcuData = { // 单片机端回传结构体
0, // 当前云台yaw角 0, // 当前云台yaw角
0, // 当前云台pitch角 0, // 当前云台pitch角
SMALL_ENERGY_STATE, // 当前状态,自瞄-大符-小符 BIG_ENERGY_STATE, // 当前状态,自瞄-大符-小符
0, // 云台角度标记位 0, // 云台角度标记位
1, // 是否启用数字识别 1, // 是否启用数字识别
ENEMY_RED, // 敌方颜色 ENEMY_RED, // 敌方颜色
@@ -66,8 +66,8 @@ int main(int argc, char *argv[]) {
video_gimbal = new CameraWrapper(ARMOR_CAMERA_GAIN, 2/*, "armor"*/); video_gimbal = new CameraWrapper(ARMOR_CAMERA_GAIN, 2/*, "armor"*/);
video_chassis = new CameraWrapper(ENERGY_CAMERA_GAIN, 2/*, "energy"*/); video_chassis = new CameraWrapper(ENERGY_CAMERA_GAIN, 2/*, "energy"*/);
} else { } else {
video_gimbal = 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/18.avi"); video_chassis = new VideoWrapper("/home/sun/项目/energy_video/new/79.avi");
} }
if (video_gimbal->init()) { if (video_gimbal->init()) {
LOGM("video_gimbal source initialization successfully."); LOGM("video_gimbal source initialization successfully.");

View File

@@ -44,19 +44,19 @@
#define SMALL_PITCH_AIM_KP (2.4) #define SMALL_PITCH_AIM_KP (2.4)
#endif #endif
#ifndef BIG_YAW_AIM_KD #ifndef BIG_YAW_AIM_KD
#define BIG_YAW_AIM_KD (0.7) #define BIG_YAW_AIM_KD (1)
#endif #endif
#ifndef BIG_YAW_AIM_KP #ifndef BIG_YAW_AIM_KP
#define BIG_YAW_AIM_KP (4.5) #define BIG_YAW_AIM_KP (5.5)
#endif #endif
#ifndef BIG_YAW_AIM_KI #ifndef BIG_YAW_AIM_KI
#define BIG_YAW_AIM_KI (0.1) #define BIG_YAW_AIM_KI (0.1)
#endif #endif
#ifndef BIG_PITCH_AIM_KD #ifndef BIG_PITCH_AIM_KD
#define BIG_PITCH_AIM_KD (0.7) #define BIG_PITCH_AIM_KD (1)
#endif #endif
#ifndef BIG_PITCH_AIM_KP #ifndef BIG_PITCH_AIM_KP
#define BIG_PITCH_AIM_KP (4.5) #define BIG_PITCH_AIM_KP (5.5)
#endif #endif
#ifndef BIG_PITCH_AIM_KI #ifndef BIG_PITCH_AIM_KI
#define BIG_PITCH_AIM_KI (0.1) #define BIG_PITCH_AIM_KI (0.1)