energy changed

This commit is contained in:
sun
2019-07-06 21:53:14 +08:00
parent 0ffec961da
commit 125c09b79e
9 changed files with 84 additions and 72 deletions

View File

@@ -30,7 +30,8 @@ public:
Serial &serial;//串口
void setEnergyRotationInit();//判断顺逆时针函数
void extract(cv::Mat &src);//框取图像中的一块区域进行处理
void sendTargetByUart(float x, float y, float z);//向主控板发送数据
void sendBigTarget(Serial& serial, float x, float y, float z);
void sendSmallTarget(Serial& serial, float x, float y, char change, char shoot);
private:
@@ -62,6 +63,7 @@ private:
float origin_yaw, origin_pitch;//初始的云台角度设定值
float target_cnt;//用于记录寻找到的装甲板总数,该值变化则立即中断主控板发射进程,防止重复击打已点亮的装甲板
bool save_new_mark;//若操作手进行过手动标定则为true
bool small_energy_shoot;//若为true则要求主控板发弹
std::vector<EnergyPart> fans;//图像中所有扇叶
std::vector<EnergyPart> armors;//图像中所有装甲板
std::vector<EnergyPart> centerRs;//风车中心字母R的可能候选区

View File

@@ -46,5 +46,5 @@ void Energy::StructingElementErodeDilate(cv::Mat &src) {
// imshow("dilate_3", src);
erode(src,src, element_erode_2);
imshow("erode_2", src);
// imshow("erode_2", src);
}

View File

@@ -32,24 +32,15 @@ int Energy::findFan(const cv::Mat src, int &last_fans_cnt) {
}
fans.emplace_back(fan_contour);
/* double cur_contour_area = contourArea(fan_contour);
RotatedRect cur_rect = minAreaRect(fan_contour);
Size2f cur_size = cur_rect.size;
cout<<"cur_contour_area: "<<cur_contour_area<<'\t'<<"rect_area: "<<cur_size.area()<<
'\t'<<"ratio: "<<cur_contour_area/cur_size.area()<<endl;
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;
cout<<"fan area: "<<length<<'\t'<<width<<endl;
if(length>20&&width>20){
cout<<cur_rect.center;
fans.emplace_back(fan_contour);
cout<<"fan area: "<<length<<'\t'<<width<<endl;
}
cout<<"fan area: "<<length<<'\t'<<width<<endl;*/
// RotatedRect cur_rect = minAreaRect(fan_contour);
// 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>20&&width>20){
// cout<<cur_rect.center;
// fans.emplace_back(fan_contour);
// cout<<"fan area: "<<length<<'\t'<<width<<endl;
// }
}
if(fans.size() < last_fans_cnt){
last_fans_cnt = static_cast<int>(fans.size());

View File

@@ -20,4 +20,10 @@ void Energy::getAimPoint(){
double dy = target_point.y - 240;
yaw_rotation = atan(dx / FOCUS_PIXAL) * 180 / PI;
pitch_rotation = atan(dy / FOCUS_PIXAL) * 180 / PI;
if(fabs(yaw_rotation) < 0.5 && fabs(pitch_rotation) < 0.5){
small_energy_shoot = true;
cout<<"send"<<endl;
}
else
small_energy_shoot = false;
}

View File

@@ -44,6 +44,7 @@ void Energy::initEnergy() {
blue_origin_pitch = 15.688477;
target_cnt = 0;
small_energy_shoot = false;
energy_rotation_init = false;
predict_rad = 20;
@@ -66,23 +67,23 @@ void Energy::initEnergy() {
// 此函数对能量机关参数进行初始化
// ---------------------------------------------------------------------------------------------------------------------
void Energy::initEnergyPartParam() {
energy_part_param_.GRAY_THRESH = 235;
energy_part_param_.GRAY_THRESH = 225;
energy_part_param_.SPLIT_GRAY_THRESH = 60;
energy_part_param_.FAN_GRAY_THRESH = 75;
energy_part_param_.ARMOR_GRAY_THRESH = 80;
energy_part_param_.FAN_CONTOUR_AREA_MAX = 17000;
energy_part_param_.FAN_CONTOUR_AREA_MIN = 0;
energy_part_param_.FAN_CONTOUR_LENGTH_MIN = 90;
energy_part_param_.FAN_CONTOUR_LENGTH_MAX = 140;
energy_part_param_.FAN_CONTOUR_WIDTH_MIN = 35;
energy_part_param_.FAN_CONTOUR_LENGTH_MIN = 70;
energy_part_param_.FAN_CONTOUR_LENGTH_MAX = 100;
energy_part_param_.FAN_CONTOUR_WIDTH_MIN = 30;
energy_part_param_.FAN_CONTOUR_WIDTH_MAX = 60;
energy_part_param_.FAN_CONTOUR_HW_RATIO_MAX = 4;
energy_part_param_.FAN_CONTOUR_HW_RATIO_MIN = 1;
energy_part_param_.ARMOR_CONTOUR_AREA_MAX = 100000;
energy_part_param_.ARMOR_CONTOUR_AREA_MIN = 0;
energy_part_param_.ARMOR_CONTOUR_LENGTH_MIN = 15;
energy_part_param_.ARMOR_CONTOUR_LENGTH_MIN = 13;
energy_part_param_.ARMOR_CONTOUR_WIDTH_MIN = 5;
energy_part_param_.ARMOR_CONTOUR_LENGTH_MAX = 30;
energy_part_param_.ARMOR_CONTOUR_WIDTH_MAX = 20;

View File

@@ -57,7 +57,8 @@ int Energy::runBig(cv::Mat &gimble_src, cv::Mat &chassis_src){
// cout<<"send"<<endl;
// cout<<"position mode: "<<position_mode<<endl;
sendTargetByUart(yaw_rotation, pitch_rotation, target_cnt);
if(changeTarget())target_cnt++;
sendBigTarget(serial, yaw_rotation, pitch_rotation, target_cnt);
return 0;
}
// if(centered)
@@ -122,7 +123,8 @@ int Energy::runBig(cv::Mat &gimble_src){
}
getPredictPoint();
gimbleRotation();
sendTargetByUart(yaw_rotation, pitch_rotation, target_cnt);
if(changeTarget())target_cnt++;
sendBigTarget(serial, yaw_rotation, pitch_rotation, target_cnt);
// cout<<"yaw: "<<yaw_rotation<<'\t'<<"pitch: "<<pitch_rotation<<endl;
// cout<<"curr_yaw: "<<mcuData.curr_yaw<<'\t'<<"curr_pitch: "<<mcuData.curr_pitch<<endl;
@@ -149,7 +151,8 @@ int Energy::runSmall(cv::Mat &gimble_src){
findTargetByIntersection();
if(armors_cnt>0||fans_cnt>0) showBothContours("Both", gimble_src);
getAimPoint();
sendTargetByUart(yaw_rotation, pitch_rotation, target_cnt);
if(changeTarget())target_cnt++;//若云台移动过程中发现有新装甲板亮起需改变target_cnt值以及时告知主控板中断进程防止重复打击
sendSmallTarget(serial, yaw_rotation, pitch_rotation, target_cnt, small_energy_shoot);
}

View File

@@ -0,0 +1,52 @@
//
// Created by xixiliadorabarry on 1/24/19.
//
#include "energy/energy.h"
#include <iostream>
using namespace std;
//----------------------------------------------------------------------------------------------------------------------
// 此函数用于发送小符数据
// ---------------------------------------------------------------------------------------------------------------------
void Energy::sendBigTarget(Serial& serial, float x, float y, float z) {
static short x_tmp, y_tmp, z_tmp;
uint8_t buff[8];
x_tmp = static_cast<short>(x * (32768 - 1) / 100);
y_tmp = static_cast<short>(y * (32768 - 1) / 100);
z_tmp = static_cast<short>(z * (32768 - 1) / 1000);
buff[0] = 's';
buff[1] = static_cast<char>((x_tmp >> 8) & 0xFF);
buff[2] = static_cast<char>((x_tmp >> 0) & 0xFF);
buff[3] = static_cast<char>((y_tmp >> 8) & 0xFF);
buff[4] = static_cast<char>((y_tmp >> 0) & 0xFF);
buff[5] = static_cast<char>((z_tmp >> 8) & 0xFF);
buff[6] = static_cast<char>((z_tmp >> 0) & 0xFF);
buff[7] = 'e';
serial.WriteData(buff, sizeof(buff));
send_cnt+=1;
}
//----------------------------------------------------------------------------------------------------------------------
// 此函数用于发送大符数据
// ---------------------------------------------------------------------------------------------------------------------
void Energy::sendSmallTarget(Serial& serial, float x, float y, char change, char shoot){
static short x_tmp, y_tmp, z_tmp;
uint8_t buff[8];
x_tmp = static_cast<short>(x * (32768 - 1) / 100);
y_tmp = static_cast<short>(y * (32768 - 1) / 100);
buff[0] = 's';
buff[1] = static_cast<char>((x_tmp >> 8) & 0xFF);
buff[2] = static_cast<char>((x_tmp >> 0) & 0xFF);
buff[3] = static_cast<char>((y_tmp >> 8) & 0xFF);
buff[4] = static_cast<char>((y_tmp >> 0) & 0xFF);
buff[5] = change;
buff[6] = shoot;
buff[7] = 'e';
serial.WriteData(buff, sizeof(buff));
send_cnt+=1;
}

View File

@@ -1,43 +0,0 @@
//
// Created by xixiliadorabarry on 1/24/19.
//
#include "energy/energy.h"
#include <iostream>
using namespace std;
//----------------------------------------------------------------------------------------------------------------------
// 此函数用于向主控板发送数据
// ---------------------------------------------------------------------------------------------------------------------
bool sendTarget(Serial& serial, float x, float y, float z) {
static short x_tmp, y_tmp, z_tmp;
uint8_t buff[8];
x_tmp = static_cast<short>(x * (32768 - 1) / 100);
y_tmp = static_cast<short>(y * (32768 - 1) / 100);
z_tmp = static_cast<short>(z * (32768 - 1) / 1000);
buff[0] = 's';
buff[1] = static_cast<char>((x_tmp >> 8) & 0xFF);
buff[2] = static_cast<char>((x_tmp >> 0) & 0xFF);
buff[3] = static_cast<char>((y_tmp >> 8) & 0xFF);
buff[4] = static_cast<char>((y_tmp >> 0) & 0xFF);
buff[5] = static_cast<char>((z_tmp >> 8) & 0xFF);
buff[6] = static_cast<char>((z_tmp >> 0) & 0xFF);
buff[7] = 'e';
return serial.WriteData(buff, sizeof(buff));
}
//----------------------------------------------------------------------------------------------------------------------
// 此函数用于操作手数据发送
// ---------------------------------------------------------------------------------------------------------------------
void Energy::sendTargetByUart(float x, float y, float z) {
if(changeTarget())target_cnt++;
sendTarget(serial, x, y, z);
send_cnt+=1;
// cout<<"send"<<endl;
}

View File

@@ -26,7 +26,7 @@ using namespace std;
mcu_data mcuData = {
0,
0,
ARMOR_STATE,
SMALL_ENERGY_STATE,
0,
1,
ENEMY_BLUE,