Compare commits

...

5 Commits

Author SHA1 Message Date
NoError f6ab9c3102
cmakelist
Signed-off-by: NoError <2381910282@qq.com>
2023-09-13 09:22:03 +00:00
NoError d08dbde4da
src
Signed-off-by: NoError <2381910282@qq.com>
2023-09-13 09:21:04 +00:00
NoError 4f47ae7273
新建 src 2023-09-13 09:19:35 +00:00
NoError 6b40ea5118
删除文件 src 2023-09-13 09:19:26 +00:00
NoError 250ac60065
add src.
Signed-off-by: NoError <2381910282@qq.com>
2023-09-13 09:19:10 +00:00
13 changed files with 778 additions and 0 deletions

44
CHANGELOG.rst Normal file
View File

@ -0,0 +1,44 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package librviz_tutorial
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0.11.0 (2020-05-13)
-------------------
0.10.4 (2020-05-13)
-------------------
* Updated required CMake version to avoid CMP0048 warning (`#57 <https://github.com/ros-visualization/visualization_tutorials/issues/57>`_)
* Contributors: Alejandro Hernández Cordero
0.10.3 (2018-05-09)
-------------------
0.10.2 (2018-01-05)
-------------------
* Unified find_package for Qt4 and Qt5. (`#33 <https://github.com/ros-visualization/visualization_tutorials//issues/33>`_)
* Contributors: Robert Haschke, William Woodall
0.10.1 (2016-04-21)
-------------------
* Added qt5 dependencies to the package.xml.
* Contributors: William Woodall
0.10.0 (2016-04-21)
-------------------
* Added support Qt5 in Kinetic.
* Contributors: William Woodall
0.9.2 (2015-09-21)
------------------
0.9.1 (2015-01-26)
------------------
* Renamed a CMake variable to avoid colliding with built-in name.
* librviz_tutorial now installs it's executable ``myviz``.
* Removed explicit default_plugin library to fix "ld: cannot find -ldefault_plugin" isolated build error
* Contributors: Honore Doktorr, Kei Okada, William Woodall
0.9.0 (2014-03-24)
------------------
* set myself (william) as maintainer
* Contributors: William Woodall

53
CMakeLists.txt Normal file
View File

@ -0,0 +1,53 @@
## BEGIN_TUTORIAL
## This CMakeLists.txt file for rviz_plugin_tutorials builds both the
## TeleopPanel tutorial and the ImuDisplay tutorial.
##
## First start with some standard catkin stuff.
cmake_minimum_required(VERSION 3.0.2)
project(librviz_tutorial)
find_package(catkin REQUIRED COMPONENTS rviz roscpp std_msgs)
catkin_package()
include_directories(${catkin_INCLUDE_DIRS})
link_directories(${catkin_LIBRARY_DIRS})
## This setting causes Qt's "MOC" generation to happen automatically.
set(CMAKE_AUTOMOC ON)
## This plugin includes Qt widgets, so we must include Qt.
## We'll use the version that rviz used so they are compatible.
if(rviz_QT_VERSION VERSION_LESS "5")
message(STATUS "Using Qt4 based on the rviz_QT_VERSION: ${rviz_QT_VERSION}")
find_package(Qt4 ${rviz_QT_VERSION} EXACT REQUIRED QtCore QtGui)
## pull in all required include dirs, define QT_LIBRARIES, etc.
include(${QT_USE_FILE})
else()
message(STATUS "Using Qt5 based on the rviz_QT_VERSION: ${rviz_QT_VERSION}")
find_package(Qt5 ${rviz_QT_VERSION} EXACT REQUIRED Core Widgets)
## make target_link_libraries(${QT_LIBRARIES}) pull in all required dependencies
set(QT_LIBRARIES Qt5::Widgets)
endif()
## I prefer the Qt signals and slots to avoid defining "emit", "slots",
## etc because they can conflict with boost signals, so define QT_NO_KEYWORDS here.
add_definitions(-DQT_NO_KEYWORDS)
## Here we specify the list of source files.
## The generated MOC files are included automatically as headers.
set(SRC_FILES
src/myviz.cpp
src/main.cpp
)
## Add the "myviz" executable and specify the list of source files we
## collected above in ``${SRC_FILES}``.
add_executable(myviz ${SRC_FILES})
## Link the myviz executable with whatever Qt libraries have been defined by
## the ``find_package(Qt4 ...)`` line above, or by the
## ``set(QT_LIBRARIES Qt5::Widgets)``, and with whatever libraries
## catkin has included.
target_link_libraries(myviz ${QT_LIBRARIES} ${catkin_LIBRARIES})
## END_TUTORIAL
## Install
install(TARGETS myviz DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

30
package.xml Normal file
View File

@ -0,0 +1,30 @@
<package>
<name>librviz_tutorial</name>
<version>0.11.0</version>
<description>
Tutorial showing how to compile your own C++ program with RViz displays and features.
</description>
<maintainer email="mabel@openrobotics.org">Mabel Zhang</maintainer>
<license>BSD</license>
<url>http://ros.org/wiki/librviz_tutorial</url>
<author>Dave Hershberger</author>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>qtbase5-dev</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>rviz</build_depend>
<run_depend>libqt5-core</run_depend>
<run_depend>libqt5-gui</run_depend>
<run_depend>libqt5-widgets</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>rviz</run_depend>
<run_depend>std_msgs</run_depend>
<export>
<rosdoc config="${prefix}/rosdoc.yaml"/>
</export>
</package>

2
rosdoc.yaml Normal file
View File

@ -0,0 +1,2 @@
- builder: sphinx
sphinx_root_dir: src/doc

0
src/.keep Normal file
View File

25
src/doc/conf.py Normal file
View File

@ -0,0 +1,25 @@
import sys, os
sys.path += [ os.path.abspath( '.' )]
extensions = [ 'sphinx.ext.extlinks',
'tutorialformatter' ]
# The master toctree document.
master_doc = 'index'
# The suffix of source filenames.
source_suffix = '.rst'
project = u'librviz_tutorial'
copyright = u'2012, Willow Garage, Inc'
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
show_authors = True
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
extlinks = {'codedir': ('https://github.com/ros-visualization/visualization_tutorials/blob/hydro-devel/librviz_tutorial/%s', '')}

67
src/doc/index.rst Normal file
View File

@ -0,0 +1,67 @@
Librviz Tutorial
================
Overview
--------
RViz is not just a visualizer application, it is also a library! Much
of RViz's functionality can be accessed within your own application by
linking against librviz.so (or whatever your OS likes to call it).
This tutorial shows a very simple example of creating a 3D visualizer
widget (rviz::RenderPanel), programmatically creating a new Grid
display within it, then using Qt slider controls to adjust a couple of
the grid's properties. The app is called "myviz".
The source code for this tutorial is in the librviz_tutorial
package. You can check out the source directly or (if you use Ubuntu)
you can just apt-get install the pre-compiled Debian package like so::
sudo apt-get install ros-hydro-visualization-tutorials
The running application looks like this:
.. image:: myviz.png
The Code
--------
The code for myviz is in these files:
:codedir:`src/main.cpp`,
:codedir:`src/myviz.h`, and
:codedir:`src/myviz.cpp`.
main.cpp
^^^^^^^^
The full text of main.cpp is here: :codedir:`src/main.cpp`
.. tutorial-formatter:: ../main.cpp
myviz.h
^^^^^^^
The full text of myviz.h is here: :codedir:`src/myviz.h`
.. tutorial-formatter:: ../myviz.h
myviz.cpp
^^^^^^^^^
The full text of myviz.cpp is here: :codedir:`src/myviz.cpp`
.. tutorial-formatter:: ../myviz.cpp
Building
--------
The full text of CMakeLists.txt is here: :codedir:`CMakeLists.txt`
.. tutorial-formatter:: ../../CMakeLists.txt
Running
-------
Just type::
rosrun librviz_tutorial myviz

BIN
src/doc/myviz.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,132 @@
"""
tutorialformatter
===========================
This extension provides a directive to include a source code file
in a document, but with certain comments from the file formatted
as regular document text. This allows code for a tutorial to look like:
/// BEGIN_TUTORIAL
/// This next line adds one.
i = i + 1;
/// Then we need to double it.
i = i * 2;
/// END_TUTORIAL
And have it formatted as
This next line adds one.::
i = i + 1;
Then we need to double it.::
i = i * 2;
The special-looking comment character sequence at the start of
each text line can be anything not starting or ending with
whitespace. tutorialformatter starts by scanning the file for the
string BEGIN_TUTORIAL. When it finds it, it takes all the
characters before BEGIN_TUTORIAL on that line, strips whitespace
from the left, and uses that as the text marker. So this would
also be fine:
#My Tutorial# BEGIN_TUTORIAL
#My Tutorial# This next line adds one.
i = i + 1
#My Tutorial# Then we need to double it.
i = i * 2
#My Tutorial# END_TUTORIAL
.. moduleauthor:: Dave Hershberger <hersh@willowgarage.com>
"""
__version__ = '0.1.0'
import os
from docutils.parsers import rst
from docutils.parsers.rst.directives import flag, unchanged
from docutils.statemachine import string2lines
from pygments.lexers import get_lexer_for_filename
class TutorialFormatterDirective(rst.Directive):
has_content = False
final_argument_whitespace = True
required_arguments = 1
option_spec = dict(shell=flag, prompt=flag, nostderr=flag,
in_srcdir=flag, extraargs=unchanged,
until=unchanged)
def run(self):
filename = self.arguments[0]
text_tag = None
tag_len = 0
filepath = self.state.document.settings.env.srcdir
absfilename = os.path.join( filepath, filename )
if absfilename.endswith('.h'):
language = 'c++'
elif absfilename.endswith('CMakeLists.txt'):
language = 'cmake'
else:
try:
language = get_lexer_for_filename( absfilename ).name.lower()
if language == 'text only':
language = 'none'
except:
language = 'none'
code_prefix = '\n.. code-block:: ' + language + '\n\n'
code_suffix = '\n'
print "tutorial-formatter running on", absfilename
file_ = open( absfilename, 'r' )
text_to_process = ""
current_block = ""
in_code = False
in_text = False
in_tutorial = False
for line in file_:
if not in_tutorial:
begin_pos = line.find( 'BEGIN_TUTORIAL' )
if begin_pos != -1:
text_tag = line[:begin_pos].lstrip()
tag_len = len( text_tag )
in_tutorial = True
continue
if line.find( 'END_TUTORIAL' ) != -1:
break
stripped = line.lstrip()
if stripped.startswith( text_tag.strip() ):
if in_code:
text_to_process += code_prefix + current_block + code_suffix
current_block = ""
in_code = False
in_text = True
addition = stripped[tag_len:]
if addition == '' or addition[-1] != '\n':
addition += '\n'
current_block += addition
else:
if in_text:
text_to_process += current_block
current_block = ""
in_text = False
in_code = True # Code to show begins right after tagged text
if in_code:
current_block += ' ' + line
if in_code:
text_to_process += code_prefix + current_block + code_suffix
elif in_text:
text_to_process += current_block
# Debug writes...
#print 'text_to_process ='
#print text_to_process
#print '= text_to_process'
lines = string2lines( text_to_process )
self.state_machine.insert_input( lines, absfilename )
return []
def setup(app):
app.add_directive('tutorial-formatter', TutorialFormatterDirective)

56
src/main.cpp Normal file
View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2012, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
// BEGIN_TUTORIAL
// The main() for this "myviz" example is very simple, it just
// initializes ROS, creates a QApplication, creates the top-level
// widget (of type "MyViz"), shows it, and runs the Qt event loop.
#include <QApplication>
#include <ros/ros.h>
#include "myviz.h"
int main(int argc, char **argv)
{
if( !ros::isInitialized() )
{
ros::init( argc, argv, "myviz", ros::init_options::AnonymousName );
}
QApplication app( argc, argv );
MyViz* myviz = new MyViz();
myviz->setGeometry(0, 0, 2000, 1000);
myviz->show();
app.exec();
delete myviz;
}

270
src/myviz.cpp Normal file
View File

@ -0,0 +1,270 @@
/*
* Copyright (c) 2012, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <QColor>
#include <QSlider>
#include <QLabel>
#include <QGridLayout>
#include <QVBoxLayout>
#include<QLineEdit>
#include<QSpinBox>
#include<QPushButton>
#include <QProcess>
#include <QDebug>
#include<iostream>
#include "rviz/visualization_manager.h"
#include "rviz/render_panel.h"
#include "rviz/display.h"
#include "myviz.h"
#include "qthread.h"
// BEGIN_TUTORIAL
// Constructor for MyViz. This does most of the work of the class.
MyViz::MyViz( QWidget* parent )
: QWidget( parent )
{
nh=ros::NodeHandle("~");
sub=nh.subscribe("/test",1000,&MyViz::subCallback,this);
pub=nh.advertise<std_msgs::String>("/test_pub",1000);
pub_thread=std::thread(&MyViz::pubThread,this);
//pub_thread.join();
// Construct and lay out labels and slider controls.
QLabel* thickness_label = new QLabel( "Line Thickness" );
QSlider* thickness_slider = new QSlider( Qt::Horizontal );
thickness_slider->setMinimum( 1 );
thickness_slider->setMaximum( 100 );
QLabel* cell_size_label = new QLabel( "Cell Size" );
QSlider* cell_size_slider = new QSlider( Qt::Horizontal );
cell_size_slider->setMinimum( 1 );
cell_size_slider->setMaximum( 100 );
QLabel* Topic=new QLabel("TOPIC:");
QLineEdit* Topic_text=new QLineEdit();
QGridLayout* controls_layout = new QGridLayout();
QLabel* Size=new QLabel("Cloud Size");
QSpinBox* size=new QSpinBox();
/*button goto file begining*/
QPushButton* but_reset = new QPushButton("reset", this);
/*button goto file ending*/
QPushButton* but_ending = new QPushButton("end", this);
//TODO: set button color
//button->setStyleSheet("background-color: red; color: white;");
//TODO: set shortcut key
//button->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A));
//enable button
but_reset->setEnabled(true);
but_ending->setEnabled(true);
but_reset->setFixedSize(100, 30);
but_ending->setFixedSize(100, 30);
controls_layout->addWidget( thickness_label, 0, 0 );
controls_layout->addWidget( thickness_slider, 0, 1 );
controls_layout->addWidget( cell_size_label, 0, 2 );
controls_layout->addWidget( cell_size_slider, 0, 3 );
//button locatin
controls_layout->addWidget( but_reset, 1, 0 );
controls_layout->addWidget( but_ending, 1, 1 );
controls_layout->addWidget(Topic,0,4);
controls_layout->addWidget(Topic_text,0,5);
controls_layout->addWidget(Size,0,6);
controls_layout->addWidget(size,0,7);
// Construct and lay out render panel.
render_panel_ = new rviz::RenderPanel();
QVBoxLayout* main_layout = new QVBoxLayout;
main_layout->addLayout( controls_layout );
main_layout->addWidget( render_panel_ );
// Set the top-level layout for this MyViz widget.
setLayout( main_layout );
// Make signal/slot connections.
connect( thickness_slider, SIGNAL( valueChanged( int )), this, SLOT( setThickness( int )));
connect( cell_size_slider, SIGNAL( valueChanged( int )), this, SLOT( setCellSize( int )));
//connect(Topic_text,SIGNAL(textChanged(const QString &)),this,SLOT(setCloudTopic(const QString &)));
//topic change signal
connect(Topic_text,SIGNAL(textChanged(const QString &)),this,SLOT(setlaserTopic(const QString &)));
//button signal
connect(but_ending, &QPushButton::clicked, this, [&]() {
QStringList arguments, infoarg;
QString time;
QString file_path = "/home/noerror/123/catkin_for_ros/src/librviz_tutorial/data/result.bag";
QProcess *rosbaginfoProcess = new QProcess(this);
infoarg << "info" << file_path;
rosbaginfoProcess->start("rosbag", infoarg);
if(rosbaginfoProcess->waitForFinished()){
QByteArray output = rosbaginfoProcess->readAllStandardOutput();
QString outputString = QString::fromLocal8Bit(output);
QString delimiter = "duration:";
outputString = outputString.section(delimiter, 1, 1);
delimiter = "\n";
outputString = outputString.section(delimiter, 0, 0);
outputString.remove(" ");
outputString.remove("s");
double number = outputString.toDouble(); //qstring convert to double
time = QString::number(number-0.1);
qDebug() << time;
}
arguments << "play" << file_path << "--start" << time;
QProcess *rosbagProcess = new QProcess(this);
//QProcess::execute("rosbag play /home/noerror/123/catkin_for_ros/src/librviz_tutorial/data/result.bag");
rosbagProcess->start("rosbag", arguments);
});
connect(but_reset, &QPushButton::clicked, this, [&]() {
QStringList arguments, infoarg;
QString time;
QString file_path = "/home/noerror/123/catkin_for_ros/src/librviz_tutorial/data/result.bag";
arguments << "play" << file_path;
QProcess *rosbagProcess = new QProcess(this);
//QProcess::execute("rosbag play /home/noerror/123/catkin_for_ros/src/librviz_tutorial/data/result.bag");
rosbagProcess->start("rosbag", arguments);
});
connect(size,SIGNAL(valueChanged(int)),this,SLOT(setCloudSize(int)));
// Next we initialize the main RViz classes.
//
// The VisualizationManager is the container for Display objects,
// holds the main Ogre scene, holds the ViewController, etc. It is
// very central and we will probably need one in every usage of
// librviz.
manager_ = new rviz::VisualizationManager( render_panel_ );
render_panel_->initialize( manager_->getSceneManager(), manager_ );
//manager_->setFixedFrame("world");
/*TODO: laser data*/
manager_->setFixedFrame("laser");
manager_->initialize();
manager_->startUpdate();
// Create a Grid display.
grid_ = manager_->createDisplay( "rviz/Grid", "adjustable grid", true );
ROS_ASSERT( grid_ != NULL );
cloud = manager_->createDisplay( "rviz/PointCloud2", "point cloud", true );
ROS_ASSERT( cloud != NULL );
/*TODO: laser data display*/
laser = manager_->createDisplay( "rviz/LaserScan", "laser", true );
ROS_ASSERT( laser != NULL );
//set defualt topic to /scan
laser->subProp("Topic")->setValue("/scan");
laser->subProp("Decay Time")->setValue("0");
cloud->subProp("Topic")->setValue("/pose_graph/octree");
cloud->subProp("Style")->setValue("Points");
cloud->subProp("Size (Pixels)")->setValue("2");
cloud->subProp("Color Transformer")->setValue("Intensity");
cloud->subProp("Invert Rainbow")->setValue("true");
cloud->subProp("Decay Time")->setValue("1");
// Configure the GridDisplay the way we like it.
grid_->subProp( "Line Style" )->setValue( "Billboards" );
grid_->subProp( "Color" )->setValue( QColor( Qt::yellow ) );
// Initialize the slider values.
thickness_slider->setValue( 5 );
cell_size_slider->setValue( 10 );
}
// Destructor.
MyViz::~MyViz()
{
delete manager_;
}
// This function is a Qt slot connected to a QSlider's valueChanged()
// signal. It sets the line thickness of the grid by changing the
// grid's "Line Width" property.
void MyViz::setThickness( int thickness_percent )
{
if( grid_ != NULL )
{
grid_->subProp( "Line Style" )->subProp( "Line Width" )->setValue( thickness_percent / 100.0f );
}
}
// This function is a Qt slot connected to a QSlider's valueChanged()
// signal. It sets the cell size of the grid by changing the grid's
// "Cell Size" Property.
void MyViz::setCellSize( int cell_size_percent )
{
if( grid_ != NULL )
{
grid_->subProp( "Cell Size" )->setValue( cell_size_percent / 10.0f );
}
}
void MyViz::setCloudTopic(const QString &newTopic){
if(cloud!=NULL){
cloud->subProp( "Topic" )->setValue(newTopic);
//ROS_INFO_STREAM("cloud topic changed to => "<<newTopic.toStdString());
}
}
void MyViz::setCloudSize(int cloudsize){
if(cloud!=NULL){
cloud->subProp("Size (Pixels)")->setValue(cloudsize);
}
}
void MyViz::subCallback(const std_msgs::String& msg){
ROS_INFO_STREAM("receive message!");
}
void MyViz::pubThread(){
while(ros::ok()){
ROS_INFO_STREAM_ONCE("here is in publish process!");
}
}
void MyViz::setlaserTopic(const QString & lasertopic){
if(laser!=NULL){
laser->subProp("Topic")->setValue(lasertopic);
manager_->startUpdate();
}
}
void MyViz::PushButtonBegining(const QString & things){
QProcess::execute("rosbag play /home/noerror/123/catkin_for_ros/src/librviz_tutorial/data/result.bag ");
}

79
src/myviz.h Normal file
View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2012, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MYVIZ_H
#define MYVIZ_H
#include <QWidget>
#include<QString>
#include<ros/ros.h>
#include"std_msgs/String.h"
#include<thread>
namespace rviz
{
class Display;
class RenderPanel;
class VisualizationManager;
}
// BEGIN_TUTORIAL
// Class "MyViz" implements the top level widget for this example.
class MyViz: public QWidget
{
Q_OBJECT
public:
MyViz( QWidget* parent = 0 );
virtual ~MyViz();
void subCallback(const std_msgs::String& msg);
void pubThread();
private Q_SLOTS:
void setThickness( int thickness_percent );
void setCellSize( int cell_size_percent );
void setCloudTopic(const QString &newTopic);
void setCloudSize(int cloudsize);
void setlaserTopic(const QString &lasertopic);
void PushButtonBegining(const QString & things);
private:
rviz::VisualizationManager* manager_;
rviz::RenderPanel* render_panel_;
rviz::Display* grid_;
rviz::Display* cloud;
/*TODO: laser data*/
rviz::Display* laser;
/*TODO: create new thread*/
QProcess *rosbagProcessStart, *rosbagProcessEnd, *rosbagProcessReset;
ros::NodeHandle nh;
ros::Subscriber sub;
ros::Publisher pub;
std::thread pub_thread;
};
// END_TUTORIAL
#endif // MYVIZ_H

20
src/qthread.h Normal file
View File

@ -0,0 +1,20 @@
#include <QThread>
#include <QProcess>
class RosbagThread : public QThread {
Q_OBJECT
public:
void run() override {
// 在这里执行您的rosbag任务
// 例如记录数据到ROS bag文件或播放ROS bag文件
// 使用与前面示例中相似的方式启动rosbag进程
QStringList arguments;
QProcess rosbagProcess;
arguments << "play" << "/home/noerror/123/catkin_for_ros/src/librviz_tutorial/data/result.bag";
//QProcess::execute("rosbag play /home/noerror/123/catkin_for_ros/src/librviz_tutorial/data/result.bag");
rosbagProcess.start("rosbag", arguments);
}
};