pull/34/head
大耳刮子 3 years ago
parent 23c319bd40
commit 897269e030

@ -33,21 +33,17 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(SOURCES
src/include/qnode.hpp
src/include/joystick.h
src/include/dashboard.h
src/main/main.cpp
src/main/mainwindow.cpp
src/main/qnode.cpp
src/main/joystick.cpp
src/main/dashboard.cpp
src/ui/mainwindow.hpp
src/ui/mainwindow.ui
file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
FOLLOW_SYMLINKS src/include/Air_Ground_CEC/*.hpp *.h)
file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
FOLLOW_SYMLINKS src/*.cpp)
)
QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT5_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT5_WRAP_CPP(QT_MOC_HPP ${QT_MOC})
QT5_add_resources(qrc_Files src/resources/images.qrc)
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
@ -56,7 +52,9 @@ include_directories(
${OpenCV_INCLUDE_DIRS}
)
add_executable(Air_Ground_CEC ${SOURCES} ${qrc_Files})
add_executable(Air_Ground_CEC ${QRC_FILES} ${QT_SOURCES}
${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(Air_Ground_CEC
Qt5::Widgets
${catkin_LIBRARIES}

@ -1,146 +0,0 @@
#include"Djitellowhite.h"
#include<iostream>
#include<opencv2/opencv.hpp>
#include<stdio.h>
#include<sys/socket.h>
#include<string.h>
#include<arpa/inet.h>
#include<sys/types.h>
using namespace cv;
using namespace std;
Tello::Tello(const char* IP) {
this->stream_on=false;
this->host = inet_addr(IP);
cout << "create successfully!" << endl;
}
Tello::~Tello() {}
void Tello::set_conf(int socket){
this->sock = socket;
}
void Tello::get_connect(sockaddr_in serveraddr) {
char tmp[10] = {"command"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "connect successfully!" <<endl;
}
unsigned long Tello::gethost(){
return this->host;
}
void Tello::takeoff(sockaddr_in serveraddr) {
char tmp[10] = {"takeoff"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "takeoff successfully!" <<endl;
}
void Tello::land(sockaddr_in serveraddr) {
char tmp[10] = {"land"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "land successfully!" <<endl;
}
bool Tello::send_message(char* msg,sockaddr_in server_addr,int timeout){
char buffer[BUFFER_SIZE];
memset(buffer,0,sizeof(buffer));
strcpy(buffer,msg);
//cout << buffer;
sendto(this->sock,buffer,strlen(buffer),0,(struct sockaddr *)&server_addr, sizeof(server_addr));
return true;
}
void* Tello::udp_response_receiver(void* arg){
//int m_SockServer; //创建socket对象
//sockaddr_in serveraddr; //创建sockaddr_in对象储存自身信息(当有多个端口,可以多个绑定)
//sockaddr_in serveraddrfrom;
//serveraddr.sin_family = AF_INET; //设置服务器地址家族
//serveraddr.sin_port = htons(8889); //设置服务器端口号
//serveraddr.sin_addr.s_addr = inet_addr("0.0.0.0");
//m_SockServer = socket(AF_INET, SOCK_DGRAM, 0); //创建一个临时变量并赋值给m_SockServer
//int i = bind(m_SockServer, (sockaddr*)&serveraddr, sizeof(serveraddr)); //把名字和套接字绑定
//std::cout << "bind:" << i << std::endl;
int socket = *(int *)arg;
cout << "receive start" << endl;
while(1){
char buffer[20];
int iret;
memset(buffer,0,sizeof(buffer));
iret = recv(socket, buffer,20,MSG_WAITALL);
if(iret > 0 && iret <10){
printf("Message from tello: %s\n", buffer);
}
}
}
void Tello::forward(sockaddr_in serveraddr){
char tmp[15] = {"forward 20"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "forward successfully!" <<endl;
}
void Tello::back(sockaddr_in serveraddr){
char tmp[15] = {"back 20"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "back successfully!" <<endl;
}
void Tello::left(sockaddr_in serveraddr){
char tmp[15] = {"left 20"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "left successfully!" <<endl;
}
void Tello::right(sockaddr_in serveraddr){
char tmp[15] = {"right 20"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "right successfully!" <<endl;
}
void Tello::up(sockaddr_in serveraddr){
char tmp[15] = {"up 20"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "up successfully!" <<endl;
}
void Tello::down(sockaddr_in serveraddr){
char tmp[15] = {"down 20"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "down successfully!" <<endl;
}
void Tello::cw(sockaddr_in serveraddr){
char tmp[15] = {"cw 20"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "cw successfully!" <<endl;
}
void Tello::ccw(sockaddr_in serveraddr){
char tmp[15] = {"ccw 20"};
send_message(tmp,serveraddr,0);// 0 -> timeout
cout << "ccw successfully!" <<endl;
}
void Tello::get_video(sockaddr_in serveraddr){
char tmp[15] = {"streamon"};
send_message(tmp,serveraddr,0);
cout << "stream_on successfully!" <<endl;
this->stream_on = true;
cout << "vid";
VideoCapture cap("udp://@0.0.0.0:11111");
cout << "cap";
if(!cap.isOpened()){
cout << "fuck off";
return;
}
Mat frame;
cout << "continue!";
while(1){
cap>>frame;
if(frame.empty())
break;
imshow("video",frame);
waitKey(20);
}
cap.release();
}

@ -1,80 +0,0 @@
#ifndef _DJITELLOWHITE_H
#define _DJITELLOWHITE_H
#include<iostream>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<pthread.h>
#include<cstring>
#include<unistd.h>
/*Library for interacting with DJI Ryze Tello drones.*/
//coding = utf - 8
/* """C++ wrapper to interact with the Ryze Tello drone using the official Tello api.
Tello API documentation:
[1.3](https://dl-cdn.ryzerobotics.com/downloads/tello/20180910/Tello%20SDK%20Documentation%20EN_1.3.pdf)
*/
#define RESPONSE_TIMEOUT 7 //in seconds
#define TAKEOFF_TIMEOUT 20 //in seconds
#define FRAME_GRAB_TIMEOUT 3
#define TIME_BTW_COMMANDS 0.1 //in seconds
#define TIME_BTW_RC_CONTROL_COMMANDS 0.001 //in seconds
#define RETRY_COUNT 3 //number of retries after a failed command
//Video stream, server socket
#define VS_UDP_IP "0.0.0.0"
#define VS_UDP_PORT 11111
#define CONTROL_UDP_PORT 8889
#define STATE_UDP_PORT 8890
#define BUFFER_SIZE 1024
//Constants for video settings
#define BITRATE_AUTO 0
#define BITRATE_1MBPS 1
#define BITRATE_2MBPS 2
#define BITRATE_3MBPS 3
#define BITRATE_4MBPS 4
#define BITRATE_5MBPS 5
#define RESOLUTION_480P "low"
#define RESOLUTION_720P "high"
#define FPS_5 "low"
#define FPS_15 "middle"
#define FPS_30 "high"
#define CAMERA_FORWARD 0
#define CAMERA_DOWNWARD 1
//日志模块暂时不写
class Tello {
private:
int sock;
bool stream_on;
unsigned long host;
public:
Tello(const char* IP);
~Tello();
void set_conf(int socket);
unsigned long gethost();
void get_connect(sockaddr_in serveraddr);
void takeoff(sockaddr_in serveraddr);
void land(sockaddr_in serveraddr);
void forward(sockaddr_in serveraddr);
void back(sockaddr_in serveraddr);
void left(sockaddr_in serveraddr);
void right(sockaddr_in serveraddr);
void up(sockaddr_in serveraddr);
void down(sockaddr_in serveraddr);
void cw(sockaddr_in serveraddr);
void ccw(sockaddr_in serveraddr);
bool send_message(char* msg,sockaddr_in server_addr,int timeout = RESPONSE_TIMEOUT);
static void *udp_response_receiver(void* arg);
void get_video(sockaddr_in serveraddr);
};
#endif

Binary file not shown.

@ -1,6 +0,0 @@
#ifndef _HARDWARELISTENER_H
#define _HARDWARELISTENER_H
#include "Djitellowhite.h"
int listenkeyboard(Tello T,sockaddr_in serveraddr);
int scanKeyboard();
#endif

@ -1,45 +0,0 @@
#include"Djitellowhite.h"
#include"Hardwarelistener.h"
#include<iostream>
using namespace std;
int main(void){
Tello T("192.168.10.1");
int socket_fd, err;
if((socket_fd = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP))==-1)
{
cout << "initialized error" << endl;
cout << 0;
return -1;
}
//cout << 1 << socket_fd;
T.set_conf(socket_fd);
pthread_t thread_receive;
err = pthread_create(&thread_receive,nullptr,T.udp_response_receiver,&socket_fd);
sleep(3);
struct sockaddr_in serveraddr;
memset(&serveraddr,0,sizeof(serveraddr));
serveraddr.sin_family=AF_INET;
serveraddr.sin_addr.s_addr=T.gethost();
serveraddr.sin_port=htons(CONTROL_UDP_PORT);
if(err!=0)
{
cout << err << " " << "can't create thread";
}
T.get_connect(serveraddr);
//sleep(1);
//T.takeoff(serveraddr);
T.get_video(serveraddr);
sleep(5);
//T.land(serveraddr);
pthread_join(thread_receive,NULL);
listenkeyboard(T,serveraddr);
return 0;
}

@ -1,57 +0,0 @@
#include <termio.h>
#include <stdio.h>
#include "Hardwarelistener.h"
#include <iostream>
using namespace std;
int scanKeyboard()
{
int in;
struct termios new_settings;
struct termios stored_settings;
//设置终端参数
tcgetattr(0,&stored_settings);
new_settings = stored_settings;
new_settings.c_lflag &= (~ICANON);
new_settings.c_cc[VTIME] = 0;
tcgetattr(0,&stored_settings);
new_settings.c_cc[VMIN] = 1;
tcsetattr(0,TCSANOW,&new_settings);
in = getchar();
tcsetattr(0,TCSANOW,&stored_settings);
return in;
}
//测试函数
int listenkeyboard(Tello T, sockaddr_in serveraddr){
while(1){
switch(scanKeyboard())
{
case (int)'w':
cout << "forward"<< endl;
T.forward(serveraddr);
break;
case (int)'s':
cout << "back" << endl;
T.back(serveraddr);
break;
case (int)'a':
cout << "left" <<endl;
T.left(serveraddr);
break;
case (int)'d':
cout << "right"<<endl;
T.right(serveraddr);
break;
}
}
return 0;
// while(1){
// printf("%d\n",scanKeyboard());
// }
}

@ -1,21 +0,0 @@
obj = Djitellowhite.o keyboard.cpp Triplet.cpp
CXXFLAGS += -c -Wall $(shell pkg-config --cflags opencv4)
LDFLAGS += $(shell pkg-config --libs --static opencv4)
test : $(obj)
$(CXX) -o test $(obj) $(LDFLAGS)
Djitellowhite.o : Djitellowhite.h
$(CXX) -c Djitellowhite.cpp $(CXXFLAGS)
keyboard.o : Hardwarelistener.h
$(CXX) -c keyboard.cpp $(CXXFLAGS)
Triplet : Djitellowhite.h Hardwarelistener.h
$(CXX) -c Triplet.cpp -lpthread $(CXXFLAGS)
.PHONY : clean
clean :
rm test $(obj)

@ -1,58 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#define PORT 8890
void udp_server(int sockfd)
{
socklen_t len;
char buf[1024] = {0};
struct sockaddr_in server_addr;
int n;
int opt = 1;
len = sizeof(server_addr);
memset(&buf, 0, sizeof(buf));
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
server_addr.sin_port = htons(PORT);
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); //当服务器非正常断开的时候重启服务器不会进入TIME_WAIT状态
if (bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
printf("can not bind\n");
exit(1);
}
while (1) {
printf("========wait for client's request========\n");
n = recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&server_addr, &len);
buf[n] = '\0';
printf("receive client's data: %s\n", buf);
sendto(sockfd, buf, n, 0, (struct sockaddr *)&server_addr, len);
printf("send data to client: %s\n", buf);
}
close(sockfd);
}
int main(int argc, char **argv)
{
int sockfd;
if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
printf("create socket false\n");
exit(1);
}
udp_server(sockfd);
exit(0);
}

Binary file not shown.

@ -6,9 +6,10 @@
#include <QMutex>
#include <QTimer>
#include "ui_mainwindow.h"
#include "../include/joystick.h"
#include "../include/qnode.hpp"
#include "../include/dashboard.h"
#include "joystick.h"
#include "qnode.hpp"
#include "dashboard.h"
#include <sensor_msgs/BatteryState.h>
using namespace cv;

@ -1,6 +0,0 @@
#include "automove.h"
AutoMove::AutoMove()
{
}

@ -0,0 +1,6 @@
#include "../include/Air_Ground_CEC/automove.h"
AutoMove::AutoMove()
{
}

@ -1,4 +1,4 @@
#include "../include/dashboard.h"
#include "../include/Air_Ground_CEC/dashboard.h"
#include <qapplication.h>
#include <qpainter.h>

@ -1,4 +1,4 @@
#include "../include/joystick.h"
#include "../include/Air_Ground_CEC/joystick.h"
#include <QDebug>
JoyStick::JoyStick(QWidget* parent) : QWidget(parent) {

@ -1,5 +1,4 @@
#include "../ui/mainwindow.hpp"
#include "../include/Air_Ground_CEC/mainwindow.hpp"
#include <QApplication>

@ -1,4 +1,4 @@
#include "../ui/mainwindow.hpp"
#include "../include/Air_Ground_CEC/mainwindow.hpp"
#include <QtConcurrent/QtConcurrent>

@ -1,4 +1,4 @@
#include "../include/qnode.hpp"
#include "../include/Air_Ground_CEC/qnode.hpp"
#include "sensor_msgs/image_encodings.h"
#include <QtConcurrent/QtConcurrent>

@ -1,73 +0,0 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe

@ -1,38 +0,0 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv2 \
/usr/local/include/opencv4
LIBS += /usr/local/lib/libopencv_world.so

@ -1,11 +0,0 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

@ -1,51 +0,0 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(importFrame()));
//InitVideo();
}
void MainWindow::importFrame()
{
capture >> frame;
cvtColor(frame, frame, CV_BGR2RGB);
QImage srcQImage = QImage((uchar*)(frame.data), frame.cols, frame.rows, QImage::Format_RGB888);
ui->label->setPixmap(QPixmap::fromImage(srcQImage));
ui->label->resize(srcQImage.size());
ui->label->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_PLAY_clicked()
{
capture.open("udp://@0.0.0.0:11111");
timer->start(30);
}
void MainWindow::on_CLOSE_clicked()
{
timer->stop();
capture.release();
}

@ -1,47 +0,0 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtWidgets/QMainWindow>
#include <QTimer>
#include "opencv2/opencv.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgproc/types_c.h>
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
using namespace std;
using namespace cv;
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
VideoCapture cap;
void InitVideo();
private slots:
void importFrame();//read video
void on_PLAY_clicked();//start video
void on_CLOSE_clicked();//finish video
private:
Ui::MainWindow *ui;
VideoCapture capture;
QTimer *timer;
Mat frame;
bool isCamerea = 0;
};
#endif // MAINWINDOW_H

@ -1,71 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1280</width>
<height>768</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="CLOSE">
<property name="geometry">
<rect>
<x>1100</x>
<y>440</y>
<width>80</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>CLOSE</string>
</property>
</widget>
<widget class="QPushButton" name="PLAY">
<property name="geometry">
<rect>
<x>1100</x>
<y>250</y>
<width>80</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>PLAY</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>50</x>
<y>30</y>
<width>731</width>
<height>461</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1280</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
Loading…
Cancel
Save