测试冲突解决 #25

Closed
porlfbpwz wants to merge 7 commits from gehongbo_branch into master

@ -11,6 +11,7 @@ find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
cv_bridge
sensor_msgs
image_transport
)
@ -122,16 +123,19 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(SOURCES
src/include/qnode.hpp
src/include/roskeyboardteleopnode.h
src/include/joystick.h
src/main/main.cpp
src/main/mainwindow.cpp
src/main/qnode.cpp
src/main/roskeyboardteleopnode.cpp
src/main/joystick.cpp
src/ui/mainwindow.hpp
src/ui/mainwindow.ui
)
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(
@ -140,7 +144,7 @@ include_directories(
${OpenCV_INCLUDE_DIRS}
)
add_executable(Air_Ground_CEC ${SOURCES})
add_executable(Air_Ground_CEC ${SOURCES} ${qrc_Files})
target_link_libraries(Air_Ground_CEC
Qt5::Widgets
${catkin_LIBRARIES}

@ -0,0 +1,55 @@
#ifndef JOYSTICK_H
#define JOYSTICK_H
#include <QDebug>
#include <QDrag>
#include <QMouseEvent>
#include <QPainter>
#include <QTimer>
#include <QWidget>
#include <QtMath>
class JoyStick : public QWidget {
Q_OBJECT
public:
JoyStick(QWidget *parent = 0);
~JoyStick();
enum {
upleft = 0,
up,
upright,
left,
stop,
right,
downleft,
down,
downright
};
signals:
void keyNumchanged(int num);
protected:
void paintEvent(QPaintEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
// void resizeEvent(QResizeEvent *event)override;
private:
int mouseX;
int mouseY;
int JoyStickX; //摇杆
int JoyStickY;
int JoyStickR;
int padX; //底盘
int padY;
int padR;
double handPadDis; //两圆圆心距离
bool mousePressed;
QTimer *tim;
private:
double Pointdis(int a, int b, int x, int y); //两点距离
int getKeyNum();
};
#endif // JoyStick_H

@ -4,6 +4,8 @@
#ifndef Q_MOC_RUN
#include <ros/ros.h>
#endif
#include <iostream>
#include <QImage>
#include <opencv2/core/core.hpp>
@ -17,6 +19,8 @@
#include <geometry_msgs/Twist.h>
#include <QThread>
using namespace std;
class QNode : public QThread{
Q_OBJECT
@ -25,13 +29,8 @@ public:
virtual ~QNode();
bool init();
void SubAndPubTopic();
void KeyboardMove(char key);
//void myCallback_img(const sensor_msgs::ImageConstPtr& msg);//camera callback function
//QImage image;
void KeyboardMove(char key, float speed_linear, float speed_trun);
//Q_SIGNALS:
//void loggingCamera();//发出设置相机图片信号
private:
int init_argc;
@ -39,11 +38,7 @@ private:
ros::Subscriber cmdVel_sub;
ros::Publisher cmd_pub;
//ros::Publisher chatter_publisher;
//QStringList logging_model;
//image_transport::Subscriber image_sub;
//cv::Mat img;
};
#endif

@ -0,0 +1,105 @@
#include "../include/joystick.h"
#include <QDebug>
JoyStick::JoyStick(QWidget* parent) : QWidget(parent) {
setPalette(QPalette(Qt::white));
resize(parent->width(), parent->height());
setMinimumSize(100, 100);
mouseX = width() / 2;
mouseY = height() / 2;
tim = new QTimer(this);
connect(tim, &QTimer::timeout, this,
[=] { emit keyNumchanged(getKeyNum()); });
// connect(this,&JoyStick::keyNumchanged,this,[=](int num){
// qDebug()<<num<<endl;
// });
}
JoyStick::~JoyStick() {}
void JoyStick::paintEvent(QPaintEvent*) {
QPainter painter(this);
int side = qMin(width(), height());
padR = side / 2; //底盘半径
padX = padR; //底盘圆心
padY = padR; //底盘圆心
JoyStickR = padR / 4; //摇杆圆半径
int JoyStickMaxR = padR - JoyStickR;
QColor JoyStickColor;
JoyStickColor.setRgb(85, 87, 83);
//加载底盘图像
// painter.save();
// painter.scale(side / 400.0, side / 400.0);//坐标会随窗口缩放
// painter.drawPixmap(0, 0, QPixmap(":/image/pad.png"));
// painter.restore();
//自绘底盘
painter.save();
QRadialGradient RadialGradient(padR, padR, padR * 3, padR,
padR); //圆心2半径1焦点2
RadialGradient.setColorAt(0, QColor(255, 253, 253, 255)); //渐变
RadialGradient.setColorAt(1, QColor(255, 240, 245, 190)); //渐变
painter.setBrush(RadialGradient);
painter.setPen(Qt::NoPen);
painter.drawEllipse(QPoint(padR, padR), side / 2, side / 2); //大圆盘
painter.restore();
// painter.drawText(20,20,tr("%1,%2,%3").arg(mouseX).arg(mouseY).arg(handPadDis));
if (!mousePressed) { //鼠标没按下则摇杆恢复到底盘中心
mouseX = padX;
mouseY = padY;
}
handPadDis = Pointdis(padR, padR, mouseX, mouseY);
if (handPadDis <= JoyStickMaxR) {
JoyStickX = mouseX;
JoyStickY = mouseY;
} else {
JoyStickX = (int)(JoyStickMaxR * (mouseX - padX) / handPadDis + padX);
JoyStickY = (int)(JoyStickMaxR * (mouseY - padY) / handPadDis + padY);
}
// painter.drawText(200,200,tr("%1,%2,%3").arg(JoyStickX).arg(JoyStickY).arg(handPaddis));
painter.setPen(Qt::NoPen);
painter.setBrush(JoyStickColor);
painter.drawEllipse(QPoint(JoyStickX, JoyStickY), JoyStickR,
JoyStickR); //摇杆
}
void JoyStick::mouseMoveEvent(QMouseEvent* event) {
static bool r = false;
mouseX = event->pos().x();
mouseY = event->pos().y();
if (r == true) {
update();
r = false;
} else {
r = true;
}
}
void JoyStick::mouseReleaseEvent(QMouseEvent* event) {
mouseX = width() / 2;
mouseY = height() / 2;
tim->stop();
mousePressed = false;
emit keyNumchanged(JoyStick::stop);
update();
}
void JoyStick::mousePressEvent(QMouseEvent* event) {
mouseX = event->pos().x();
mouseY = event->pos().y();
tim->start(100);
mousePressed = true;
update();
}
double JoyStick::Pointdis(int a, int b, int x, int y) {
return sqrt((double)((x - a) * (x - a) + (y - b) * (y - b)));
}
int JoyStick::getKeyNum() {
int x, y;
int keynum;
x = (int)(JoyStickX * 3.0 / (padR * 2));
y = (int)(JoyStickY * 3.0 / (padR * 2));
keynum = 3 * y + x;
return keynum;
}

@ -22,3 +22,6 @@ int main(int argc, char** argv)
/*
* find . "(" -name "*.cpp" -or -name "*.h" -or -name "*.hpp" -or -name "*.qrc" ")" -print | xargs wc -l
*/

@ -9,6 +9,7 @@ MainWindow::MainWindow(int argc, char **argv, QWidget *parent) :
{
qnode.init();
ui->setupUi(this);
initUis();
connections();
}
@ -18,63 +19,255 @@ MainWindow::~MainWindow()
}
void MainWindow::initUis(){
setBtnStyles();
/*
* init
*/
rock_widget = new JoyStick(ui->JoyStick_widget);
rock_widget->show();
}
void MainWindow::setBtnStyles(){
/*
* set PushButton state
*/
ui->btn_main->setIcon(QIcon("://images/up.png"));
ui->btn_main->setText("mainWidget");
ui->btn_main->setStyleSheet(
"QPushButton:hover{"
"background-color:rgb(186, 189, 182);"
"border-bottom:2px solid rgb(67, 154, 246);}"
"QPushButton:checked{"
"background-color:cyan;"
"border-bottom:2px solid white}"
"QPushButton:pressed{"
"background-color:rgb(67, 154, 246)}"
"QPushButton{"
"background-color:rgb(238, 238, 236);"
"border:none;"
"padding:0px 0px 0px 0px;"
"margin:0px 0px 0px 0px;}");
ui->btn_uav->setStyleSheet(
"QPushButton:hover{"
"background-color:rgb(186, 189, 182);"
"border-bottom:2px solid rgb(67, 154, 246);}"
"QPushButton:checked{"
"background-color:cyan;"
"border-bottom:2px solid white}"
"QPushButton:pressed{"
"background-color:rgb(67, 154, 246)}"
"QPushButton{"
"background-color:rgb(238, 238, 236);"
"border:none;"
"padding:0px 0px 0px 0px;"
"margin:0px 0px 0px 0px;}");
ui->btn_ugv->setStyleSheet(
"QPushButton:hover{"
"background-color:rgb(186, 189, 182);"
"border-bottom:2px solid rgb(67, 154, 246);}"
"QPushButton:checked{"
"background-color:cyan;"
"border-bottom:2px solid white}"
"QPushButton:pressed{"
"background-color:rgb(67, 154, 246)}"
"QPushButton{"
"background-color:rgb(238, 238, 236);"
"border:none;"
"padding:0px 0px 0px 0px;"
"margin:0px 0px 0px 0px;}");
// 8 -> Forward: ↑
ui->pushButton_Forward->setShortcut(Qt::Key_8);
ui->pushButton_Forward->setStyleSheet(
"QPushButton{border-image: url(://images/up.png)}"
"QPushButton{border:none}"
"QPushButton:pressed{border-image: url(://images/up_2.png)}");
ui->pushButton_Forward->setFlat(true);
// 2 -> Back: ↓
ui->pushButton_Back->setShortcut(Qt::Key_2);
ui->pushButton_Back->setStyleSheet(
"QPushButton{border-image: url(://images/down.png)}"
"QPushButton{border:none}"
"QPushButton:pressed{border-image: url(://images/down_2.png)}");
ui->pushButton_Back->setFlat(true);
// 4 -> Left: ←
ui->pushButton_Left->setShortcut(Qt::Key_4);
ui->pushButton_Left->setStyleSheet(
"QPushButton{border-image: url(://images/left.png)}"
"QPushButton{border:none}"
"QPushButton:pressed{border-image: url(://images/left_2.png)}");
ui->pushButton_Left->setFlat(true);
// 6 -> Right: →
ui->pushButton_Right->setShortcut(Qt::Key_6);
ui->pushButton_Right->setStyleSheet(
"QPushButton{border-image: url(://images/right.png)}"
"QPushButton{border:none}"
"QPushButton:pressed{border-image: url(://images/right_2.png)}");
ui->pushButton_Right->setFlat(true);
// 7 -> Left_Forward: ↖
ui->pushButton_Left_Forward->setShortcut(Qt::Key_7);
ui->pushButton_Left_Forward->setStyleSheet(
"QPushButton{border-image: url(://images/up_left.png)}"
"QPushButton{border:none}"
"QPushButton:pressed{border-image: url(://images/up_left_2.png)}");
ui->pushButton_Left_Forward->setFlat(true);
// 9 -> Right_Forward: ↗
ui->pushButton_Right_Forward->setShortcut(Qt::Key_9);
ui->pushButton_Right_Forward->setStyleSheet(
"QPushButton{border-image: url(://images/up_right.png)}"
"QPushButton{border:none}"
"QPushButton:pressed{border-image: url(://images/up_right_2.png)}");
ui->pushButton_Right_Forward->setFlat(true);
// 1 -> Left_Back: ↙
ui->pushButton_Left_Back->setShortcut(Qt::Key_1);
ui->pushButton_Left_Back->setStyleSheet(
"QPushButton{border-image: url(://images/down_left.png)}"
"QPushButton{border:none}"
"QPushButton:pressed{border-image: url(://images/down_left_2.png)}");
ui->pushButton_Left_Back->setFlat(true);
// 3 -> Right_Back: ↘
ui->pushButton_Right_Back->setShortcut(Qt::Key_3);
ui->pushButton_Right_Back->setStyleSheet(
"QPushButton{border-image: url(://images/down_right.png)}"
"QPushButton{border:none}"
"QPushButton:pressed{border-image: url(://images/down_right_2.png)}");
ui->pushButton_Right_Back->setFlat(true);
}
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';
}
*/
if (btn_name == "")
key = '1';
else if (btn_name == "")
key = '2';
else if (btn_name == "")
key = '3';
else if (btn_name == "")
key = '4';
//else if (btn_name == "")
// key = '5';
else if (btn_name == "")
key = '6';
else if (btn_name == "")
key = '7';
else if (btn_name == "")
key = '8';
else if (btn_name == "")
key = '9';
qnode.KeyboardMove(key);
//速度
float liner = ui->horizontalSlider_linear->value() * 0.01;
float turn = ui->horizontalSlider_raw->value() * 0.01;
//bool is_rage_mode = ui->checkBox_rage_mode->isChecked();
//std::cout<<liner<<" "<<turn<<std::endl;
qnode.KeyboardMove(key, liner, turn);
}
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()));
//
//QObject::connect(&qnode, SIGNAL(loggingCamera()), this, SLOT(slot_updateCamera()));
void MainWindow::slot_rockKeyChange(int key){
//速度
float liner = ui->horizontalSlider_linear->value() * 0.01;
float turn = ui->horizontalSlider_raw->value() * 0.01;
switch (key) {
case upleft:
qnode.KeyboardMove('7', liner, turn);
break;
case up:
qnode.KeyboardMove('8', liner, turn);
break;
case upright:
qnode.KeyboardMove('9', liner, turn);
break;
case left:
qnode.KeyboardMove('4', liner, turn);
break;
case right:
qnode.KeyboardMove('6', liner, turn);
break;
case downleft:
qnode.KeyboardMove('1', liner, turn);
break;
case down:
qnode.KeyboardMove('2', liner, turn);
break;
case downright:
qnode.KeyboardMove('3', liner, turn);
break;
}
}
void MainWindow::connections(){
QObject::connect(ui->btn_main, &QPushButton::clicked, this, [=](){
ui->stackedWidget_main->setCurrentIndex(0);
});
QObject::connect(ui->btn_uav, &QPushButton::clicked, this, [=](){
ui->stackedWidget_main->setCurrentIndex(1);
});
QObject::connect(ui->btn_ugv, &QPushButton::clicked, this, [=](){
ui->stackedWidget_main->setCurrentIndex(2);
});
/*
*
*/
// 8 -> Forward: ↑
connect(ui->pushButton_Forward, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
// 2 -> Back: ↓
connect(ui->pushButton_Back, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
// 4 -> Left: ←
connect(ui->pushButton_Left, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
// 6 -> Right: →
connect(ui->pushButton_Right, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
// 7 -> Left_Forward: ↖
connect(ui->pushButton_Left_Forward, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
// 9 -> Right_Forward: ↗
connect(ui->pushButton_Right_Forward, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
// 1 -> Left_Back: ↙
connect(ui->pushButton_Left_Back, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
// 3 -> Right_Back: ↘
connect(ui->pushButton_Right_Back, SIGNAL(clicked()), this, SLOT(slot_keyboard_control()));
connect(rock_widget, SIGNAL(keyNumchanged(int)), this,
SLOT(slot_rockKeyChange(int)));
/*
void MainWindow::slot_dispalyCamera(const QImage &image){
qimage_mutex.lock();
qimage = image.copy();
ui->UGV_Vedio->setPixmap(QPixmap::fromImage(qimage));
ui->UGV_Vedio->resize(ui->UGV_Vedio->pixmap()->size());
qimage_mutex.unlock();
//绑定slider的函数
connect(ui->horizontalSlider_raw, SIGNAL(valueChanged(int)), this,
SLOT(Slider_raw_valueChanged(int)));
connect(ui->horizontalSlider_linear, SIGNAL(valueChanged(int)), this,
SLOT(Slider_linear_valueChanged(int)));
}
void MainWindow::slot_updateCamera()
{
slot_dispalyCamera(qnode.image);
//滑动条处理槽函数
void MainWindow::Slider_raw_valueChanged(int v) {
ui->label_raw->setText(QString::number(v));
}
//滑动条处理槽函数
void MainWindow::Slider_linear_valueChanged(int v) {
ui->label_linear->setText(QString::number(v));
}
*/

@ -30,37 +30,35 @@ void QNode::SubAndPubTopic(){
cmd_pub = n.advertise<geometry_msgs::Twist>("cmd_vel", 1);
}
void QNode::KeyboardMove(char key){
void QNode::KeyboardMove(char key, float speed_linear, float speed_trun){
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}}
// {'key', {x, y, z, th}}
{'7', {1, 1, 0, 1}}, {'8', {1, 0, 0, 0}}, {'9', {1, -1, 0, -1}},
{'4', {0, 0, 0, 1}}, {'5', {0, 0, 0, 0}}, {'6', {0, 0, 0, -1}},
{'1', {-1, 1, 0, 1}}, {'2', {-1, 0, 0, 0}}, {'3', {-1, -1, 0, -1}}
};
float x = moveBindings[key][0];
float z = moveBindings[key][1];
float y = moveBindings[key][1];
float z = moveBindings[key][2];
float th = moveBindings[key][3];
//计算线速度和角速度
float speed = speed_linear;
float turn = speed_trun;
geometry_msgs::Twist twist;
twist.linear.x = x;
twist.angular.z = z;
twist.linear.x = x * speed;
twist.linear.y = y * speed;
twist.linear.z = z * speed;
twist.angular.x = 0;
twist.angular.y = 0;
twist.angular.z = th * turn;
cmd_pub.publish(twist);
ros::spinOnce();
}
/*
void QNode::myCallback_img(const sensor_msgs::ImageConstPtr &msg)
{
try
{
cv_bridge::CvImageConstPtr cv_ptr = cv_bridge::toCvShare(msg, sensor_msgs::image_encodings::RGB8);
img = cv_ptr->image;
image = QImage(img.data,img.cols,img.rows,img.step[0],QImage::Format_RGB888);//change to QImage format
ROS_INFO("I'm setting picture in mul_t callback function!");
Q_EMIT loggingCamera();
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
}
}
*/

@ -0,0 +1,20 @@
<RCC>
<qresource prefix="/">
<file>images/down.png</file>
<file>images/down_2.png</file>
<file>images/down_left.png</file>
<file>images/down_left_2.png</file>
<file>images/down_right.png</file>
<file>images/down_right_2.png</file>
<file>images/left.png</file>
<file>images/left_2.png</file>
<file>images/right.png</file>
<file>images/right_2.png</file>
<file>images/up.png</file>
<file>images/up_2.png</file>
<file>images/up_left.png</file>
<file>images/up_left_2.png</file>
<file>images/up_right.png</file>
<file>images/up_right_2.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 764 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@ -6,6 +6,7 @@
#include <QMutex>
#include "ui_mainwindow.h"
#include "../include/joystick.h"
#include "../include/qnode.hpp"
namespace Ui {
@ -19,18 +20,39 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(int argc, char **argv, QWidget *parent = 0);
~MainWindow();
enum {
upleft = 0,
up,
upright,
left,
stop,
right,
downleft,
down,
downright
};
public slots:
void slot_keyboard_control();
//void slot_updateCamera();
//void slot_dispalyCamera(const QImage& image);
//void slot_command_control(int linear, int angular);
void slot_rockKeyChange(int);
void Slider_raw_valueChanged(int v);
void Slider_linear_valueChanged(int v);
private:
Ui::MainWindow *ui;
void connections();
QNode qnode;
//QImage qimage;
//mutable QMutex qimage_mutex;
JoyStick *rock_widget;
void initUis();
void setBtnStyles();
void connections();
};

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save