Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

串口 (#1) #2

Open
wants to merge 7 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 41 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,43 @@ include_directories(${OpenCV_INCLUDE_DIRS})
link_libraries(${OpenCV_LIBS})

#CUDA
#find_package(CUDA)
#if (${CUDA_FOUND})
# set(CUDA_SOURCE_PROPERTY_FORMAT OBJ)
# set(CUDA_SEPARABLE_COMPILATION ON)
# include_directories(${CUDA_INCLUDE_DIRS})
# set(CUDA_PROPAGATE_HOST_FLAGS OFF)
# set(CUDA_NVCC_FLAGS -gencode arch=compute_20,code=sm_20;-G;-g)#根据具体GPU更改参数
# #arch=compute_30,code=sm_30
# #arch=compute_35,code=sm_35
# #arch=compute_50,code=[sm_50,compute_50]
# #arch=compute_52,code=[sm_52,compute_52]
# #SET(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_61,code=sm_61;-std=c++11;-O3;-G;-g)
# link_directories($ENV{CUDA_PATH}/lib/x64)
# CUDA_ADD_EXECUTABLE(cv_2022 ${CURRENT_HEADERS} ${CURRENT_SOURCES})
#else (${CUDA_FOUND})
# MESSAGE(STATUS "Skip CUDA!")
#endif (${CUDA_FOUND})
find_package(CUDA)
if (${CUDA_FOUND})
set(CUDA_SOURCE_PROPERTY_FORMAT OBJ)
set(CUDA_SEPARABLE_COMPILATION ON)
include_directories(${CUDA_INCLUDE_DIRS})
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
set(CUDA_NVCC_FLAGS -gencode arch=compute_20,code=sm_20;-G;-g)#根据具体GPU更改参数
#arch=compute_30,code=sm_30
#arch=compute_35,code=sm_35
#arch=compute_50,code=[sm_50,compute_50]
#arch=compute_52,code=[sm_52,compute_52]
#SET(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_61,code=sm_61;-std=c++11;-O3;-G;-g)
link_directories($ENV{CUDA_PATH}/lib/x64)
CUDA_ADD_EXECUTABLE(cv_2022 ${CURRENT_HEADERS} ${CURRENT_SOURCES})
else (${CUDA_FOUND})
MESSAGE(STATUS "Skip CUDA!")
endif (${CUDA_FOUND})

if (WIN32)
file(GLOB CURRENT_HEADERS Inc/*.h Inc/*.hpp Inc/*.cuh)
file(GLOB CURRENT_SOURCES Src/*.cpp Src/*.cu)
include_directories(win-unix/)
file(GLOB WIN_UNIX win-unix/*.h win-unix/*.hpp)
else()
file(GLOB CURRENT_HEADERS Inc/*.h Inc/*.hpp Inc/*.cuh)
file(GLOB CURRENT_SOURCES Src/*.cpp Src/*.cu)
endif()
source_group("Include" FILES ${CURRENT_HEADERS})
source_group("Source" FILES ${CURRENT_SOURCES})
#if (WIN32)
# file(GLOB CURRENT_HEADERS Inc/*.h Inc/*.hpp Inc/*.cuh)
# file(GLOB CURRENT_SOURCES Src/*.cpp Src/*.cu)
# include_directories(win-unix/)
# file(GLOB WIN_UNIX win-unix/*.h win-unix/*.hpp)
#else()
# file(GLOB CURRENT_HEADERS Inc/*.h Inc/*.hpp Inc/*.cuh)
# file(GLOB CURRENT_SOURCES Src/*.cpp Src/*.cu)
#endif()
#source_group("Include" FILES ${CURRENT_HEADERS})
#source_group("Source" FILES ${CURRENT_SOURCES})
#
#include_directories(./)
#include_directories(Inc/)
#include_directories(Src/)
#
#add_executable(cv_test main.cpp ${CURRENT_HEADERS} ${CURRENT_SOURCES} ${WIN_UNIX})

#---------------------TEST---------------------
include_directories(./)
include_directories(Inc/)
include_directories(Src/)
Expand All @@ -54,36 +61,17 @@ aux_source_directory(Lib/libv4l2_opencv_mat/src libv4l2_SRC_FILES)
add_library(libv4l2 STATIC ${libv4l2_SRC_FILES})
target_include_directories(libv4l2 PUBLIC "Lib/libv4l2_opencv_mat/inc")

add_library(WzSerialPortPlus STATIC Lib/WzSerialPortPlus/WzSerialPortPlus.cpp )
add_library(WzSerialPortPlus STATIC Lib/WzSerialPortPlus/WzSerialPortPlus.cpp)
target_include_directories(WzSerialPortPlus PUBLIC "Lib/WzSerialPortPlus")


add_executable(cv_test ${CURRENT_HEADERS} ${CURRENT_SOURCES} ${WIN_UNIX})
set(SRC Src/armour.cpp Src/new_uart_thread_init.cpp Src/led.cpp Src/kalman.cpp)
set(INC Inc/armour.h Inc/new_uart_thread_init.h Inc/led.h Inc/kalman.h)
add_executable(cv_test ${SRC} ${INC})
target_link_libraries(cv_test libv4l2)
target_link_libraries(cv_test WzSerialPortPlus)

#---------------------TEST---------------------
#include_directories(./)
#include_directories(Inc/)
#include_directories(Src/)
#
#aux_source_directory(Lib/libv4l2_opencv_mat/src libv4l2_SRC_FILES)
#add_library(libv4l2 STATIC ${libv4l2_SRC_FILES})
#target_include_directories(libv4l2 PUBLIC "Lib/libv4l2_opencv_mat/inc")
#
#add_library(WzSerialPortPlus STATIC Lib/WzSerialPortPlus/WzSerialPortPlus.cpp )
#target_include_directories(WzSerialPortPlus PUBLIC "Lib/WzSerialPortPlus")
#
#set(SRC Src/armour.cpp Src/led.cpp Src/kalman.cpp )
#set(INC Inc/armour.h Inc/led.h Inc/kalman.h )
##set(SRC Src/armour.cpp Src/led.cpp Src/kalman.cpp Src/serial.cpp)
##set(INC Inc/armour.h Inc/led.h Inc/kalman.h Inc/serial.h)
#add_executable(cv_test ${SRC} ${INC} Src/serial.cpp Inc/serial.h)
#target_link_libraries(cv_test libv4l2 WzSerialPortPlus)
#
##target_link_libraries(cv_test WzSerialPortPlus)
#target_link_libraries(cv_test WzSerialPortPlus)
#---------------------END----------------------

#!
add_executable(test_lib main.cpp Src/serial.cpp Inc/serial.h)
add_executable(test_lib main.cpp)
target_link_libraries(test_lib WzSerialPortPlus)
8 changes: 5 additions & 3 deletions Inc/armour.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ using namespace cv;

#endif

//#include "new_uart_thread_init.h"
#include "serial.h"
#include "new_uart_thread_init.h"
#include "led.h"
#include "kalman.h"
#include "BufWu.h"
Expand All @@ -53,7 +52,6 @@ enum MODE_FLAG {
MODE_NONE = 0,
MODE_RED = 1,
MODE_BLUE = 2

};

struct combine_rect_height {
Expand All @@ -63,6 +61,8 @@ struct combine_rect_height {

extern int CMD_COLOR;

static pos_data data_send;

class armour {
public:
double cost_time;
Expand Down Expand Up @@ -105,6 +105,8 @@ class armour {

Mat HSV_to_gray(const Mat &, int, int, int, int, int, int, int);

auto judgeColor(const Mat &src_image);

void fire(Mat &);

vector<vector<Point> > judge_the_min_distance(const Mat &, const vector<vector<Point> > &, double, double);
Expand Down
5 changes: 3 additions & 2 deletions Inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#define IMAGE_WIDTH 3264
#define IMAGE_HEIGHT 2448
#define FPS 30
#define SERIAL_PORT "/dev/ttyUSB0"
#define SERIAL_BAUDRATE 115200

// 1: red, 2: blue
#define BEAT_COLOR 1

#endif //CV_TEST_CONFIG_H
5 changes: 2 additions & 3 deletions Inc/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
#include <linux/fs.h> //ÓëÉ豞Çý¶¯³ÌÐòÓйØ
#include <fcntl.h> //žÄ±äÒÑŽò¿ªµÄÎÄŒþÐÔÖÊ
#include <cstring>
#include <termios.h>
#include <termios.h> //²ÎÊýÉèÖÃ
#include <cerrno>
#include <iostream>
//#include "new_uart_thread_init.h"
#include "serial.h"
#include "new_uart_thread_init.h"

using namespace std;

Expand Down
62 changes: 62 additions & 0 deletions Inc/new_uart_2stm32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef _NEW_UART_2STM32
#define _NEW_UART_2STM32
/*<inttypes.h>:
#pragma pack(8):
*/
#include <cinttypes>
#include <cstdio>
#include <cstring>
#include <cstdlib>

typedef struct {

uint8_t Head;
uint8_t CmdID;
uint16_t Datalength;

}__attribute__((packed, aligned(1))) Frame_hearder;

typedef struct {

int32_t x;
int32_t y;
int32_t z;
int32_t Time_Interval;
uint8_t Goal_State;

}__attribute__((packed, aligned(1))) Armour_MOD;
typedef struct {

uint8_t Mod_set_over;

}__attribute__((packed, aligned(1))) Reply_MOD;

typedef struct {

float x;
float y;
float z;
uint8_t Target_state;


}__attribute__((packed, aligned(1))) Power_MOD;
typedef struct {

uint8_t Target_state;

}__attribute__((packed, aligned(1))) Error_MOD;
//ÊÓŸõÊýŸÝœá¹¹
typedef struct {
Frame_hearder FH_data;
union {
Armour_MOD Ar_data;
Reply_MOD Re_data;
Power_MOD PW_data;
Error_MOD Err_data;
} Data;
uint16_t CRC16;
}__attribute__((packed, aligned(1))) Date_message;

void send_message_AR(float xdata, float ydata, float zdata, float tdata, uint8_t Cmdata);

#endif
59 changes: 59 additions & 0 deletions Inc/new_uart_thread_init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef _NEW_UART_THREAD_INIT_H
#define _NEW_UART_THREAD_INIT_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/ioctl.h>
#include <termios.h>
#include <math.h>
#include <pthread.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <errno.h>
#include <math.h>
#include <unistd.h>
#include <sys/time.h>

#include "new_uart_2stm32.h"

#define BUFF_REPEAT 1
#define BUFF_UNREPEAT 2
#define BUFF_CENTER 3
#define BUFF_UNCENTER 4

#define BEGIN_LED 1
#define BLUE_LED 2
#define RED_LED 3
//²Ëµ¥×÷ΪѡÏî
enum {
MOD_NULL = 0,
MOD_RED, //ºì·½
MOD_BLUE, //À¶·½
MOD_POWER_BIG, //´ò´ó·ù
MOD_POWER_SMALL,//С·û
MOD_AUTO, //×Ô¶¯´ò»÷
};
/*====send the mesage====*/
//void send_message_PW(float xdata, float ydata, float zdata, uint8_t Cmdata);
void send_message_AR(float xdata, float ydata, float zdata, float tdata, uint8_t Cmdata);
//void send_message_VR( uint8_t Cmdata);
//void send_message_ER(uint8_t Cmdata);
/*=====the thread====*/
void *thread_read(void *arg);

void *thread_write(void *arg);
//void *thread_video(void * arg);
//void *thread_led(void *arg);
/*===== uart =====*/
int INIT_UART();

int UART_WRITE_DATA(char *data, int data_sizeof);


#endif/*end the init*/

58 changes: 0 additions & 58 deletions Inc/serial.h

This file was deleted.

Loading