Merge remote-tracking branch 'origin/master'
# Conflicts: # armor/src/armor_finder/anti_top/anti_top.cpp # energy/src/energy/find/energy_finder.cpp
This commit is contained in:
@@ -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;//风车旋转方向
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Created by xixiliadorabarry on 1/24/19.
|
||||
//
|
||||
#include "energy/energy.h"
|
||||
@@ -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<<endl;
|
||||
|
||||
}
|
||||
// showFans("fan", src_bin);
|
||||
if (fans.size() < last_fans_cnt) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
extern mcu_data mcuData;
|
||||
extern McuData mcu_data;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// 此函数通过自瞄逻辑击打目标点,用于大符的自动对心和小符直接打击
|
||||
@@ -29,12 +29,12 @@ void Energy::getAimPoint(cv::Point target_point_) {
|
||||
extra_delta_y = 0;
|
||||
}
|
||||
|
||||
double dx = -(target_point_.x - 320 - COMPENSATE_YAW - mcuData.delta_x - manual_delta_x - extra_delta_x);
|
||||
double dy = -(target_point_.y - 240 - COMPENSATE_PITCH - mcuData.delta_y - manual_delta_y - extra_delta_y);
|
||||
double dx = -(target_point_.x - 320 - COMPENSATE_YAW - mcu_data.delta_x - manual_delta_x - extra_delta_x);
|
||||
double dy = -(target_point_.y - 240 - COMPENSATE_PITCH - mcu_data.delta_y - manual_delta_y - extra_delta_y);
|
||||
yaw_rotation = atan(dx / FOCUS_PIXAL) * 180 / PI;
|
||||
pitch_rotation = atan(dy / FOCUS_PIXAL) * 180 / PI;
|
||||
// cout << "yaw: " << yaw_rotation << '\t' << "pitch: " << pitch_rotation << endl;
|
||||
// cout << "mcuData.delta_x: " << mcuData.delta_x << '\t' << "mcuData.delta_y: " << mcuData.delta_y << endl;
|
||||
// cout << "mcu_data.delta_x: " << mcu_data.delta_x << '\t' << "mcu_data.delta_y: " << mcu_data.delta_y << endl;
|
||||
// cout << "manual delta: " << manual_delta_x << '\t' << manual_delta_y << endl;
|
||||
|
||||
}
|
||||
|
||||
@@ -15,23 +15,23 @@ using std::vector;
|
||||
// 此函数用于操作手手动标定
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
void Energy::changeMark() {
|
||||
if (mcuData.mark == 0 && last_mark == 1) {//完成标定
|
||||
last_mark = mcuData.mark;
|
||||
origin_yaw = mcuData.curr_yaw;
|
||||
origin_pitch = mcuData.curr_pitch;
|
||||
if (mcu_data.mark == 0 && last_mark == 1) {//完成标定
|
||||
last_mark = mcu_data.mark;
|
||||
origin_yaw = mcu_data.curr_yaw;
|
||||
origin_pitch = mcu_data.curr_pitch;
|
||||
is_mark = false;
|
||||
manual_mark = true;
|
||||
// LOGM(STR_CTR(WORD_LIGHT_YELLOW, "IsMark"));
|
||||
} else if (mcuData.mark == 1) {//正在标定
|
||||
last_mark = mcuData.mark;
|
||||
} else if (mcu_data.mark == 1) {//正在标定
|
||||
last_mark = mcu_data.mark;
|
||||
is_mark = true;
|
||||
// LOGM(STR_CTR(WORD_BLUE,"Marking..."));
|
||||
|
||||
} else {//未在标定
|
||||
last_mark = mcuData.mark;
|
||||
last_mark = mcu_data.mark;
|
||||
is_mark = false;
|
||||
}
|
||||
//cout<<"mark: "<<int(mcuData.mark)<<endl;
|
||||
//cout<<"mark: "<<int(mcu_data.mark)<<endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ bool Energy::getOrigin() {
|
||||
if (abs(center_delta_yaw) > 0.3 || abs(center_delta_pitch) > 0.3) {
|
||||
return false;
|
||||
} else {
|
||||
origin_yaw = mcuData.curr_yaw;
|
||||
origin_pitch = mcuData.curr_pitch;
|
||||
origin_yaw = mcu_data.curr_yaw;
|
||||
origin_pitch = mcu_data.curr_pitch;
|
||||
auto_mark = true;
|
||||
LOGM(STR_CTR(WORD_BLUE_CODE, "auto mark success!"));
|
||||
return true;
|
||||
|
||||
@@ -14,7 +14,7 @@ using namespace cv;
|
||||
// 此函数用于判断世界坐标系下是否可以发弹
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
void Energy::judgeShootInWorld() {
|
||||
if (abs(yaw_rotation - mcuData.curr_yaw) < 0.5 && abs(pitch_rotation - mcuData.curr_pitch) < 0.5) {
|
||||
if (abs(yaw_rotation - mcu_data.curr_yaw) < 0.5 && abs(pitch_rotation - mcu_data.curr_pitch) < 0.5) {
|
||||
shoot = 4;
|
||||
// is_predicting = false;
|
||||
// is_guessing = true;
|
||||
|
||||
@@ -12,11 +12,11 @@ using namespace cv;
|
||||
// 此函数用于记录操作手的微调dx和dy
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
void Energy::writeDownSlightChange(cv::Mat &src) {
|
||||
if (findFans(src) >= 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,
|
||||
mcuData.delta_y + manual_delta_y);
|
||||
fprintf(fp_delta, "delta_x: %d, delta_y: %d\n", mcu_data.delta_x + manual_delta_x,
|
||||
mcu_data.delta_y + manual_delta_y);
|
||||
fclose(fp_delta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -19,30 +19,45 @@ void Energy::sendEnergy() {
|
||||
sum_yaw += yaw_rotation;
|
||||
sum_pitch += pitch_rotation;
|
||||
MINMAX(sum_yaw, -100, 100);
|
||||
MINMAX(sum_pitch, -100, 100);\
|
||||
MINMAX(sum_pitch, -100, 100);
|
||||
double tmp_yaw = yaw_rotation;
|
||||
double tmp_pitch = pitch_rotation;
|
||||
yaw_rotation = BIG_YAW_AIM_KP * yaw_rotation + BIG_YAW_AIM_KI * sum_yaw + BIG_YAW_AIM_KD * (yaw_rotation - last_yaw);
|
||||
pitch_rotation = BIG_PITCH_AIM_KP * pitch_rotation + BIG_PITCH_AIM_KI * sum_pitch +
|
||||
BIG_PITCH_AIM_KD * (pitch_rotation - last_pitch);
|
||||
last_yaw = tmp_yaw;
|
||||
last_pitch = tmp_pitch;
|
||||
} else if (is_chassis) {
|
||||
sum_yaw += yaw_rotation - mcuData.curr_yaw;
|
||||
sum_pitch += pitch_rotation - mcuData.curr_pitch;
|
||||
yaw_rotation = BIG_YAW_AIM_KP * (yaw_rotation - mcuData.curr_yaw) + BIG_YAW_AIM_KI * sum_yaw;
|
||||
pitch_rotation = BIG_PITCH_AIM_KP * (pitch_rotation - mcuData.curr_pitch) + BIG_PITCH_AIM_KI * sum_pitch;
|
||||
sum_yaw += yaw_rotation - mcu_data.curr_yaw;
|
||||
sum_pitch += pitch_rotation - mcu_data.curr_pitch;
|
||||
double tmp_yaw = yaw_rotation;
|
||||
double tmp_pitch = pitch_rotation;
|
||||
yaw_rotation = BIG_YAW_AIM_KP * (yaw_rotation - mcu_data.curr_yaw) + BIG_YAW_AIM_KI * sum_yaw;
|
||||
pitch_rotation = BIG_PITCH_AIM_KP * (pitch_rotation - mcu_data.curr_pitch) + BIG_PITCH_AIM_KI * sum_pitch;
|
||||
last_yaw = tmp_yaw;
|
||||
last_pitch = tmp_pitch;
|
||||
}
|
||||
} else if (is_small){
|
||||
sum_yaw += yaw_rotation;
|
||||
sum_pitch += pitch_rotation;
|
||||
MINMAX(sum_yaw, -100, 100);
|
||||
MINMAX(sum_pitch, -100, 100);
|
||||
double tmp_yaw = yaw_rotation;
|
||||
double tmp_pitch = pitch_rotation;
|
||||
yaw_rotation = SMALL_YAW_AIM_KP * yaw_rotation + SMALL_YAW_AIM_KD * (yaw_rotation - last_yaw);
|
||||
pitch_rotation = SMALL_PITCH_AIM_KP * pitch_rotation + SMALL_PITCH_AIM_KD * (pitch_rotation - last_pitch);
|
||||
last_yaw = tmp_yaw;
|
||||
last_pitch = tmp_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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user