Auto Aim
This commit is contained in:
@@ -18,16 +18,16 @@ void Energy::gimbleRotation(){
|
|||||||
// pitch_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(PITCH_ORIGIN_RAD)-STRETCH*(hit_point.y-ZERO_POINT_Y)), ATTACK_DISTANCE));
|
// pitch_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(PITCH_ORIGIN_RAD)-STRETCH*(hit_point.y-ZERO_POINT_Y)), ATTACK_DISTANCE));
|
||||||
|
|
||||||
//该方法用于操作手自己完成对心工作的情况,对操作手要求高
|
//该方法用于操作手自己完成对心工作的情况,对操作手要求高
|
||||||
// cv::Point2f real_hit_point;
|
cv::Point2f real_hit_point;
|
||||||
// stretch(hit_point, real_hit_point);
|
stretch(hit_point, real_hit_point);
|
||||||
// yaw_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(YAW_ORIGIN_RAD)-real_hit_point.x), ATTACK_DISTANCE));
|
// yaw_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(YAW_ORIGIN_RAD)-real_hit_point.x), ATTACK_DISTANCE));
|
||||||
// pitch_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(PITCH_ORIGIN_RAD)-real_hit_point.y), ATTACK_DISTANCE));
|
// pitch_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(PITCH_ORIGIN_RAD)-real_hit_point.y), ATTACK_DISTANCE));
|
||||||
|
|
||||||
// yaw_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(curr_yaw)-real_hit_point.x), ATTACK_DISTANCE));
|
yaw_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(mark_yaw*PI/180)-real_hit_point.x), ATTACK_DISTANCE));
|
||||||
// pitch_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(curr_pitch)-real_hit_point.y), ATTACK_DISTANCE));
|
pitch_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(mark_pitch*PI/180)-real_hit_point.y), ATTACK_DISTANCE));
|
||||||
|
|
||||||
yaw_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(3.5*PI/180)-STRETCH*(hit_point.x-cycle_center.x)), ATTACK_DISTANCE));
|
// yaw_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(3.5*PI/180)-STRETCH*(hit_point.x-cycle_center.x)), ATTACK_DISTANCE));
|
||||||
pitch_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(9.1*PI/180)-STRETCH*(hit_point.y-cycle_center.y)), ATTACK_DISTANCE));
|
// pitch_rotation = static_cast<float>(180 / PI * atan2((ATTACK_DISTANCE*tan(9.1*PI/180)-STRETCH*(hit_point.y-cycle_center.y)), ATTACK_DISTANCE));
|
||||||
cout<<"cur: "<<curr_yaw<<endl;
|
// cout<<"cur: "<<curr_yaw<<endl;
|
||||||
cout<<"hit point: "<<hit_point<<'\t'<<"cycle center: "<<cycle_center<<endl;
|
// cout<<"hit point: "<<hit_point<<'\t'<<"cycle center: "<<cycle_center<<endl;
|
||||||
}
|
}
|
||||||
@@ -8,12 +8,18 @@ using std::cout;
|
|||||||
using std::endl;
|
using std::endl;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
|
extern float mark_yaw, mark_pitch;
|
||||||
|
extern int mark;
|
||||||
|
|
||||||
int Energy::run(cv::Mat &src){
|
int Energy::run(cv::Mat &src){
|
||||||
fans.clear();
|
fans.clear();
|
||||||
armors.clear();
|
armors.clear();
|
||||||
fanPosition.clear();
|
fanPosition.clear();
|
||||||
armorPosition.clear();
|
armorPosition.clear();
|
||||||
gimble_zero_points.clear();
|
gimble_zero_points.clear();
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -24,7 +30,7 @@ int Energy::run(cv::Mat &src){
|
|||||||
threshold(src, src, energy_part_param_.GRAY_THRESH, 255, THRESH_BINARY);
|
threshold(src, src, energy_part_param_.GRAY_THRESH, 255, THRESH_BINARY);
|
||||||
// imshow("bin",src);
|
// imshow("bin",src);
|
||||||
|
|
||||||
/*
|
|
||||||
fans_cnt = findFan(src, fans, last_fans_cnt);
|
fans_cnt = findFan(src, fans, last_fans_cnt);
|
||||||
// cout<<"fans_cnt: "<<fans_cnt<<endl;
|
// cout<<"fans_cnt: "<<fans_cnt<<endl;
|
||||||
if(fans_cnt==-1) return 0;//滤去漏判的帧
|
if(fans_cnt==-1) return 0;//滤去漏判的帧
|
||||||
@@ -39,22 +45,24 @@ int Energy::run(cv::Mat &src){
|
|||||||
if(armors_cnt>0||fans_cnt>0) showBothContours("Both",src, fans, armors);
|
if(armors_cnt>0||fans_cnt>0) showBothContours("Both",src, fans, armors);
|
||||||
|
|
||||||
if(armors_cnt != fans_cnt+1) return 0;
|
if(armors_cnt != fans_cnt+1) return 0;
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
//此处用于标定云台在摄像头视频中的零点
|
//此处用于标定云台在摄像头视频中的零点
|
||||||
findGimbleZeroPoint(src,gimble_zero_points);
|
findGimbleZeroPoint(src,gimble_zero_points);
|
||||||
cout<<"gimble zero points: :"<<gimble_zero_points.size()<<endl;
|
cout<<"gimble zero points: :"<<gimble_zero_points.size()<<endl;
|
||||||
showFanContours("zero",src,gimble_zero_points);
|
showFanContours("zero",src,gimble_zero_points);
|
||||||
cycle_center = cv::Point(291,305);
|
cycle_center = cv::Point(291,305);
|
||||||
if(gimble_zero_points.size()>0)hit_point = gimble_zero_points.at(0).rect.center;
|
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(248,247);
|
cycle_center = cv::Point(416,227);
|
||||||
// radius = 208.439;
|
radius = 203.665;
|
||||||
getFanPosition(fanPosition, fans, cycle_center, radius);
|
getFanPosition(fanPosition, fans, cycle_center, radius);
|
||||||
getArmorPosition(armorPosition, armors, cycle_center, radius);
|
getArmorPosition(armorPosition, armors, cycle_center, radius);
|
||||||
findTarget(fanPosition, armorPosition, target_armor);
|
findTarget(fanPosition, armorPosition, target_armor);
|
||||||
@@ -62,14 +70,17 @@ int Energy::run(cv::Mat &src){
|
|||||||
cout<<"The target armor center is: "<<target_center<<endl;
|
cout<<"The target armor center is: "<<target_center<<endl;
|
||||||
|
|
||||||
getHitPoint();
|
getHitPoint();
|
||||||
|
hit_point = target_center;
|
||||||
cout << "The hit point position is " << hit_point << endl;
|
cout << "The hit point position is " << hit_point << endl;
|
||||||
// hit_point = cycle_center;
|
// hit_point = cycle_center;
|
||||||
*/
|
|
||||||
gimbleRotation();
|
gimbleRotation();
|
||||||
|
|
||||||
sendTargetByUart(yaw_rotation, pitch_rotation, attack_distance);
|
sendTargetByUart(yaw_rotation, pitch_rotation, attack_distance);
|
||||||
cout<<"yaw: "<<yaw_rotation<<'\t'<<"pitch: "<<pitch_rotation<<endl;
|
cout<<"yaw: "<<yaw_rotation<<'\t'<<"pitch: "<<pitch_rotation<<endl;
|
||||||
// cout<<"send_cnt: "<<send_cnt<<endl;
|
cout<<"mark_yaw: "<<mark_yaw<<'\t'<<"mark_pitch: "<<mark_pitch<<endl;
|
||||||
|
|
||||||
|
cout<<"send_cnt: "<<send_cnt<<endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,10 @@ void Energy::showBothContours(std::string windows_name, const cv::Mat &src, cons
|
|||||||
line(image2show, vertices[i], vertices[(i + 1) % 4], Scalar(0, 0, 255), 4);
|
line(image2show, vertices[i], vertices[(i + 1) % 4], Scalar(0, 0, 255), 4);
|
||||||
// cout << "armor center: "<< armor.rect.center << '\t'<< "armor angle: "<< armor.rect.angle;
|
// cout << "armor center: "<< armor.rect.center << '\t'<< "armor angle: "<< armor.rect.angle;
|
||||||
// cout << endl;
|
// cout << endl;
|
||||||
|
|
||||||
|
cv::Point2f point = armor.rect.center;
|
||||||
|
cv::circle(image2show, point, 2, cv::Scalar(0, 0, 255));//在图像中画出特征点,2是圆的半径
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imshow(windows_name, image2show);
|
imshow(windows_name, image2show);
|
||||||
|
|||||||
4
main.cpp
4
main.cpp
@@ -27,6 +27,7 @@ using namespace std;
|
|||||||
int state = ENERGY_STATE;
|
int state = ENERGY_STATE;
|
||||||
float curr_yaw=0, curr_pitch=0;
|
float curr_yaw=0, curr_pitch=0;
|
||||||
float mark_yaw=0, mark_pitch=0;
|
float mark_yaw=0, mark_pitch=0;
|
||||||
|
int mark = 0;
|
||||||
|
|
||||||
void uartReceive(Uart* uart);
|
void uartReceive(Uart* uart);
|
||||||
|
|
||||||
@@ -112,8 +113,9 @@ void uartReceive(Uart* uart){
|
|||||||
}
|
}
|
||||||
memcpy(&curr_yaw, buffer, 4);
|
memcpy(&curr_yaw, buffer, 4);
|
||||||
memcpy(&curr_pitch, buffer+4, 4);
|
memcpy(&curr_pitch, buffer+4, 4);
|
||||||
LOGM("Get yaw:%f pitch:%f", curr_yaw, curr_pitch);
|
// LOGM("Get yaw:%f pitch:%f", curr_yaw, curr_pitch);
|
||||||
if(buffer[9] == 1){
|
if(buffer[9] == 1){
|
||||||
|
mark = 1;
|
||||||
mark_yaw = curr_yaw;
|
mark_yaw = curr_yaw;
|
||||||
mark_pitch = curr_pitch;
|
mark_pitch = curr_pitch;
|
||||||
// LOGM("Marked");
|
// LOGM("Marked");
|
||||||
|
|||||||
Reference in New Issue
Block a user