diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fd0bbf..d32a901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ catkin_package( ########### #set(OpenCV_DIR /usr/local/share/opencv4) -#find_package(OpenCV REQUIRED) +find_package(OpenCV REQUIRED) find_package(Qt5 REQUIRED COMPONENTS Widgets ) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) diff --git a/src/include/automove.cpp b/src/include/automove.cpp new file mode 100644 index 0000000..3238fd7 --- /dev/null +++ b/src/include/automove.cpp @@ -0,0 +1,6 @@ +#include "automove.h" + +AutoMove::AutoMove() +{ + +} diff --git a/src/include/automove.h b/src/include/automove.h new file mode 100644 index 0000000..2890af9 --- /dev/null +++ b/src/include/automove.h @@ -0,0 +1,12 @@ +#ifndef AUTOMOVE_H +#define AUTOMOVE_H + + +class AutoMove +{ +public: + AutoMove(); + +}; + +#endif // AUTOMOVE_H diff --git a/src/include/qnode.hpp b/src/include/qnode.hpp index 7641131..f5aa260 100644 --- a/src/include/qnode.hpp +++ b/src/include/qnode.hpp @@ -35,6 +35,8 @@ public: bool init(); void SubAndPubTopic(); void KeyboardMove(char key, float speed_linear, float speed_trun); + void AutoMove(float speed_linear, float speed_turn, + float target_linear, float target_turn); QImage image; Q_SIGNALS: @@ -52,6 +54,7 @@ private: ros::Publisher chatter_publisher; ros::Subscriber chatter_subscriber; ros::Publisher cmd_pub; + ros::Publisher cmd_pub1; ros::Subscriber cmdVel_sub; ros::Subscriber power_sub; QStringListModel logging_model; diff --git a/src/main/mainwindow.cpp b/src/main/mainwindow.cpp index 8c545d4..d670d0c 100644 --- a/src/main/mainwindow.cpp +++ b/src/main/mainwindow.cpp @@ -191,6 +191,7 @@ void MainWindow::slot_keyboard_control(){ //std::cout<("cmd_vel", 1); - + cmd_pub1 = n.advertise("cmd_vel", 1); image_transport::ImageTransport it(n); //chatter_subscriber = n.subscribe("chatter",1000,&QNode::myCallback,this); image_sub = it.subscribe("camera/image",100,&QNode::myCallback_img,this); @@ -76,6 +76,79 @@ void QNode::KeyboardMove(char key, float speed_linear, float speed_trun){ ros::spinOnce(); } +void QNode::AutoMove(float speed_linear, float speed_turn, + float target_linear, float target_turn){ + + // wrong command + if (speed_linear==0 && speed_turn ==0){ + std::cout<<"wrong command"<> Directions { + {'w',{1, 0, 0, 0}}, {'x',{-1, 0, 0, 0}}, {'s',{0, 0, 0, 0}}, + {'a',{0, 0, 0, 1}}, {'d',{0, 0, 0, -1}} + }; + char key = 's'; + if(target_linear < 0){ + key = 'x'; + } + else if (target_linear > 0){ + key = 'w'; + } + else if (target_turn > 0){ + key = 'a'; + } + else if (target_turn < 0){ + key = 'd'; + } + + float x = Directions[key][0]; + float y = Directions[key][1]; + float z = Directions[key][2]; + float th = Directions[key][3]; + + + + float total_times = 0; + if (target_linear == 0){ + total_times = fabs(target_turn)/speed_turn; + } + else{ + total_times = fabs(target_linear)/speed_linear; + } + + std::cout<< total_times<0 0 1440 - 810 + 860 + + + 1440 + 860 + + + + + 1440 + 860 + + MainWindow @@ -17,8 +29,178 @@ - - + + + + + 0 + + + + + + 0 + 60 + + + + + + + + + + + 32 + 32 + + + + + + + + + 0 + 60 + + + + + + + + + + + 32 + 32 + + + + + + + + + 0 + 60 + + + + ArrowCursor + + + + + + + + + + ../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui + + + + 32 + 32 + + + + + + + + + 0 + 60 + + + + PointingHandCursor + + + 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; +} + + + + + + + ../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui + + + + 32 + 32 + + + + + + + + + 0 + 60 + + + + PointingHandCursor + + + 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; +} + + + + + + + ../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui + + + + 32 + 32 + + + + + + + 2 @@ -54,431 +236,885 @@ - + - 1000 - 30 - 407 - 680 + 700 + 0 + 735 + 750 - + - - - 1 - - - - - - - - - Qt::Vertical - - - QSizePolicy::Preferred - - - - 20 - 20 - - - - - - - - - - - 64 - 64 - - - - - 64 - 64 - - - - - 15 - - - - - - - - - - - - 64 - 64 - - - - - 64 - 64 - - - - - 15 - - - - QPushButton{border-image: url(://images/up.png);} - - - - - - - - - - - 64 - 64 - - - - - 64 - 64 - - - - - 15 - - - - - - - - - - - - - - - - 64 - 64 - - - - - 64 - 64 - - - - - 15 - - - - - - - - - - - - 90 - 64 - - - - - 90 - 64 - - - - 全向模式(k) - - - K - - - + + + + + + 60 + 0 + + + + + 13 + + + + 00:00:00 + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + :/images/robot2.png + + + + + + + + + + 系统状态: + + + + + + + + 20 + 20 + + + + + 20 + 20 + + + + PointingHandCursor + + + QPushButton{ +border:none; +padding:0px 0px 0px 0px; +margin:0px 0px 0px 0px; +} + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + 30 + 30 + + + + + + + :/images/power.png + + + + + + + + 90 + 16777215 + + + + QProgressBar#progressBar +{ + border:none; /*无边框*/ + background:rgb(211, 215, 207); + border-radius:5px; + text-align:center; /*文本的位置*/ + color: rgb(229, 229, 229); /*文本颜色*/ +} + +QProgressBar::chunk +{ + background-color:rgb(115, 210, 22); + border-radius:4px; +} + + + + 70 + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + :/images/power-v.png + + + + + + + + 50 + 32 + + + + + 50 + 32 + + + + + + + 00.00V + + + + + + + + + + + + + + 270 + 200 + + + + map + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 270 + 200 + + + + target + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 270 + 200 + + + + shortcut + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + - - - - 64 - 64 - - - - - 64 - 64 - - - - - 15 - - - - - - - - - + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 20 + + + + + + + + + + + 64 + 64 + + + + + 64 + 64 + + + + + 15 + + + + + + + + + + + + 64 + 64 + + + + + 64 + 64 + + + + + 15 + + + + QPushButton{border-image: url(://images/up.png);} + + + + + + + + + + + 64 + 64 + + + + + 64 + 64 + + + + + 15 + + + + + + + + + + + + + + + + 64 + 64 + + + + + 64 + 64 + + + + + 15 + + + + + + + + + + + + 90 + 64 + + + + + 90 + 64 + + + + 全向模式(k) + + + K + + + + + + + + 64 + 64 + + + + + 64 + 64 + + + + + 15 + + + + + + + + + + + + + + + + + + + 64 + 64 + + + + + 64 + 64 + + + + + 15 + + + + + + + + + + + + 64 + 64 + + + + + 64 + 64 + + + + + 15 + + + + QPushButton{border-image: url(://images/down.png);} +QPushButton{border:none;} +QPushButton:pressed{border-image: url(://images/down_2.png);} + + + + + + + + + + + 64 + 64 + + + + + 64 + 64 + + + + + 15 + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 30 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + + 线速度(cm/s): + + + + + + + 100 + + + 1 + + + 50 + + + Qt::Horizontal + + + + + + + 50 + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + 角速度(cm/s): + + + + + + + 100 + + + 100 + + + Qt::Horizontal + + + + + + + 100 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 30 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + 200 + 200 + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 385 + 21 + + + + + - - - + + + - + - 64 - 64 - - - - - 64 - 64 + 0 + 221 - - - 15 - - - + TextLabel - + - 64 - 64 + 300 + 0 - 64 - 64 + 12312312 + 12312312 - - - 15 - - - QPushButton{border-image: url(://images/down.png);} -QPushButton{border:none;} -QPushButton:pressed{border-image: url(://images/down_2.png);} - - - - - - - - - - - 64 - 64 - - - - - 64 - 64 - - - - - 15 - - - - + QListView{ +border-top: 5px solid qlineargradient(y0:0, y1:1,stop: 0 #ececef, stop: 1 white); +border-left: 5px solid qlineargradient(x0:0, x1:1,stop: 0 #ececef, stop: 1 white); + border-bottom: 5px solid qlineargradient(y0:0, y1:1,stop: 0 white, stop: 1 #ececef); +border-right: 5px solid qlineargradient(x0:0, x1:1,stop: 0 white, stop: 1 #ececef); +background-color: rgb(255,255,255); +} + - + + + + + + + 0 + - + - Qt::Vertical + Qt::Horizontal QSizePolicy::Fixed - 20 - 30 + 10 + 20 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - - - 线速度(cm/s): - - - - - - - 100 - - - 1 - - - 50 - - - Qt::Horizontal - - - - - - - 50 - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - + + + + 0 + 45 + + + + system + + - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - 角速度(cm/s): - - - - - - - 100 - - - 100 - - - Qt::Horizontal - - - - - - - 100 - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - + + + + 0 + 45 + + + + keyboard + + - + - Qt::Vertical + Qt::Horizontal QSizePolicy::Fixed @@ -486,67 +1122,7 @@ QPushButton:pressed{border-image: url(://images/down_2.png);} 20 - 30 - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 20 - - - - - - - - - 200 - 200 - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 385 - 21 + 20 @@ -554,110 +1130,211 @@ QPushButton:pressed{border-image: url(://images/down_2.png);} - - - - - - - - 0 - 221 - - - - TextLabel - - - + + + + + + + + + 21 + 1 + 660 + 756 + + + + + + + + 0 + 0 + + + + Logging + + + + + + + 600 + 270 + + + + CameraLabel + + + + + + + true + + + + 600 + 81 + + + + + 16777215 + 81 + + + + + + + + + + + - + 300 - 0 - - - - - 12312312 - 12312312 + 300 - QListView{ -border-top: 5px solid qlineargradient(y0:0, y1:1,stop: 0 #ececef, stop: 1 white); -border-left: 5px solid qlineargradient(x0:0, x1:1,stop: 0 #ececef, stop: 1 white); - border-bottom: 5px solid qlineargradient(y0:0, y1:1,stop: 0 white, stop: 1 #ececef); -border-right: 5px solid qlineargradient(x0:0, x1:1,stop: 0 white, stop: 1 #ececef); -background-color: rgb(255,255,255); -} - + + + + + + + + 160 + 30 + + + + x 轴线速度 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 60 + 35 + + + + 正向 + + + + + - - - - - - - 0 - + - + Qt::Horizontal - - QSizePolicy::Fixed - - 10 + 40 20 - - - - 0 - 45 - - - - system - - - - - - - - 0 - 45 - - - - keyboard - - + + + + + + 300 + 300 + + + + + + + + + + + + + + 160 + 30 + + + + x 轴线速度 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 60 + 35 + + + + 正向 + + + + + + - + Qt::Horizontal - - QSizePolicy::Fixed - - 20 + 40 20 @@ -667,252 +1344,9 @@ background-color: rgb(255,255,255); - - - - 100 - 400 - 302 - 300 - - - - - 300 - 300 - - - - - - - - - - 490 - 400 - 302 - 300 - - - - - 300 - 300 - - - - - - - - - - 50 - 10 - 541 - 368 - - - - - 0 - 0 - - - - Logging - - - - - - true - - - - - - - CameraLabel - - - - - - - - - 0 - - - - - - 0 - 60 - - - - - - - - - - - 32 - 32 - - - - - - - - - 0 - 60 - - - - - - - - - - - 32 - 32 - - - - - - - - - 0 - 60 - - - - ArrowCursor - - - - - - - - - - ../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui - - - - 32 - 32 - - - - - - - - - 0 - 60 - - - - PointingHandCursor - - - 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; -} - - - - - - - ../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui - - - - 32 - 32 - - - - - - - - - 0 - 60 - - - - PointingHandCursor - - - 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; -} - - - - - - - ../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui../../../../../catkin_ws/src/Ros_Qt5_Gui_App/ui - - - - 32 - 32 - - - - - -