Merge remote-tracking branch 'origin/master'

This commit is contained in:
xinyang
2019-07-25 12:48:26 +08:00
12 changed files with 43 additions and 29 deletions

View File

@@ -16,7 +16,7 @@ static bool sendTarget(Serial &serial, double x, double y, double z, uint16_t sh
time_t t = time(nullptr);
if (last_time != t) {
last_time = t;
cout << "fps:" << fps << ", (" << x << "," << y << "," << z << ")" << endl;
cout << "Armor: fps:" << fps << ", (" << x << "," << y << "," << z << ")" << endl;
fps = 0;
}
fps += 1;

View File

@@ -37,7 +37,7 @@ public:
void setSmallEnergyInit();//设置小能量机关初始化
void sendEnergy();//发送能量机关数据
void sendTarget(Serial& serial, float x, float y, float z);//发送数据
void sendTarget(Serial& serial, float x, float y, float z, uint16_t u);//发送数据
void sendTarget(Serial& serial, float x, float y, uint16_t z, uint16_t u);//发送数据
private:

View File

@@ -2,6 +2,7 @@
// Created by xixiliadorabarry on 1/24/19.
//
#include "energy/energy.h"
#include "log.h"
using namespace cv;
using std::cout;
@@ -151,8 +152,8 @@ bool Energy::findCenterR(const cv::Mat src) {
// cout << cur_rect.center << endl;
return true;
}
cout << "find center R false!" << endl;
// cv::waitKey(0);
if (show_info)cout << "find center R false!" << endl;
// cv::waitKey(0);
return false;
}
@@ -198,7 +199,7 @@ bool Energy::findFlowStripFan(const cv::Mat src) {
}
// cout << "flow_strip_fans_cnt: " << flow_strip_fans.size() << endl;
if (flow_strip_fans.empty()) {
cout << "flow strip fan false!" << endl;
if (show_info)cout << "flow strip fan false!" << endl;
return false;
} else {
return true;
@@ -266,11 +267,11 @@ bool Energy::findFlowStrip(const cv::Mat src) {
}
// cout << "flow strip cnt: " << flow_strips.size() << endl;
if (flow_strips.empty()) {
cout << "flow strip false!" << endl;
if (show_info)cout << "flow strip false!" << endl;
// waitKey(0);
return false;
} else if (flow_strips.size() > 1) {
cout << "Too many flow strips!" << endl;
if (show_info)cout << "Too many flow strips!" << endl;
// waitKey(0);
return false;
} else {

View File

@@ -1,7 +1,9 @@
//
// Created by xixiliadorabarry on 1/24/19.
//
#include "energy/energy.h"
#include "log.h"
using namespace cv;
using std::cout;
@@ -67,7 +69,7 @@ bool Energy::findTargetInFlowStripFan() {
}
// cout << "target armor cnt: " << target_armors.size() << endl;
if (target_armors.empty()) {
cout << "find target armor false" << endl;
if (show_info)cout << "find target armor false" << endl;
return false;
} else {
return true;

View File

@@ -21,5 +21,6 @@ void Energy::getAimPoint(cv::Point target_point) {
pitch_rotation = atan(dy / FOCUS_PIXAL) * 180 / PI;
// cout << "yaw: " << yaw_rotation << '\t' << "pitch: " << pitch_rotation << endl;
// cout << "mcuData.delta_x: " << mcuData.delta_x << '\t' << "mcuData.delta_y: " << mcuData.delta_y << endl;
// cout << "manual delta: " << manual_delta_x << '\t' << manual_delta_y << endl;
}

View File

@@ -12,7 +12,7 @@ using namespace cv;
// 此函数用于记录操作手的微调dx和dy
// ---------------------------------------------------------------------------------------------------------------------
void Energy::writeDownSlightChange(cv::Mat &src) {
if (findFans(src) == 4){
if (findFans(src) >= 4) {
FILE *fp_delta = fopen(PROJECT_DIR"/Mark/delta.txt", "w");
if (fp_delta) {
fprintf(fp_delta, "delta_x: %d, delta_y: %d\n", mcuData.delta_x, mcuData.delta_y);

View File

@@ -28,11 +28,11 @@ void Energy::sendEnergy() {
}
if (change_target) {
sendTarget(serial, yaw_rotation, pitch_rotation, 5);
sendTarget(serial, yaw_rotation, pitch_rotation, 5, 0);
} else if (is_guessing) {
sendTarget(serial, yaw_rotation, pitch_rotation, 6);
sendTarget(serial, yaw_rotation, pitch_rotation, 6, 0);
} else {
sendTarget(serial, yaw_rotation, pitch_rotation, shoot);
sendTarget(serial, yaw_rotation, pitch_rotation, shoot, 0);
}
}
@@ -51,7 +51,7 @@ void Energy::sendTarget(Serial &serial, float x, float y, float z) {
time_t t = time(nullptr);
if (last_time != t) {
last_time = t;
// cout << "fps:" << fps << ", (" << x << "," << y << "," << z << ")" << endl;
cout << "Energy: fps:" << fps << ", (" << x << "," << y << "," << z << ")" << endl;
fps = 0;
}
fps += 1;
@@ -77,7 +77,7 @@ void Energy::sendTarget(Serial &serial, float x, float y, float z) {
//----------------------------------------------------------------------------------------------------------------------
// 此函数用于发送数据给主控板
// ---------------------------------------------------------------------------------------------------------------------
void Energy::sendTarget(Serial &serial, float x, float y, float z, uint16_t u) {
void Energy::sendTarget(Serial &serial, float x, float y, uint16_t z, uint16_t u) {
short x_tmp, y_tmp, z_tmp;
uint8_t buff[10];
@@ -87,7 +87,7 @@ void Energy::sendTarget(Serial &serial, float x, float y, float z, uint16_t u) {
time_t t = time(nullptr);
if (last_time != t) {
last_time = t;
cout << "fps:" << fps << ", (" << x << "," << y << "," << z << ")" << endl;
cout << "Energy: fps:" << fps << ", (" << x << "," << y << "," << z << "," << u << ")" << endl;
fps = 0;
}
fps += 1;
@@ -95,14 +95,13 @@ void Energy::sendTarget(Serial &serial, float x, float y, float z, uint16_t u) {
x_tmp = static_cast<short>(x * (32768 - 1) / 100);
y_tmp = static_cast<short>(y * (32768 - 1) / 100);
z_tmp = static_cast<short>(z * (32768 - 1) / 100);
buff[0] = 's';
buff[1] = static_cast<char>((x_tmp >> 8) & 0xFF);
buff[2] = static_cast<char>((x_tmp >> 0) & 0xFF);
buff[3] = static_cast<char>((y_tmp >> 8) & 0xFF);
buff[4] = static_cast<char>((y_tmp >> 0) & 0xFF);
buff[5] = static_cast<char>((z_tmp >> 8) & 0xFF);
buff[6] = static_cast<char>((z_tmp >> 0) & 0xFF);
buff[5] = static_cast<char>((z >> 8) & 0xFF);
buff[6] = static_cast<char>((z >> 0) & 0xFF);
buff[7] = static_cast<char>((u >> 8) & 0xFF);
buff[8] = static_cast<char>((u >> 0) & 0xFF);;
buff[9] = 'e';

View File

@@ -30,7 +30,7 @@ using namespace std;
mcu_data mcuData = { // 单片机端回传结构体
0, // 当前云台yaw角
0, // 当前云台pitch角
BIG_ENERGY_STATE, // 当前状态,自瞄-大符-小符
ARMOR_STATE, // 当前状态,自瞄-大符-小符
0, // 云台角度标记位
1, // 是否启用数字识别
ENEMY_RED, // 敌方颜色
@@ -96,8 +96,9 @@ int main(int argc, char *argv[]) {
// CNT_TIME("Total", {
if (mcuData.state == BIG_ENERGY_STATE) {//大能量机关模式
if (last_state != BIG_ENERGY_STATE) {//若上一帧不是大能量机关模式,即刚往完成切换,则需要初始化
LOGM(STR_CTR(WORD_BLUE, "Start Big Energy!"));
destroyAllWindows();
if(from_camera){
if (from_camera) {
delete video_gimbal;
video_gimbal = new CameraWrapper(ENERGY_CAMERA_GAIN, 0/*, "armor"*/);
if (video_gimbal->init()) {
@@ -109,6 +110,7 @@ int main(int argc, char *argv[]) {
checkReconnect(video_chassis->read(chassis_src));
energy.setBigEnergyInit();
}
last_state = mcuData.state;//更新上一帧状态
ok = checkReconnect(video_gimbal->read(gimbal_src));
video_chassis->read(chassis_src);
#ifdef GIMBAL_FLIP_MODE
@@ -120,13 +122,13 @@ int main(int argc, char *argv[]) {
if (!from_camera) extract(gimbal_src, chassis_src);
if (save_video) saveVideos(gimbal_src, chassis_src);//保存视频
if (show_origin) showOrigin(gimbal_src, chassis_src);//显示原始图像
// energy.runBig(gimbal_src, chassis_src);
energy.runBig(gimbal_src);
last_state = mcuData.state;//更新上一帧状态
energy.runBig(gimbal_src, chassis_src);
// energy.runBig(gimbal_src);
} else if (mcuData.state == SMALL_ENERGY_STATE) {
if (mcuData.state != SMALL_ENERGY_STATE) {
if (last_state != SMALL_ENERGY_STATE) {
LOGM(STR_CTR(WORD_GREEN, "Start Small Energy!"));
destroyAllWindows();
if(from_camera){
if (from_camera) {
delete video_gimbal;
video_gimbal = new CameraWrapper(ENERGY_CAMERA_GAIN, 0/*, "armor"*/);
if (video_gimbal->init()) {
@@ -137,6 +139,7 @@ int main(int argc, char *argv[]) {
}
energy.setSmallEnergyInit();
}
last_state = mcuData.state;//更新上一帧状态
ok = checkReconnect(video_gimbal->read(gimbal_src));
#ifdef GIMBAL_FLIP_MODE
flip(gimbal_src, gimbal_src, GIMBAL_FLIP_MODE);
@@ -145,11 +148,11 @@ int main(int argc, char *argv[]) {
if (save_video) saveVideos(gimbal_src);//保存视频
if (show_origin) showOrigin(gimbal_src);//显示原始图像
energy.runSmall(gimbal_src);
last_state = mcuData.state;//更新上一帧状态
} else { // 自瞄模式
if (last_state != ARMOR_STATE) {
LOGM(STR_CTR(WORD_RED, "Start Armor!"));
destroyAllWindows();
if(from_camera){
if (from_camera) {
delete video_gimbal;
video_gimbal = new CameraWrapper(ARMOR_CAMERA_GAIN, 0/*, "armor"*/);
if (video_gimbal->init()) {

View File

@@ -29,7 +29,7 @@
#define ARMOR_CAMERA_GAIN (30)
#endif
#ifndef ENERGY_CAMERA_GAIN
#define ENERGY_CAMERA_GAIN (20)
#define ENERGY_CAMERA_GAIN (30)
#endif
#ifndef AIM_KP
#define AIM_KP (6)

View File

@@ -18,6 +18,7 @@ extern bool save_labelled_boxes;
extern bool show_process;
extern bool show_energy;
extern bool save_mark;
extern bool show_info;
void process_options(int argc, char *argv[]);

Binary file not shown.

View File

@@ -17,6 +17,7 @@ bool save_labelled_boxes = false;
bool show_process = false;
bool show_energy = false;
bool save_mark = false;
bool show_info = false;
void process_options(int argc, char *argv[]) {
if (argc >= 2) {
@@ -54,6 +55,8 @@ void process_options(int argc, char *argv[]) {
LOGM("Enable show processed image");
show_energy = true;
LOGM("Enable show energy part");
show_info = true;
LOGM("Show information!");
} else if (strcmp(argv[i], "--run-with-camera") == 0) {
run_with_camera = true;
LOGM("Run with camera!");
@@ -70,14 +73,18 @@ void process_options(int argc, char *argv[]) {
show_process = true;
LOGM("Enable show processed image!");
} else if (strcmp(argv[i], "--show-energy") == 0) {
show_energy= true;
show_energy = true;
LOGM("Enable show energy part!");
} else if (strcmp(argv[i], "--save-mark") == 0) {
save_mark = true;
LOGM("Write down mark");
} else if (strcmp(argv[i], "--show-info") == 0) {
show_info = true;
LOGM("Show information!");
} else {
LOGW("Unknown option: %s. Use --help to see options.", argv[i]);
}
}
}
}