From f2fe6c498e3fff673d163eb81b35234da67c7654 Mon Sep 17 00:00:00 2001 From: xinyang Date: Sun, 14 Apr 2019 18:22:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- main.cpp | 39 +++++++++++++-------------------------- src/uart/uart.cpp | 10 ---------- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fadacbf..32751b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5) project(auto-aim) set(CMAKE_CXX_STANDARD 11) -SET(CMAKE_BUILD_TYPE DEBUG) +SET(CMAKE_BUILD_TYPE RELEASE) FIND_PROGRAM(CCACHE_FOUND ccache) IF(CCACHE_FOUND) diff --git a/main.cpp b/main.cpp index 2a35638..93c7cce 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,8 @@ // // Created by xixiliadorabarry on 1/24/19. // -#include #include #include -#include -#include #include "energy/energy.h" #include "include/uart/uart.h" @@ -18,7 +15,6 @@ #include #include -#include #include using namespace cv; @@ -27,8 +23,8 @@ using namespace std; #define ENERGY_STATE 1 #define ARMOR_STATE 0 -int state = ENERGY_STATE; -float yaw, pitch; +int state = ARMOR_STATE; +float yaw=0, pitch=0; void uartReceive(Uart* uart); @@ -36,8 +32,8 @@ int main(int argc, char *argv[]) { process_options(argc, argv); Uart uart; + thread receive(uartReceive, &uart); bool flag = true; - short done = 0;//用于检测是否已经读完初始激光中心时的角度 while (flag) { @@ -60,7 +56,7 @@ int main(int argc, char *argv[]) cout << "Video source initialization successfully." << endl; } - Mat src, src_none; + Mat energy_src, armor_src; ArmorFinder armorFinder(ENEMY_BLUE, uart); @@ -68,26 +64,16 @@ int main(int argc, char *argv[]) energy.setAllyColor(ally_color); energy.setRotation(energy_part_rotation); - static thread receive(uartReceive, &uart); - - if(state==1 && done == 0){ - energy.uart.receive_data(); - done = 1; - } - -// energy.sendTargetByUart(-8,-8,-8); - - - time_t t1 = time(nullptr), t2 = time(nullptr); - - while (video->read(src, src_none)) + while (video->read(energy_src, armor_src)) { -// if(!from_camera)energy.extract(src); - if(state == 1){ - imshow("src", src); - energy.run(src); + if(show_origin) { + imshow("enery src", energy_src); + imshow("armor src", armor_src); + } + if(state == ENERGY_STATE){ + energy.run(energy_src); }else{ - armorFinder.run(src_none); + armorFinder.run(armor_src); } if (waitKey(1) == 'q') { @@ -119,6 +105,7 @@ void uartReceive(Uart* uart){ LOGM("State switch to armor!"); }else{ sscanf(buffer, "%f %f", &yaw, &pitch); + LOGM("Get yaw:%f pitch:%f", yaw, pitch); } cnt = 0; } diff --git a/src/uart/uart.cpp b/src/uart/uart.cpp index c480d89..50c2a0b 100644 --- a/src/uart/uart.cpp +++ b/src/uart/uart.cpp @@ -159,13 +159,3 @@ char Uart::receive() { return data; } - -void Uart::receive_data() { - char Enemy_Info[6] = {0}; - read(fd, &Enemy_Info, 6); - if(Enemy_Info[0]=='s'&&Enemy_Info[5]=='e'){ - aim.yaw = static_cast(((Enemy_Info[1]<<8)|(Enemy_Info[2]))*(100.0 / (32768.0 - 1.0))); - aim.pitch = static_cast(((Enemy_Info[3]<<8)|(Enemy_Info[4]))*(100.0 / (32768.0 - 1.0))); - } - else return; -}