使用命令行参数
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
|
|||||||
|
|
||||||
project(auto-aim)
|
project(auto-aim)
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
SET(CMAKE_BUILD_TYPE DEBUG)
|
SET(CMAKE_BUILD_TYPE RELEASE)
|
||||||
|
|
||||||
FIND_PROGRAM(CCACHE_FOUND ccache)
|
FIND_PROGRAM(CCACHE_FOUND ccache)
|
||||||
IF(CCACHE_FOUND)
|
IF(CCACHE_FOUND)
|
||||||
|
|||||||
39
main.cpp
39
main.cpp
@@ -1,11 +1,8 @@
|
|||||||
//
|
//
|
||||||
// Created by xixiliadorabarry on 1/24/19.
|
// Created by xixiliadorabarry on 1/24/19.
|
||||||
//
|
//
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <opencv2/core/core.hpp>
|
#include <opencv2/core/core.hpp>
|
||||||
#include <opencv2/highgui/highgui.hpp>
|
|
||||||
#include <opencv2/imgproc/imgproc.hpp>
|
|
||||||
|
|
||||||
#include "energy/energy.h"
|
#include "energy/energy.h"
|
||||||
#include "include/uart/uart.h"
|
#include "include/uart/uart.h"
|
||||||
@@ -18,7 +15,6 @@
|
|||||||
#include <options/options.h>
|
#include <options/options.h>
|
||||||
#include <log.h>
|
#include <log.h>
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
@@ -27,8 +23,8 @@ using namespace std;
|
|||||||
#define ENERGY_STATE 1
|
#define ENERGY_STATE 1
|
||||||
#define ARMOR_STATE 0
|
#define ARMOR_STATE 0
|
||||||
|
|
||||||
int state = ENERGY_STATE;
|
int state = ARMOR_STATE;
|
||||||
float yaw, pitch;
|
float yaw=0, pitch=0;
|
||||||
|
|
||||||
void uartReceive(Uart* uart);
|
void uartReceive(Uart* uart);
|
||||||
|
|
||||||
@@ -36,8 +32,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
process_options(argc, argv);
|
process_options(argc, argv);
|
||||||
Uart uart;
|
Uart uart;
|
||||||
|
thread receive(uartReceive, &uart);
|
||||||
bool flag = true;
|
bool flag = true;
|
||||||
short done = 0;//用于检测是否已经读完初始激光中心时的角度
|
|
||||||
|
|
||||||
while (flag)
|
while (flag)
|
||||||
{
|
{
|
||||||
@@ -60,7 +56,7 @@ int main(int argc, char *argv[])
|
|||||||
cout << "Video source initialization successfully." << endl;
|
cout << "Video source initialization successfully." << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat src, src_none;
|
Mat energy_src, armor_src;
|
||||||
|
|
||||||
ArmorFinder armorFinder(ENEMY_BLUE, uart);
|
ArmorFinder armorFinder(ENEMY_BLUE, uart);
|
||||||
|
|
||||||
@@ -68,26 +64,16 @@ int main(int argc, char *argv[])
|
|||||||
energy.setAllyColor(ally_color);
|
energy.setAllyColor(ally_color);
|
||||||
energy.setRotation(energy_part_rotation);
|
energy.setRotation(energy_part_rotation);
|
||||||
|
|
||||||
static thread receive(uartReceive, &uart);
|
while (video->read(energy_src, armor_src))
|
||||||
|
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
// if(!from_camera)energy.extract(src);
|
if(show_origin) {
|
||||||
if(state == 1){
|
imshow("enery src", energy_src);
|
||||||
imshow("src", src);
|
imshow("armor src", armor_src);
|
||||||
energy.run(src);
|
}
|
||||||
|
if(state == ENERGY_STATE){
|
||||||
|
energy.run(energy_src);
|
||||||
}else{
|
}else{
|
||||||
armorFinder.run(src_none);
|
armorFinder.run(armor_src);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waitKey(1) == 'q') {
|
if (waitKey(1) == 'q') {
|
||||||
@@ -119,6 +105,7 @@ void uartReceive(Uart* uart){
|
|||||||
LOGM("State switch to armor!");
|
LOGM("State switch to armor!");
|
||||||
}else{
|
}else{
|
||||||
sscanf(buffer, "%f %f", &yaw, &pitch);
|
sscanf(buffer, "%f %f", &yaw, &pitch);
|
||||||
|
LOGM("Get yaw:%f pitch:%f", yaw, pitch);
|
||||||
}
|
}
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,13 +159,3 @@ char Uart::receive() {
|
|||||||
return data;
|
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<float>(((Enemy_Info[1]<<8)|(Enemy_Info[2]))*(100.0 / (32768.0 - 1.0)));
|
|
||||||
aim.pitch = static_cast<float>(((Enemy_Info[3]<<8)|(Enemy_Info[4]))*(100.0 / (32768.0 - 1.0)));
|
|
||||||
}
|
|
||||||
else return;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user