Auto Aim
This commit is contained in:
@@ -19,10 +19,10 @@ const float ATTACK_DISTANCE = 770;//cm
|
||||
const double WHOLE_FAN = 80;//cm
|
||||
const double ARMOR_CENTER_TO_CYCLE_CENTER = 75;//cm
|
||||
//const double ARMOR_CENTER_TO_CYCLE_CENTER = 71;//cm
|
||||
const int EXTRACT_POINT_X = 200;
|
||||
const int EXTRACT_POINT_Y = 20;
|
||||
const int EXTRACT_WIDTH = 240;
|
||||
const int EXTRACT_HEIGHT = 180;
|
||||
const int EXTRACT_POINT_X = 120;
|
||||
const int EXTRACT_POINT_Y = 0;
|
||||
const int EXTRACT_WIDTH = 400;
|
||||
const int EXTRACT_HEIGHT = 300;
|
||||
|
||||
//以摄像头正方向位y轴
|
||||
const int GM_L = 14;//云台摄像头z方向
|
||||
|
||||
@@ -11,18 +11,79 @@ using std::endl;
|
||||
using std::vector;
|
||||
|
||||
void Energy::getHitPoint(){
|
||||
// if(!changeTarget()){
|
||||
// //last_target_center = target_center;
|
||||
// //last_target_position = target_position;
|
||||
// return;
|
||||
// }
|
||||
// else {
|
||||
double rad = static_cast<double>(energy_part_rotation * energy_part_param_.RPM
|
||||
* energy_part_param_.HIT_TIME * 360 / 60);
|
||||
rotate(rad, radius, cycle_center, target_center, hit_point);
|
||||
//last_target_center = target_center;
|
||||
//last_target_position = target_position;
|
||||
// }
|
||||
int hit_position = 1000;
|
||||
|
||||
if(energy_part_rotation==1){ //顺时针
|
||||
if(target_armor>=0&&target_armor<60){
|
||||
hit_point.x = cycle_center.x + static_cast<int>(radius / 2);
|
||||
hit_point.y = cycle_center.y + static_cast<int>(radius * sqrt(3) / 2);
|
||||
hit_position = -60;
|
||||
}
|
||||
if(target_armor>=60&&target_armor<120){
|
||||
hit_point.x = cycle_center.x + static_cast<int>(radius);
|
||||
hit_point.y = cycle_center.y;
|
||||
hit_position = 0;
|
||||
}
|
||||
if(target_armor>=120&&target_armor<=180){
|
||||
hit_point.x = cycle_center.x + static_cast<int>(radius / 2);
|
||||
hit_point.y = cycle_center.y - static_cast<int>(radius * sqrt(3) / 2);
|
||||
hit_position = 60;
|
||||
}
|
||||
if(target_armor>=-180&&target_armor<-120){
|
||||
hit_point.x = cycle_center.x - static_cast<int>(radius / 2);
|
||||
hit_point.y = cycle_center.y - static_cast<int>(radius * sqrt(3) / 2);
|
||||
hit_position = 120;
|
||||
}
|
||||
if(target_armor>=-120&&target_armor<-60){
|
||||
hit_point.x = cycle_center.x - static_cast<int>(radius);
|
||||
hit_point.y = cycle_center.y;
|
||||
hit_position = 180;
|
||||
}
|
||||
if(target_armor>=-60&&target_armor<0){
|
||||
hit_point.x = cycle_center.x - static_cast<int>(radius / 2);
|
||||
hit_point.y = cycle_center.y + static_cast<int>(radius * sqrt(3) / 2);
|
||||
hit_position = -120;
|
||||
}
|
||||
}
|
||||
|
||||
if(energy_part_rotation==-1){ //逆时针
|
||||
if(target_armor>=0&&target_armor<60){
|
||||
hit_point.x = cycle_center.x - static_cast<int>(radius / 2);
|
||||
hit_point.y = cycle_center.y - static_cast<int>(radius * sqrt(3) / 2);
|
||||
hit_position = 120;
|
||||
}
|
||||
if(target_armor>=60&&target_armor<120){
|
||||
hit_point.x = cycle_center.x - static_cast<int>(radius);
|
||||
hit_point.y = cycle_center.y;
|
||||
hit_position = 180;
|
||||
}
|
||||
if(target_armor>=120&&target_armor<=180){
|
||||
hit_point.x = cycle_center.x - static_cast<int>(radius / 2);
|
||||
hit_point.y = cycle_center.y + static_cast<int>(radius * sqrt(3) / 2);
|
||||
hit_position = -120;
|
||||
}
|
||||
if(target_armor>=-180&&target_armor<-120){
|
||||
hit_point.x = cycle_center.x + static_cast<int>(radius / 2);
|
||||
hit_point.y = cycle_center.y + static_cast<int>(radius * sqrt(3) / 2);
|
||||
hit_position = -60;
|
||||
}
|
||||
if(target_armor>=-120&&target_armor<-60){
|
||||
hit_point.x = cycle_center.x + static_cast<int>(radius);
|
||||
hit_point.y = cycle_center.y;
|
||||
hit_position = 0;
|
||||
}
|
||||
if(target_armor>=-60&&target_armor<0){
|
||||
hit_point.x = cycle_center.x + static_cast<int>(radius / 2);
|
||||
hit_point.y = cycle_center.y - static_cast<int>(radius * sqrt(3) / 2);
|
||||
hit_position = 60;
|
||||
}
|
||||
}
|
||||
|
||||
cout<<"hit position: "<<hit_position<<endl;
|
||||
|
||||
// double rad = static_cast<double>(energy_part_rotation * energy_part_param_.RPM
|
||||
// * energy_part_param_.HIT_TIME * 360 / 60);
|
||||
// rotate(rad, radius, cycle_center, target_center, hit_point);
|
||||
}
|
||||
|
||||
bool Energy::changeTarget(){
|
||||
|
||||
@@ -14,7 +14,7 @@ void Energy::initEnergyPartParam() {
|
||||
energy_part_param_.HIT_TIME = 1.14;
|
||||
|
||||
energy_part_param_.GRAY_THRESH = 240;
|
||||
energy_part_param_.SPLIT_GRAY_THRESH = 80;
|
||||
energy_part_param_.SPLIT_GRAY_THRESH = 60;
|
||||
energy_part_param_.FAN_GRAY_THRESH = 75;
|
||||
energy_part_param_.ARMOR_GRAY_THRESH = 80;
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ int Energy::run(cv::Mat &src){
|
||||
armorPosition.clear();
|
||||
gimble_zero_points.clear();
|
||||
|
||||
if(mark==0)return 0;
|
||||
// if(mark==0)return 0;
|
||||
|
||||
// if(all_armor_centers.size()>200)all_armor_centers.clear();
|
||||
// if(first_armor_centers.size()>200)first_armor_centers.clear();
|
||||
// cout<<"first_armor_centers.size(): "<<first_armor_centers.size()<<endl;
|
||||
|
||||
// imagePreprocess(src);
|
||||
imagePreprocess(src);
|
||||
// imshow("img_preprocess",src);
|
||||
|
||||
threshold(src, src, energy_part_param_.GRAY_THRESH, 255, THRESH_BINARY);
|
||||
@@ -47,22 +47,10 @@ int Energy::run(cv::Mat &src){
|
||||
|
||||
if(armors_cnt != fans_cnt+1) return 0;
|
||||
|
||||
|
||||
/*
|
||||
//此处用于标定云台在摄像头视频中的零点
|
||||
findGimbleZeroPoint(src,gimble_zero_points);
|
||||
cout<<"gimble zero points: :"<<gimble_zero_points.size()<<endl;
|
||||
showFanContours("zero",src,gimble_zero_points);
|
||||
cycle_center = cv::Point(291,305);
|
||||
if(gimble_zero_points.size()>0)hit_point = gimble_zero_points.at(0).rect.center;
|
||||
*/
|
||||
|
||||
|
||||
getAllArmorCenters();
|
||||
cout<<"all_armor_centers.size(): "<<all_armor_centers.size()<<endl;
|
||||
cycleLeastFit();
|
||||
|
||||
|
||||
// cycle_center = cv::Point(212,246);
|
||||
// radius = 123.942;
|
||||
attack_distance = ATTACK_DISTANCE * 123.323 / radius;
|
||||
@@ -89,5 +77,17 @@ int Energy::run(cv::Mat &src){
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
//此处用于标定云台在摄像头视频中的零点
|
||||
findGimbleZeroPoint(src,gimble_zero_points);
|
||||
cout<<"gimble zero points: :"<<gimble_zero_points.size()<<endl;
|
||||
showFanContours("zero",src,gimble_zero_points);
|
||||
cycle_center = cv::Point(291,305);
|
||||
if(gimble_zero_points.size()>0)hit_point = gimble_zero_points.at(0).rect.center;
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user