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 WHOLE_FAN = 80;//cm
|
||||||
const double ARMOR_CENTER_TO_CYCLE_CENTER = 75;//cm
|
const double ARMOR_CENTER_TO_CYCLE_CENTER = 75;//cm
|
||||||
//const double ARMOR_CENTER_TO_CYCLE_CENTER = 71;//cm
|
//const double ARMOR_CENTER_TO_CYCLE_CENTER = 71;//cm
|
||||||
const int EXTRACT_POINT_X = 200;
|
const int EXTRACT_POINT_X = 120;
|
||||||
const int EXTRACT_POINT_Y = 20;
|
const int EXTRACT_POINT_Y = 0;
|
||||||
const int EXTRACT_WIDTH = 240;
|
const int EXTRACT_WIDTH = 400;
|
||||||
const int EXTRACT_HEIGHT = 180;
|
const int EXTRACT_HEIGHT = 300;
|
||||||
|
|
||||||
//以摄像头正方向位y轴
|
//以摄像头正方向位y轴
|
||||||
const int GM_L = 14;//云台摄像头z方向
|
const int GM_L = 14;//云台摄像头z方向
|
||||||
|
|||||||
@@ -11,18 +11,79 @@ using std::endl;
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
void Energy::getHitPoint(){
|
void Energy::getHitPoint(){
|
||||||
// if(!changeTarget()){
|
int hit_position = 1000;
|
||||||
// //last_target_center = target_center;
|
|
||||||
// //last_target_position = target_position;
|
if(energy_part_rotation==1){ //顺时针
|
||||||
// return;
|
if(target_armor>=0&&target_armor<60){
|
||||||
// }
|
hit_point.x = cycle_center.x + static_cast<int>(radius / 2);
|
||||||
// else {
|
hit_point.y = cycle_center.y + static_cast<int>(radius * sqrt(3) / 2);
|
||||||
double rad = static_cast<double>(energy_part_rotation * energy_part_param_.RPM
|
hit_position = -60;
|
||||||
* energy_part_param_.HIT_TIME * 360 / 60);
|
}
|
||||||
rotate(rad, radius, cycle_center, target_center, hit_point);
|
if(target_armor>=60&&target_armor<120){
|
||||||
//last_target_center = target_center;
|
hit_point.x = cycle_center.x + static_cast<int>(radius);
|
||||||
//last_target_position = target_position;
|
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(){
|
bool Energy::changeTarget(){
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ void Energy::initEnergyPartParam() {
|
|||||||
energy_part_param_.HIT_TIME = 1.14;
|
energy_part_param_.HIT_TIME = 1.14;
|
||||||
|
|
||||||
energy_part_param_.GRAY_THRESH = 240;
|
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_.FAN_GRAY_THRESH = 75;
|
||||||
energy_part_param_.ARMOR_GRAY_THRESH = 80;
|
energy_part_param_.ARMOR_GRAY_THRESH = 80;
|
||||||
|
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ int Energy::run(cv::Mat &src){
|
|||||||
armorPosition.clear();
|
armorPosition.clear();
|
||||||
gimble_zero_points.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(all_armor_centers.size()>200)all_armor_centers.clear();
|
||||||
// if(first_armor_centers.size()>200)first_armor_centers.clear();
|
// if(first_armor_centers.size()>200)first_armor_centers.clear();
|
||||||
// cout<<"first_armor_centers.size(): "<<first_armor_centers.size()<<endl;
|
// cout<<"first_armor_centers.size(): "<<first_armor_centers.size()<<endl;
|
||||||
|
|
||||||
// imagePreprocess(src);
|
imagePreprocess(src);
|
||||||
// imshow("img_preprocess",src);
|
// imshow("img_preprocess",src);
|
||||||
|
|
||||||
threshold(src, src, energy_part_param_.GRAY_THRESH, 255, THRESH_BINARY);
|
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;
|
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();
|
getAllArmorCenters();
|
||||||
cout<<"all_armor_centers.size(): "<<all_armor_centers.size()<<endl;
|
cout<<"all_armor_centers.size(): "<<all_armor_centers.size()<<endl;
|
||||||
cycleLeastFit();
|
cycleLeastFit();
|
||||||
|
|
||||||
|
|
||||||
// cycle_center = cv::Point(212,246);
|
// cycle_center = cv::Point(212,246);
|
||||||
// radius = 123.942;
|
// radius = 123.942;
|
||||||
attack_distance = ATTACK_DISTANCE * 123.323 / radius;
|
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;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
3
main.cpp
3
main.cpp
@@ -73,6 +73,9 @@ int main(int argc, char *argv[])
|
|||||||
imshow("armor src", armor_src);
|
imshow("armor src", armor_src);
|
||||||
}
|
}
|
||||||
if(state == ENERGY_STATE){
|
if(state == ENERGY_STATE){
|
||||||
|
if(from_camera==0){
|
||||||
|
energy.extract(energy_src);
|
||||||
|
}
|
||||||
energy.run(energy_src);
|
energy.run(energy_src);
|
||||||
}else{
|
}else{
|
||||||
armorFinder.run(armor_src);
|
armorFinder.run(armor_src);
|
||||||
|
|||||||
Reference in New Issue
Block a user