diff --git a/.gitignore b/.gitignore index 69211d5..b15ebf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ cmake-build-debug +build .idea tools/TrainCNN/.idea tools/TrainCNN/__pycache__ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 10c26dd..6e58ca0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,5 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/armor/include) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/others/include) - TARGET_LINK_LIBRARIES(${BIN_NAME} ${CMAKE_THREAD_LIBS_INIT}) -TARGET_LINK_LIBRARIES(${BIN_NAME} ${OpenCV_LIBS}) \ No newline at end of file +TARGET_LINK_LIBRARIES(${BIN_NAME} ${OpenCV_LIBS}) diff --git a/energy/src/energy/calibrate/structing.cpp b/energy/src/energy/calibrate/structing.cpp index 35fd77c..97b2721 100644 --- a/energy/src/energy/calibrate/structing.cpp +++ b/energy/src/energy/calibrate/structing.cpp @@ -28,14 +28,14 @@ void Energy::StructingElementErodeDilate(cv::Mat &src) { // imshow("dilate_1", src); erode(src,src, element_erode_1); - imshow("erode_1", src); +// imshow("erode_1", src); dilate(src, src, element_dilate_2); - imshow("dilate_2", src); +// imshow("dilate_2", src); erode(src,src, element_erode_2); - imshow("erode_2", src); +// imshow("erode_2", src); dilate(src, src, element_dilate_3); - imshow("dilate_3", src); +// imshow("dilate_3", src); } diff --git a/energy/src/energy/find/energy_finder.cpp b/energy/src/energy/find/energy_finder.cpp index 04cca3e..4fcf680 100644 --- a/energy/src/energy/find/energy_finder.cpp +++ b/energy/src/energy/find/energy_finder.cpp @@ -19,7 +19,8 @@ int Energy::findFan(const cv::Mat &src, vector &fans, int &last_fans std::vector > fan_contours; StructingElementClose(src_bin,6,6); - imshow("fan struct",src_bin); + +// imshow("fan struct",src_bin); findContours(src_bin, fan_contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); @@ -72,7 +73,7 @@ int Energy::findArmor(const cv::Mat &src, vector &armors, int &last_ StructingElementErodeDilate(src_bin); // StructingElementClose(src_bin,10,10); - imshow("armor struct",src_bin); +// imshow("armor struct",src_bin); findContours(src_bin, armor_contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE); findContours(src_bin, armor_contours_external, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); diff --git a/energy/src/energy/get/gimble_rotation_get.cpp b/energy/src/energy/get/gimble_rotation_get.cpp index 3d69210..c9b3377 100644 --- a/energy/src/energy/get/gimble_rotation_get.cpp +++ b/energy/src/energy/get/gimble_rotation_get.cpp @@ -16,38 +16,38 @@ void Energy::gimbleRotation(){ cv::Point2f real_hit_point; stretch(hit_point, real_hit_point); + float origin_yaw = -0.13; + float origin_pitch = 13.18; + + /*origin_yaw = mark_yaw; + origin_pitch = mark_pitch;*/ if(position_mode == 1){ - yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(mark_yaw * PI / 180) - real_hit_point.x), attack_distance)); - pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(mark_pitch*PI/180)-real_hit_point.y), attack_distance)); + yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(origin_yaw * PI / 180) - real_hit_point.x), attack_distance)); + pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(origin_pitch*PI/180)-real_hit_point.y), attack_distance)); } else if(position_mode == 2){ - yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(mark_yaw * PI / 180) - real_hit_point.x), attack_distance)); - pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(mark_pitch*PI/180)-real_hit_point.y), attack_distance)); + yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(origin_yaw * PI / 180) - real_hit_point.x), attack_distance)); + pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(origin_pitch*PI/180)-real_hit_point.y), attack_distance)); } else if(position_mode == 3){ - yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(mark_yaw * PI / 180) - real_hit_point.x), attack_distance)); - pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(mark_pitch*PI/180)-real_hit_point.y), attack_distance)); + yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(origin_yaw * PI / 180) - real_hit_point.x), attack_distance)); + pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(origin_pitch*PI/180)-real_hit_point.y), attack_distance)); } else if(position_mode == 4){ - yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(mark_yaw * PI / 180) - real_hit_point.x), attack_distance)); - pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(mark_pitch*PI/180)-real_hit_point.y), attack_distance)); + yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(origin_yaw * PI / 180) - real_hit_point.x), attack_distance)); + pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(origin_pitch*PI/180)-real_hit_point.y), attack_distance)); } else if(position_mode == 5){ - yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(mark_yaw * PI / 180) - real_hit_point.x), attack_distance)); - pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(mark_pitch*PI/180)-real_hit_point.y), attack_distance)); + yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(origin_yaw * PI / 180) - real_hit_point.x), attack_distance)); + pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(origin_pitch*PI/180)-real_hit_point.y), attack_distance)); } else if(position_mode == 6){ - yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(mark_yaw * PI / 180) - real_hit_point.x), attack_distance)); - pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(mark_pitch*PI/180)-real_hit_point.y), attack_distance)); + yaw_rotation = static_cast(180 / PI * atan2((attack_distance * tan(origin_yaw * PI / 180) - real_hit_point.x), attack_distance)); + pitch_rotation = static_cast(180 / PI * atan2((attack_distance*tan(origin_pitch*PI/180)-real_hit_point.y), attack_distance)); } // else{ // pitch_rotation = 5.5+static_cast(180 / PI * atan2((attack_distance*tan(mark_pitch*PI/180)-real_hit_point.y), attack_distance)); // } - -// yaw_rotation = static_cast(180 / PI * atan2((ATTACK_DISTANCE*tan(3.5*PI/180)-STRETCH*(hit_point.x-cycle_center.x)), ATTACK_DISTANCE)); -// pitch_rotation = static_cast(180 / PI * atan2((ATTACK_DISTANCE*tan(9.1*PI/180)-STRETCH*(hit_point.y-cycle_center.y)), ATTACK_DISTANCE)); -// cout<<"cur: "<200)all_armor_centers.clear(); // if(first_armor_centers.size()>200)first_armor_centers.clear(); @@ -30,7 +30,7 @@ int Energy::run(cv::Mat &src){ // imshow("img_preprocess",src); 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); @@ -54,7 +54,10 @@ int Energy::run(cv::Mat &src){ // cycle_center = cv::Point(335, 246); // radius = 116.936; - attack_distance = ATTACK_DISTANCE * 120/ radius; +// attack_distance = ATTACK_DISTANCE * 120/ radius; + + attack_distance = 794 + 1245 * 75 * (1/radius - 1/113.9); +// cout << "attack distance: " << attack_distance << endl; getFanPosition(fanPosition, fans, cycle_center, radius); getArmorPosition(armorPosition, armors, cycle_center, radius); diff --git a/main.cpp b/main.cpp index 82aaa44..d851c79 100644 --- a/main.cpp +++ b/main.cpp @@ -37,7 +37,7 @@ void uartReceive(Serial *uart); int main(int argc, char *argv[]) { process_options(argc, argv); - Serial uart(115200); + Serial uart(115200); thread receive(uartReceive, &uart); bool flag = true; diff --git a/others/energy.Config b/others/energy.Config index 327ec1d..a4e571f 100644 --- a/others/energy.Config +++ b/others/energy.Config @@ -1,4 +1,4 @@ -create_time = "2019-05-14 19:59:50"; +create_time = "2019-05-14 20:21:31"; internal_id = "E7FCFFE8999B"; resolution : { diff --git a/others/include/camera/camera_define.h b/others/include/camera/camera_define.h index c8f880c..e06b8b3 100644 --- a/others/include/camera/camera_define.h +++ b/others/include/camera/camera_define.h @@ -14,21 +14,22 @@ typedef unsigned int UINT; typedef unsigned long long UINT64; typedef int BOOL; typedef unsigned char BYTE; -typedef unsigned int DWORD; +#define DWORD unsigned int typedef void* PVOID; -typedef void* HWND; -typedef char* LPCTSTR; +#define HWND typedef void* +#define LPCTSTR char* typedef unsigned short USHORT; typedef short SHORT; typedef unsigned char* LPBYTE; typedef char CHAR; -typedef short WORD; -typedef INT HANDLE; -typedef void VOID; +#define WORD short +#define HANDLE INT +#define VOID void typedef unsigned long ULONG; -typedef void** LPVOID; +#define LPVOID void** typedef unsigned char UCHAR; -typedef void* HMODULE; +#define HMODULE void* + #define TRUE 1 diff --git a/others/src/camera/camera_wrapper.cpp b/others/src/camera/camera_wrapper.cpp index e20cec0..8fa3ac9 100644 --- a/others/src/camera/camera_wrapper.cpp +++ b/others/src/camera/camera_wrapper.cpp @@ -72,28 +72,9 @@ bool CameraWrapper::init() { return false; } LOGM("successfully loaded %s!", filepath); -/* if(mode == 0){ - // 不使用自动曝光 - CameraSetAeState(h_camera, false); - // 曝光时间10ms - CameraSetExposureTime(h_camera, 10000); - double t; - CameraGetExposureTime(h_camera, &t); - LOGM("Exposure time: %lfms", t/1000.0); - // 模拟增益4 - CameraSetAnalogGain(h_camera, 64); - // 使用预设LUT表 - CameraSetLutMode(h_camera, LUTMODE_PRESET); - // 抗频闪 -// CameraSetAntiFlick(h_camera, true); - } - else if(mode == 1){ - // 不使用自动曝光 - CameraSetAeState(h_camera, false); - // 抗频闪 -// CameraSetAntiFlick(h_camera, true); - } -*/ + double t; + CameraGetExposureTime(h_camera, &t); + LOGM("Exposure time: %lfms", t / 1000.0); /*让SDK进入工作模式,开始接收来自相机发送的图像 数据。如果当前相机是触发模式,则需要接收到 触发帧以后才会更新图像。 */ diff --git a/others/src/serial/serial.cpp b/others/src/serial/serial.cpp index bad7aae..d714ea6 100644 --- a/others/src/serial/serial.cpp +++ b/others/src/serial/serial.cpp @@ -42,12 +42,12 @@ bool Serial::openPort(UINT portNo) { char szPort[50]; sprintf_s(szPort, "COM%d", portNo); - /** ָĴ */ - hComm = CreateFileA(szPort, /** 豸,COM1,COM2 */ - GENERIC_READ | GENERIC_WRITE, /** ģʽ,ͬʱд */ - 0, /** ģʽ,0ʾ */ - NULL, /** ȫ,һʹNULL */ - OPEN_EXISTING, /** òʾ豸,򴴽ʧ */ + /** 打开指定的串口 */ + hComm = CreateFileA(szPort, /** 设备名,COM1,COM2等 */ + GENERIC_READ | GENERIC_WRITE, /** 访问模式,可同时读写 */ + 0, /** 共享模式,0表示不共享 */ + NULL, /** 安全性设置,一般使用NULL */ + OPEN_EXISTING, /** 该参数表示设备必须存在,否则创建失败 */ 0, 0); @@ -55,7 +55,7 @@ bool Serial::openPort(UINT portNo) { } void Serial::ClosePort() { - /** дڱ򿪣ر */ + /** 如果有串口被打开,关闭它 */ if (hComm != INVALID_HANDLE_VALUE) { CloseHandle(hComm); hComm = INVALID_HANDLE_VALUE; @@ -63,7 +63,7 @@ void Serial::ClosePort() { } bool Serial::InitPort(UINT portNo, UINT baud, char parity, UINT databits, UINT stopsbits, DWORD dwCommEvents) { - /** ʱ,ƶתΪַʽ,ԹDCBṹ */ + /** 临时变量,将制定参数转化为字符串形式,以构造DCB结构 */ char szDCBparam[50]; sprintf_s(szDCBparam, "baud=%d parity=%c data=%d stop=%d", baud, parity, databits, stopsbits); @@ -87,40 +87,40 @@ bool Serial::InitPort(UINT portNo, UINT baud, char parity, UINT databits, UINT DCB dcb; if (bIsSuccess) { - /** ȡǰò,ҹ촮DCB */ + /** 获取当前串口配置参数,并且构造串口DCB参数 */ bIsSuccess = GetCommState(hComm, &dcb); bIsSuccess = BuildCommDCB(szDCBparam, &dcb); if (!bIsSuccess) { cout << "Create dcb fail with "<< GetLastError() << endl; } - /** RTS flow */ + /** 开启RTS flow控制 */ dcb.fRtsControl = RTS_CONTROL_ENABLE; } if (bIsSuccess) { - /** ʹDCBô״̬ */ + /** 使用DCB参数配置串口状态 */ bIsSuccess = SetCommState(hComm, &dcb); if (!bIsSuccess) { cout << "SetCommState error!" << endl; } } - /** մڻ */ + /** 清空串口缓冲区 */ PurgeComm(hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT); return bIsSuccess; } UINT Serial::GetBytesInCOM() const { - DWORD dwError = 0; /** */ - COMSTAT comstat; /** COMSTATṹ,¼ͨ豸״̬Ϣ */ + DWORD dwError = 0; /** 错误码 */ + COMSTAT comstat; /** COMSTAT结构体,记录通信设备的状态信息 */ memset(&comstat, 0, sizeof(COMSTAT)); UINT BytesInQue = 0; - /** ڵReadFileWriteFile֮ǰ,ͨǰĴ־ */ + /** 在调用ReadFile和WriteFile之前,通过本函数清除以前遗留的错误标志 */ if (ClearCommError(hComm, &dwError, &comstat)) { - BytesInQue = comstat.cbInQue; /** ȡ뻺еֽ */ + BytesInQue = comstat.cbInQue; /** 获取在输入缓冲区中的字节数 */ } return BytesInQue; @@ -132,13 +132,13 @@ bool Serial::WriteData(const unsigned char* pData, unsigned int length) { return false; } - /** 򻺳дָ */ + /** 向缓冲区写入指定量的数据 */ BOOL bResult = TRUE; DWORD BytesToSend = 0; bResult = WriteFile(hComm, pData, length, &BytesToSend, NULL); if (!bResult) { DWORD dwError = GetLastError(); - /** մڻ */ + /** 清空串口缓冲区 */ PurgeComm(hComm, PURGE_RXCLEAR | PURGE_RXABORT); ErrorHandler(); return false; @@ -152,17 +152,17 @@ bool Serial::ReadData(unsigned char *buffer, unsigned int length) { return false; } - /** ӻȡlengthֽڵ */ + /** 从缓冲区读取length字节的数据 */ BOOL bResult = TRUE; DWORD totalRead = 0, onceRead = 0; while (totalRead < length) { bResult = ReadFile(hComm, buffer, length-totalRead, &onceRead, NULL); totalRead += onceRead; if ((!bResult)) { - /** ȡ,Ըݸôԭ */ + /** 获取错误码,可以根据该错误码查出错误原因 */ DWORD dwError = GetLastError(); - /** մڻ */ + /** 清空串口缓冲区 */ PurgeComm(hComm, PURGE_RXCLEAR | PURGE_RXABORT); ErrorHandler(); return false; @@ -265,17 +265,17 @@ int Serial::set_opt(int fd, int nSpeed, char nEvent, int nBits, int nStop) { } switch (nEvent) { - case 'O': //У + case 'O': //奇校验 newtio.c_cflag |= PARENB; newtio.c_cflag |= PARODD; newtio.c_iflag |= (INPCK | ISTRIP); break; - case 'E': //żУ + case 'E': //偶校验 newtio.c_iflag |= (INPCK | ISTRIP); newtio.c_cflag |= PARENB; newtio.c_cflag &= ~PARODD; break; - case 'N': //У + case 'N': //无校验 newtio.c_cflag &= ~PARENB; break; default:break;