energy change
This commit is contained in:
@@ -23,8 +23,8 @@ void Energy::clearAll(){
|
||||
// 此函数用于图像预处理
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
void Energy::initImage(cv::Mat &src){
|
||||
imagePreprocess(src);
|
||||
if(show_process)imshow("img_preprocess", src);
|
||||
// imagePreprocess(src);
|
||||
// if(show_process)imshow("img_preprocess", src);
|
||||
if (src.type() == CV_8UC3)cvtColor(src, src, COLOR_BGR2GRAY);
|
||||
threshold(src, src, energy_part_param_.GRAY_THRESH, 255, THRESH_BINARY);
|
||||
if (show_process)imshow("bin", src);
|
||||
|
||||
@@ -125,15 +125,15 @@ void Energy::initEnergyPartParam() {
|
||||
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_MAX = 100000;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_MIN = 0;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MIN = 40;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MAX = 65;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MIN = 8;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MAX = 20;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MIN = 45;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MAX = 70;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MIN = 12;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MAX = 24;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MAX = 12;
|
||||
// gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MIN = 4;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MIN = 2.7;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_RATIO_MIN = 0.5;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_INTERSETION_AREA_MIN = 117;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_HW_RATIO_MIN = 2.5;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_AREA_RATIO_MIN = 0.6;
|
||||
gimbal_energy_part_param_.FLOW_STRIP_CONTOUR_INTERSETION_AREA_MIN = 100;
|
||||
|
||||
gimbal_energy_part_param_.TWIN_ANGEL_MAX = 10;
|
||||
gimbal_energy_part_param_.TARGET_INTERSETION_CONTOUR_AREA_MIN = 40;
|
||||
@@ -229,11 +229,11 @@ void Energy::initRotation() {
|
||||
else if (target_polar_angle > last_target_polar_angle) anticlockwise_rotation_init_cnt++;
|
||||
}
|
||||
//由于刚开始圆心判断不准,角度变化可能计算有误,因此需要在角度正向或逆向变化足够大时才可确定是否为顺逆时针
|
||||
if (clockwise_rotation_init_cnt == 30) {
|
||||
if (clockwise_rotation_init_cnt == 15) {
|
||||
energy_rotation_direction = CLOCKWISE;//顺时针变化30次,确定为顺时针
|
||||
cout << "rotation: " << energy_rotation_direction << endl;
|
||||
energy_rotation_init = false;
|
||||
} else if (anticlockwise_rotation_init_cnt == 30) {
|
||||
} else if (anticlockwise_rotation_init_cnt == 15) {
|
||||
energy_rotation_direction = ANTICLOCKWISE;//逆时针变化30次,确定为顺时针
|
||||
cout << "rotation: " << energy_rotation_direction << endl;
|
||||
energy_rotation_init = false;
|
||||
|
||||
@@ -228,7 +228,7 @@ bool Energy::findFlowStrip(const cv::Mat src) {
|
||||
// Size2f cur_size = cur_rect.size;
|
||||
// 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;
|
||||
// if (length / width > 4 && width > 7 && width<30) {
|
||||
// if (length / width > 2.5 && width > 7 && width<40) {
|
||||
// cout << cur_rect.center << endl;
|
||||
// flow_strip = cv::minAreaRect(flow_strip_contour);
|
||||
// cout << "flow strip area: " << length << '\t' << width << endl;
|
||||
@@ -252,7 +252,7 @@ bool Energy::findCenterROI(const cv::Mat src) {
|
||||
vector<Point2f> mask_rect;
|
||||
target_armor.points(vertices); //计算矩形的4个顶点
|
||||
for (int i = 0; i < 4; i++)
|
||||
line(src_mask, vertices[i], vertices[(i + 1) % 4], Scalar(0, 0, 0), 15);
|
||||
line(src_mask, vertices[i], vertices[(i + 1) % 4], Scalar(0, 0, 0), 20);
|
||||
// imshow("fill", src_mask);
|
||||
if (!findFlowStrip(src_mask))return false;
|
||||
float length = target_armor.size.height > target_armor.size.width ?
|
||||
|
||||
@@ -13,8 +13,8 @@ using namespace cv;
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
void Energy::getAimPoint(cv::Point target_point) {
|
||||
//五号车
|
||||
double dx = -(target_point.x - 320 - 10);
|
||||
double dy = -(target_point.y - 240 - 22);
|
||||
double dx = -(target_point.x - 320 - 3);
|
||||
double dy = -(target_point.y - 240 - 74);
|
||||
//四号车
|
||||
// double dx = -(target_point.x - 320 + 16);
|
||||
// double dy = -(target_point.y - 240 - 82);
|
||||
|
||||
@@ -13,8 +13,12 @@ using namespace cv;
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
bool Energy::getOrigin() {
|
||||
if (!auto_mark && !manual_mark) {
|
||||
double dx = -(circle_center_point.x - 320 - 10);
|
||||
double dy = -(circle_center_point.y - 240 - 22);
|
||||
//五号车
|
||||
// double dx = -(circle_center_point.x - 320 - 10);
|
||||
// double dy = -(circle_center_point.y - 240 - 22);
|
||||
//四号车
|
||||
double dx = -(circle_center_point.x - 320 - 3);
|
||||
double dy = -(circle_center_point.y - 240 - 74);
|
||||
center_delta_yaw = static_cast<float>(atan(dx / FOCUS_PIXAL) * 180 / PI);
|
||||
center_delta_pitch = static_cast<float>(atan(dy / FOCUS_PIXAL) * 180 / PI);
|
||||
if (abs(center_delta_yaw) > 0.3 || abs(center_delta_pitch) > 0.3) {
|
||||
|
||||
@@ -204,6 +204,7 @@ bool Energy::isValidFlowStripContour(const vector<cv::Point> &flow_strip_contour
|
||||
length > energy_part_param_.FLOW_STRIP_CONTOUR_LENGTH_MAX ||
|
||||
width > energy_part_param_.FLOW_STRIP_CONTOUR_WIDTH_MAX) {
|
||||
// cout<<"length width fail."<<endl;
|
||||
// cout << "length: " << length << '\t' << "width: " << width << endl;
|
||||
return false;
|
||||
//矩形边长不合适
|
||||
}
|
||||
|
||||
@@ -101,9 +101,11 @@ void Energy::runBig(cv::Mat &gimbal_src) {
|
||||
if (show_energy)showCenterR("R", gimbal_src);
|
||||
changeTarget();
|
||||
getTargetPolarAngle();
|
||||
// cout << circle_center_point<< endl;
|
||||
|
||||
// judgeMode();
|
||||
// if (energy_mode_init)return;
|
||||
if (!getOrigin())return;
|
||||
// if (!getOrigin())return;
|
||||
if (energy_rotation_init) {
|
||||
initRotation();
|
||||
return;
|
||||
@@ -112,9 +114,8 @@ void Energy::runBig(cv::Mat &gimbal_src) {
|
||||
if (is_predicting) {
|
||||
getPredictPoint(target_point);
|
||||
getAimPoint(predict_point);
|
||||
cout << yaw_rotation << '\t' << pitch_rotation << endl;
|
||||
// cout << yaw_rotation << '\t' << pitch_rotation << endl;
|
||||
judgeShootInGimbal();
|
||||
|
||||
sendTarget(serial, yaw_rotation, pitch_rotation, shoot);
|
||||
} else if (is_guessing && stayGuessing()) {
|
||||
findFans(gimbal_src);
|
||||
@@ -127,21 +128,21 @@ void Energy::runBig(cv::Mat &gimbal_src) {
|
||||
sendTarget(serial, yaw_rotation, pitch_rotation, 5);
|
||||
}
|
||||
|
||||
// if (is_predicting) {
|
||||
// getPredictPoint(target_point);
|
||||
// gimbalRotation();
|
||||
// judgeShootInWorld();
|
||||
// sendTarget(serial, yaw_rotation, pitch_rotation, shoot);
|
||||
// } else if (is_guessing && stayGuessing()) {
|
||||
// findFans(gimbal_src);
|
||||
// if (show_energy)showFans("fans", gimbal_src);
|
||||
// if (save_mark)writeDownMark();
|
||||
// guessTarget();
|
||||
// if (show_energy)showGuessTarget("guess", gimbal_src);
|
||||
// getPredictPoint(guess_point);
|
||||
// gimbalRotation();
|
||||
// sendTarget(serial, yaw_rotation, pitch_rotation, 5);
|
||||
// }
|
||||
if (is_predicting) {
|
||||
getPredictPoint(target_point);
|
||||
gimbalRotation();
|
||||
judgeShootInWorld();
|
||||
sendTarget(serial, yaw_rotation, pitch_rotation, shoot);
|
||||
} else if (is_guessing && stayGuessing()) {
|
||||
findFans(gimbal_src);
|
||||
if (show_energy)showFans("fans", gimbal_src);
|
||||
if (save_mark)writeDownMark();
|
||||
guessTarget();
|
||||
if (show_energy)showGuessTarget("guess", gimbal_src);
|
||||
getPredictPoint(guess_point);
|
||||
gimbalRotation();
|
||||
sendTarget(serial, yaw_rotation, pitch_rotation, 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ void uartReceive(Serial *pSerial) {
|
||||
pSerial->ReadData((uint8_t *) buffer, sizeof(mcuData)+1);
|
||||
if (buffer[sizeof(mcuData)] == '\n') {
|
||||
memcpy(&mcuData, buffer, sizeof(mcuData));
|
||||
// LOGM("Get, state:%c, mark:%d!", mcuData.state, (int) mcuData.mark);
|
||||
LOGM("Get, state:%c, mark:%d!", mcuData.state, (int) mcuData.mark);
|
||||
// LOGM("Get yaw: %f, pitch: %f!", mcuData.curr_yaw, mcuData.curr_pitch);
|
||||
// static int t = time(nullptr);
|
||||
// static int cnt = 0;
|
||||
|
||||
Reference in New Issue
Block a user