From 6a1c835ea097c6d4852fcdc40a3cd81e48fe7603 Mon Sep 17 00:00:00 2001 From: Wolfgang Merkt Date: Tue, 24 Jan 2017 19:19:56 +0000 Subject: [PATCH 1/2] Add OctomapServerControl Panel with a Reset Octomap button Triggers the corresponding service. --- CMakeLists.txt | 8 +-- .../octomap_server_control.h | 68 +++++++++++++++++++ package.xml | 2 + plugin_description.xml | 9 ++- src/octomap_server_control.cpp | 60 ++++++++++++++++ 5 files changed, 141 insertions(+), 6 deletions(-) create mode 100644 include/octomap_rviz_plugins/octomap_server_control.h create mode 100644 src/octomap_server_control.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b8aabee..3fe8866 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(octomap_rviz_plugins) find_package(catkin REQUIRED COMPONENTS octomap_msgs roscpp rviz - + std_srvs ) find_package(octomap REQUIRED) @@ -38,17 +38,19 @@ link_directories(${catkin_LIBRARY_DIRS} QT4_WRAP_CPP(MOC_FILES include/octomap_rviz_plugins/occupancy_grid_display.h include/octomap_rviz_plugins/occupancy_map_display.h + include/octomap_rviz_plugins/octomap_server_control.h OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED -DBOOST_LEXICAL_CAST_INCLUDED ) set(SOURCE_FILES src/occupancy_grid_display.cpp src/occupancy_map_display.cpp + src/octomap_server_control.cpp ${MOC_FILES} ) add_library(${PROJECT_NAME} ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${Boost_LIBRARIES} ${OCTOMAP_LIBRARIES} ${catkin_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${Boost_LIBRARIES} ${OCTOMAP_LIBRARIES} ${catkin_LIBRARIES} ${rviz_DEFAULT_PLUGIN_LIBRARIES}) install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} @@ -63,5 +65,3 @@ install(TARGETS ${PROJECT_NAME} install(FILES plugin_description.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) - - diff --git a/include/octomap_rviz_plugins/octomap_server_control.h b/include/octomap_rviz_plugins/octomap_server_control.h new file mode 100644 index 0000000..aa46e19 --- /dev/null +++ b/include/octomap_rviz_plugins/octomap_server_control.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017, Wolfgang Merkt + * 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. + * + * Author: Wolfgang Merkt (wolfgang.merkt@ed.ac.uk) + * + */ + +#ifndef RVIZ_OCTOMAP_SERVER_CONTROL_H +#define RVIZ_OCTOMAP_SERVER_CONTROL_H + +#ifndef Q_MOC_RUN + +#include + +#include +#include +#include + +#endif + +namespace octomap_rviz_plugin { + +class OctomapServerControl : public rviz::Panel { + Q_OBJECT + + public: + OctomapServerControl(QWidget* parent = 0); + + protected Q_SLOTS: + void resetOctomap(); + + protected: + QVBoxLayout* vbox_; + QPushButton* btnResetOctomap_; + + private: + ros::NodeHandle nh_; + ros::ServiceClient srvResetOctomap_ = + nh_.serviceClient("/octomap_server/reset"); +}; +} + +#endif diff --git a/package.xml b/package.xml index 37c0b46..2061476 100644 --- a/package.xml +++ b/package.xml @@ -20,11 +20,13 @@ octomap roscpp rviz + std_srvs octomap_msgs octomap roscpp rviz + std_srvs diff --git a/plugin_description.xml b/plugin_description.xml index 1bfd643..e21806a 100644 --- a/plugin_description.xml +++ b/plugin_description.xml @@ -1,4 +1,3 @@ - + + + Buttons to trigger OctomapServer services. + + - diff --git a/src/octomap_server_control.cpp b/src/octomap_server_control.cpp new file mode 100644 index 0000000..cf39925 --- /dev/null +++ b/src/octomap_server_control.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017, Wolfgang Merkt + * 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. + * + * Author: Wolfgang Merkt (wolfgang.merkt@ed.ac.uk) + * + */ + +#include "octomap_rviz_plugins/octomap_server_control.h" + +namespace octomap_rviz_plugin { +OctomapServerControl::OctomapServerControl(QWidget* parent) + : rviz::Panel(parent) { + vbox_ = new QVBoxLayout(); + + btnResetOctomap_ = new QPushButton(tr("Reset Octomap")); + btnResetOctomap_->setSizePolicy(QSizePolicy::Expanding, + QSizePolicy::Expanding); + + vbox_->addWidget(btnResetOctomap_); + + connect(btnResetOctomap_, SIGNAL(clicked()), this, SLOT(resetOctomap())); + + setLayout(vbox_); +} + +void OctomapServerControl::resetOctomap() { + std_srvs::Empty req; + srvResetOctomap_.call(req); +} +} + +#include + +typedef octomap_rviz_plugin::OctomapServerControl OctomapServerControl; +PLUGINLIB_EXPORT_CLASS(OctomapServerControl, rviz::Panel) From 7a8846caa297f05cb884f3c5c0379f79cb1eabd6 Mon Sep 17 00:00:00 2001 From: Wolfgang Merkt Date: Tue, 24 Jan 2017 19:20:10 +0000 Subject: [PATCH 2/2] Added Changelog --- CHANGELOG.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d1fa168..520226a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,7 @@ +0.?.? (2017-??-??) +------------------ +* Add OctomapServerControl Panel to trigger resetting the octomap from rviz. + 0.1.0 (2016-07-07) ------------------ * Remove -ldefault_plugin from linker options, fixes `#19 `_