diff --git a/energy/include/energy/energy.h b/energy/include/energy/energy.h index 283ad25..3f0cb8f 100644 --- a/energy/include/energy/energy.h +++ b/energy/include/energy/energy.h @@ -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 fans;//图像中所有扇叶 std::vector armors;//图像中所有装甲板 std::vector centerRs;//风车中心字母R的可能候选区 diff --git a/energy/src/energy/calibrate/structing.cpp b/energy/src/energy/calibrate/structing.cpp index 356e66c..179d835 100644 --- a/energy/src/energy/calibrate/structing.cpp +++ b/energy/src/energy/calibrate/structing.cpp @@ -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); } diff --git a/energy/src/energy/find/energy_finder.cpp b/energy/src/energy/find/energy_finder.cpp index 8e9f390..6b63140 100644 --- a/energy/src/energy/find/energy_finder.cpp +++ b/energy/src/energy/find/energy_finder.cpp @@ -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_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: "<20&&width>20){ - cout< 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<(fans.size()); diff --git a/energy/src/energy/get/aim_point_get.cpp b/energy/src/energy/get/aim_point_get.cpp index 243ea6d..aeb2af7 100644 --- a/energy/src/energy/get/aim_point_get.cpp +++ b/energy/src/energy/get/aim_point_get.cpp @@ -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"<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); } diff --git a/energy/src/energy/send/send.cpp b/energy/src/energy/send/send.cpp new file mode 100644 index 0000000..8846ee0 --- /dev/null +++ b/energy/src/energy/send/send.cpp @@ -0,0 +1,52 @@ +// +// Created by xixiliadorabarry on 1/24/19. +// +#include "energy/energy.h" +#include +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(x * (32768 - 1) / 100); + y_tmp = static_cast(y * (32768 - 1) / 100); + z_tmp = static_cast(z * (32768 - 1) / 1000); + buff[0] = 's'; + buff[1] = static_cast((x_tmp >> 8) & 0xFF); + buff[2] = static_cast((x_tmp >> 0) & 0xFF); + buff[3] = static_cast((y_tmp >> 8) & 0xFF); + buff[4] = static_cast((y_tmp >> 0) & 0xFF); + buff[5] = static_cast((z_tmp >> 8) & 0xFF); + buff[6] = static_cast((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(x * (32768 - 1) / 100); + y_tmp = static_cast(y * (32768 - 1) / 100); + buff[0] = 's'; + buff[1] = static_cast((x_tmp >> 8) & 0xFF); + buff[2] = static_cast((x_tmp >> 0) & 0xFF); + buff[3] = static_cast((y_tmp >> 8) & 0xFF); + buff[4] = static_cast((y_tmp >> 0) & 0xFF); + buff[5] = change; + buff[6] = shoot; + buff[7] = 'e'; + serial.WriteData(buff, sizeof(buff)); + send_cnt+=1; +} \ No newline at end of file diff --git a/energy/src/energy/send_target_by_uart/send_target_by_uart.cpp b/energy/src/energy/send_target_by_uart/send_target_by_uart.cpp deleted file mode 100644 index eccf26c..0000000 --- a/energy/src/energy/send_target_by_uart/send_target_by_uart.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// -// Created by xixiliadorabarry on 1/24/19. -// -#include "energy/energy.h" -#include -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(x * (32768 - 1) / 100); - y_tmp = static_cast(y * (32768 - 1) / 100); - z_tmp = static_cast(z * (32768 - 1) / 1000); - buff[0] = 's'; - buff[1] = static_cast((x_tmp >> 8) & 0xFF); - buff[2] = static_cast((x_tmp >> 0) & 0xFF); - buff[3] = static_cast((y_tmp >> 8) & 0xFF); - buff[4] = static_cast((y_tmp >> 0) & 0xFF); - buff[5] = static_cast((z_tmp >> 8) & 0xFF); - buff[6] = static_cast((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"<