1. QT development environment to build, maker culture wisdom made reference tutorial https://www.ncnynl.com/archives/201903/2863.html.
ROS need to create a workspace, so you can use CMAKE be compiled and automatically generate CMakeLists.txt file.
$mkdir -p ~/catkin_ws/src $cd ~/catkin_ws/src $catkin_init_workspace $cd ~/catkin_ws $catkin_make
$cd /src $catkin_create_qt_pkg robomap
2. The goal is to develop a robot SLAM map building and autonomous navigation interface display interface. Reference record "QT ROS and language Getting Started - ROS published map display the message" Chi-made passenger tutorial that one, also need to define a speed adjustment slider.
2.1 mapp.ui interface added Slider, class name to ForBackSlider; The following code modification. The last call of the value of the Slider in qnode.cpp so that the value of the node posted messages geometry_msgs :: Twist equal ForBackSlider.
mapp.cpp: slider->setMinimum(0); slider->setMaximum(100); ui->ForBackSlider->setMinimum(0); QObject::connect(ui->ForBackSlider,SIGNAL(valueChanged(int)),this,SLOT(set_speed_value(int)); void MAPP::set_speed_value(int slider_value) { ForBackSpeed=slider_value; } mapp.h: private slots: void set_speed_value(int s); private: a float ForBackSpeed = 0.0 ; the CMakeLists.txt to support :( C ++ . 11 Characteristics) SET (CMAKE_CXX_FLAGS " $ {} CMAKE_CXX_FLAGS -std = C ++. 11)
2.2 ROS button to start the node, for example: $ roscore, $ roslaunch usb_cam usb_cam_node, etc., that do not have to open a terminal and enter the long list of commands.
main_window.ui: insert button, renamed roscore.
main_window.h: Private slots: void on_roscore_clicked ();
main_window.cpp: void robomap :: :: on_roscore_clicked the MainWindow () { System ( " GNOME -terminal the bash the -X--C 'roscore' & " ); } if you want a button a plurality of start command, to obtain a corresponding number of write system (), respectively, as a newly opened terminal.
2.3 Subscribe to the camera.
Mode 1 (tricky, using the buttons invoke the command):
$roslaunch usb_cam usb_cam_test.launch
参见https://github.com/ros-visualization/rqt_image_view
main_window.cpp:
void robomap::Maindow::on_camera_clicked()
{
system("gnome -terminal -x bash -c 'source ~/catkin_ws/devel/setup.bash; rosrun usb_cam usb_cam_node'&");
system("gnome -terminal -x bash -c 'rqt_image_view'&");
}
Second way (without buttons): camera preview and the captured image with reference to the method of example implementations linux commune Qt5, https: //www.linuxidc.com/Linux/2016-03/128792.html
QCamera:: No such file or directory, then compile the original change was not through being given a direct reference. The problem is to determine the problem can not find external libraries and header files.
In the CMakeLists.txt:
include_directories (/ usr / the include / x86_64_linux-GNU / QT5 / QtMultimedia)
was added after the error is eliminated, but there is an error during link: undefined reference to 'QCamera :: '
add: target_link_libraries (... Qt5: : Multimedia), only QCameraViewfinder not find an external library.
Data then ran CMakeLists.txt learning, or can not be solved, but added to find another way to specify the c ++ standard: set ( CMAKE_CXX_STANDARD 11).
Turn the camera first implementation calls QT interface, the first to realize the function, not the ROS space complete:
step1: New Qt widgets application engineering
step2: https: //www.cnblogs.com/annt/p/ant_000.html
when running: step3 error, install the necessary library. Completion
cam.pro:
QT = + Multimedia Core GUI multimediawidgets
greaterThan (QT_MAJOR_VERSION,. 4): QT = + Widgets
the TARGET = CAM
TEMPLATE = App
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QCamera>
#include <QCameraViewfinder>
#include <QCameraImageCapture>
#include <QFileDialog>
namespace Ui {
class MainWindow;
}
class QCamera;
class QCameraViewfinder;
class QCameraImageCapture;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void captureImage();
void displayImage(int,QImage);
void saveImage();
private:
Ui::MainWindow *ui;
QCamera *camera;
QCameraViewfinder *viewfinder;
QCameraImageCapture *imageCapture;
};
#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
camera=new QCamera(this);
viewfinder=new QCameraViewfinder(this);
imageCapture=new QCameraImageCapture(camera);
ui->ImageView->addWidget(viewfinder);
ui->ImageCapture->setScaledContents(true);
camera->setViewfinder(viewfinder);
camera->start();
connect(imageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(displayImage(int,QImage)));
connect(ui->buttonCapture, SIGNAL(clicked()), this, SLOT(captureImage()));
connect(ui->buttonSave, SIGNAL(clicked()), this, SLOT(saveImage()));
connect(ui->buttonQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::captureImage()
{
ui->statusBar->showMessage(tr("capturing..."), 1000);
imageCapture->capture();
}
void MainWindow::displayImage(int , QImage image)
{
ui->ImageCapture->setPixmap(QPixmap::fromImage(image));
ui-> statusBar-> showMessage (TR ( "Capture the OK!"), 5000);
}
void the MainWindow :: saveimage ()
{
QString fileName = QFileDialog :: getSaveFileName (the this, TR ( "File Save"), the QDir :: HOMEPATH (), TR ( "jpegfile (* JPG)."));
IF (fileName.isEmpty ()) {
ui-> statusBar-> showMessage (TR ( "Cancel Save"), 5000);
return;
}
const QPixmap a pixmap = ui- *> ImageCapture-> a pixmap ();
IF (a pixmap) {
pixmap-> Save (fileName);
ui-> statusBar-> showMessage (TR ( "Save the OK"), 5000);
}
}
function may be implemented . Call camera, capture, save and so on.
Followed by the code in the ROS modified space. (Search to a blog, is CMAKE compile the project, you need to add qt library CMakeLists file) (Ubuntu under Qt Multimedia play mp3 files Note)
CMakeLists.txt:
set (QT_LIBRARIES Qt5 :: Widgets Qt5 :: SerialPort Qt5 :: Multimedia)
with reference to the wording of a blog, join MultimediaWidgets module, compiled successfully
3. Turn turtlebot simulation, verification procedures.
APT-GET install ROS sudo-ROS-Kinetic Kinetic-turtlebot-turtlebot-Apps-turtlebot-RO-Kinetic Kinetic-turtlebot Interactions ROS-ROS-sumulatio-Kinetic-kobuki-FTDI
Source /opt/ros/kinetic/setup.bash
roslaunch turtlebot_gazebo turtlebot_world.launch need to wait a few minutes to load
roslaunch turtlebot_gazebo gmapping_demo.launch
roslaunch turtlebot_teleop keyboard_teleop.launch