commit
54a70739bc
@ -1,8 +1,29 @@
|
|||||||
#include <opencv2/core.hpp>
|
#ifndef Air_Ground_CEC_QNODE_HPP_
|
||||||
#include <opencv2/highgui.hpp>
|
#define Air_Ground_CEC_QNODE_HPP_
|
||||||
#include <opencv2/imgproc.hpp>
|
|
||||||
#include <image_transport/image_transport.h>
|
|
||||||
#include <cv_bridge/cv_bridge.h>
|
|
||||||
#include <QImage>
|
|
||||||
|
|
||||||
|
#ifndef Q_MOC_RUN
|
||||||
|
#include <ros/ros.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <geometry_msgs/Twist.h>
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
class QNode : public QThread{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QNode(int argc, char **argv);
|
||||||
|
virtual ~QNode();
|
||||||
|
bool init();
|
||||||
|
void KeyboardMove(char key);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int init_argc;
|
||||||
|
char **init_argv;
|
||||||
|
ros::NodeHandle n;
|
||||||
|
ros::Subscriber cmdVel_sub;
|
||||||
|
ros::Publisher cmd_pub;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -1,14 +1,59 @@
|
|||||||
#include "../ui/mainwindow.hpp"
|
#include "../ui/mainwindow.hpp"
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(int argc, char **argv, QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent), qnode(argc, argv),
|
||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connections();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::slot_keyboard_control(){
|
||||||
|
QPushButton *btn = qobject_cast<QPushButton *>(sender());
|
||||||
|
std::string btn_name = btn->text().toStdString();
|
||||||
|
char key = ' ';
|
||||||
|
if (btn_name == "左"){
|
||||||
|
key = 'a';
|
||||||
|
}
|
||||||
|
else if (btn_name == "右") {
|
||||||
|
key = 'd';
|
||||||
|
}
|
||||||
|
else if (btn_name == "前") {
|
||||||
|
key = 'w';
|
||||||
|
}
|
||||||
|
else if (btn_name == "后") {
|
||||||
|
key = 's';
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
else if (btn_name == "加速") {
|
||||||
|
key = 'f';
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
qnode.KeyboardMove(key);
|
||||||
|
std::cout<<key<<std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::connections(){
|
||||||
|
//绑定速度控制按钮
|
||||||
|
ui->pushButton_W->setShortcut(Qt::Key_W);
|
||||||
|
connect(ui->pushButton_W, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
|
||||||
|
ui->pushButton_S->setShortcut(Qt::Key_S);
|
||||||
|
connect(ui->pushButton_S, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
|
||||||
|
ui->pushButton_A->setShortcut(Qt::Key_A);
|
||||||
|
connect(ui->pushButton_A, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
|
||||||
|
ui->pushButton_D->setShortcut(Qt::Key_D);
|
||||||
|
connect(ui->pushButton_D, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
|
||||||
|
connect(ui->pushButton_shift, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
|
||||||
|
}
|
||||||
|
@ -1 +1,47 @@
|
|||||||
|
#include "../include/qnode.hpp"
|
||||||
|
|
||||||
|
#include <ros/ros.h>
|
||||||
|
#include <std_msgs/String.h>
|
||||||
|
#include <ros/network.h>
|
||||||
|
|
||||||
|
QNode::QNode(int argc, char **argv) : init_argc(argc), init_argv(argv){
|
||||||
|
cmd_pub = n.advertise<geometry_msgs::Twist>("cmd_vel", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QNode::~QNode() {
|
||||||
|
if (ros::isStarted()) {
|
||||||
|
ros::shutdown(); // explicitly needed since we use ros::start();
|
||||||
|
ros::waitForShutdown();
|
||||||
|
}
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QNode::init() {
|
||||||
|
ros::init(init_argc, init_argv, "cyrobot_monitor",
|
||||||
|
ros::init_options::AnonymousName);
|
||||||
|
if (!ros::master::check()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ros::start(); // explicitly needed since our nodehandle is going out of
|
||||||
|
// scope.
|
||||||
|
start();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QNode::KeyboardMove(char key){
|
||||||
|
std::map<char, std::vector<float>> moveBindings {
|
||||||
|
// {'key', {speed, turn}}
|
||||||
|
{'w', {1, 0}}, {'s', {-1, 0}}, {'a', {0, 1}}, {'d', {0, -1}},
|
||||||
|
{'W', {1, 0}}, {'S', {-1, 0}}, {'A', {0, 1}}, {'D', {0, -1}}
|
||||||
|
};
|
||||||
|
|
||||||
|
float x = moveBindings[key][0];
|
||||||
|
float z = moveBindings[key][1];
|
||||||
|
|
||||||
|
geometry_msgs::Twist twist;
|
||||||
|
twist.linear.x = x;
|
||||||
|
twist.angular.z = z;
|
||||||
|
cmd_pub.publish(twist);
|
||||||
|
ros::spinOnce();
|
||||||
|
}
|
||||||
|
@ -1,24 +1,216 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<author/>
|
|
||||||
<comment/>
|
|
||||||
<exportmacro/>
|
|
||||||
<class>MainWindow</class>
|
<class>MainWindow</class>
|
||||||
<widget name="MainWindow" class="QMainWindow">
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>1600</width>
|
||||||
<height>600</height>
|
<height>900</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget name="menubar" class="QMenuBar"/>
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget name="centralwidget" class="QWidget"/>
|
<widget class="QWidget" name="">
|
||||||
<widget name="statusbar" class="QStatusBar"/>
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>410</x>
|
||||||
|
<y>260</y>
|
||||||
|
<width>314</width>
|
||||||
|
<height>164</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QPushButton" name="pushButton_W">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>前</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QPushButton" name="pushButton_A">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>左</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QPushButton" name="pushButton_shift">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>加速</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QPushButton" name="pushButton_D">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>右</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QPushButton" name="pushButton_S">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>后</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<spacer name="horizontalSpacer_4">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1600</width>
|
||||||
|
<height>22</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
</widget>
|
</widget>
|
||||||
<pixmapfunction/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
Reference in new issue