perception_widget.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Mohamad Ayman.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * The name of Mohamad Ayman may not be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *********************************************************************/
33 
34 /* Author: Mohamad Ayman */
35 
36 // SA
37 #include "perception_widget.h"
38 #include "header_widget.h"
39 
40 // Qt
41 #include <QApplication>
42 #include <QComboBox>
43 #include <QFormLayout>
44 #include <QGroupBox>
45 #include <QLabel>
46 #include <QLineEdit>
47 #include <QVBoxLayout>
48 
49 namespace moveit_setup_assistant
50 {
51 // ******************************************************************************************
52 // Constructor
53 // ******************************************************************************************
54 PerceptionWidget::PerceptionWidget(QWidget* parent, const MoveItConfigDataPtr& config_data)
55  : SetupScreenWidget(parent), config_data_(config_data)
56 {
57  // Basic widget container
58  QVBoxLayout* layout = new QVBoxLayout();
59  layout->setAlignment(Qt::AlignTop);
60 
61  // Top Header Area ------------------------------------------------
62 
63  HeaderWidget* header =
64  new HeaderWidget("Setup 3D Perception Sensors",
65  "Configure your 3D sensors to work with MoveIt "
66  "Please see <a "
67  "href='http://docs.ros.org/kinetic/api/moveit_tutorials/html/doc/perception_pipeline/"
68  "perception_pipeline_tutorial.html'>Perception Documentation</a> "
69  "for more details.",
70  this);
71  layout->addWidget(header);
72 
73  // Add spacing
74  QSpacerItem* blank_space = new QSpacerItem(1, 8);
75  layout->addSpacerItem(blank_space);
76 
77  // Plugin type combo box
78  QLabel* plugin_field_title = new QLabel(this);
79  plugin_field_title->setText("Optionally choose a type of 3D sensor plugin to configure:");
80  layout->addWidget(plugin_field_title);
81 
82  sensor_plugin_field_ = new QComboBox(this);
83  sensor_plugin_field_->setEditable(false);
84  sensor_plugin_field_->setMaximumWidth(600);
85  connect(sensor_plugin_field_, SIGNAL(currentIndexChanged(int)), this, SLOT(sensorPluginChanged(int)));
86  layout->addWidget(sensor_plugin_field_);
87 
88  // Point Cloud group -------------------------------------------
89  point_cloud_group_ = new QGroupBox("Point Cloud");
90 
91  QFormLayout* point_cloud_form_layout = new QFormLayout();
92  point_cloud_form_layout->setContentsMargins(0, 15, 0, 15);
93 
94  // Point Cloud Topic
95  point_cloud_topic_field_ = new QLineEdit(this);
96  point_cloud_topic_field_->setMaximumWidth(400);
97  point_cloud_form_layout->addRow("Point Cloud Topic:", point_cloud_topic_field_);
98 
99  // Max Range
100  max_range_field_ = new QLineEdit(this);
101  max_range_field_->setMaximumWidth(400);
102  point_cloud_form_layout->addRow("Max Range:", max_range_field_);
103 
104  // Point Subsample
105  point_subsample_field_ = new QLineEdit(this);
106  point_subsample_field_->setMaximumWidth(400);
107  point_cloud_form_layout->addRow("Point Subsample:", point_subsample_field_);
108 
109  // Padding Offset
110  padding_offset_field_ = new QLineEdit(this);
111  padding_offset_field_->setMaximumWidth(400);
112  point_cloud_form_layout->addRow("Padding Offset:", padding_offset_field_);
113 
114  // Padding Scale
115  padding_scale_field_ = new QLineEdit(this);
116  padding_scale_field_->setMaximumWidth(400);
117  point_cloud_form_layout->addRow("Padding Scale:", padding_scale_field_);
118 
119  // Filtered Cloud Topic
120  filtered_cloud_topic_field_ = new QLineEdit(this);
121  filtered_cloud_topic_field_->setMaximumWidth(400);
122  point_cloud_form_layout->addRow("Filtered Cloud Topic:", filtered_cloud_topic_field_);
123 
124  // Max Update Rate
125  max_update_rate_field_ = new QLineEdit(this);
126  max_update_rate_field_->setMaximumWidth(400);
127  point_cloud_form_layout->addRow("Max Update Rate:", max_update_rate_field_);
128 
129  // Piont Cloud form layout
130  point_cloud_group_->setLayout(point_cloud_form_layout);
131  layout->addWidget(point_cloud_group_);
132 
133  // Depth map group --------------------------------------------
134  depth_map_group_ = new QGroupBox("Depth Map");
135 
136  // Depth Map form layout
137  QFormLayout* depth_map_form_layout = new QFormLayout();
138  depth_map_form_layout->setContentsMargins(0, 15, 0, 15);
139 
140  // Image Topic
141  image_topic_field_ = new QLineEdit(this);
142  image_topic_field_->setMaximumWidth(400);
143  depth_map_form_layout->addRow("Image Topic:", image_topic_field_);
144 
145  // Queue Size
146  queue_size_field_ = new QLineEdit(this);
147  queue_size_field_->setMaximumWidth(400);
148  depth_map_form_layout->addRow("Queue Size:", queue_size_field_);
149 
150  // Near Clipping Plane Distance
151  near_clipping_field_ = new QLineEdit(this);
152  near_clipping_field_->setMaximumWidth(400);
153  depth_map_form_layout->addRow("Near Clipping Plane Distance:", near_clipping_field_);
154 
155  // Far Clipping Plane Distance
156  far_clipping_field_ = new QLineEdit(this);
157  far_clipping_field_->setMaximumWidth(400);
158  depth_map_form_layout->addRow("Far Clipping Plane Distance:", far_clipping_field_);
159 
160  // Shadow Threshold
161  shadow_threshold_field_ = new QLineEdit(this);
162  shadow_threshold_field_->setMaximumWidth(400);
163  depth_map_form_layout->addRow("Shadow Threshold:", shadow_threshold_field_);
164 
165  // Padding Offset
166  depth_padding_offset_field_ = new QLineEdit(this);
167  depth_padding_offset_field_->setMaximumWidth(400);
168  depth_map_form_layout->addRow("Padding Offset:", depth_padding_offset_field_);
169 
170  // Padding Scale
171  depth_padding_scale_field_ = new QLineEdit(this);
172  depth_padding_scale_field_->setMaximumWidth(400);
173  depth_map_form_layout->addRow("Padding Scale:", depth_padding_scale_field_);
174 
175  // Filtered Cloud Topic
176  depth_filtered_cloud_topic_field_ = new QLineEdit(this);
177  depth_filtered_cloud_topic_field_->setMaximumWidth(400);
178  depth_map_form_layout->addRow("Filtered Cloud Topic:", depth_filtered_cloud_topic_field_);
179 
180  // Filtered Cloud Topic
181  depth_max_update_rate_field_ = new QLineEdit(this);
182  depth_max_update_rate_field_->setMaximumWidth(400);
183  depth_map_form_layout->addRow("Max Update Rate:", depth_max_update_rate_field_);
184 
185  depth_map_group_->setLayout(depth_map_form_layout);
186  layout->addWidget(depth_map_group_);
187 
188  layout->setAlignment(Qt::AlignTop);
189 
190  // Finish Layout --------------------------------------------------
191  this->setLayout(layout);
192 }
193 
194 // ******************************************************************************************
195 // Received when this widget is chosen from the navigation menu
196 // ******************************************************************************************
198 {
200 }
201 
202 // ******************************************************************************************
203 // Received when another widget is chosen from the navigation menu
204 // ******************************************************************************************
206 {
207  // Save the sensor plugin configuration to sensors_plugin_config data structure
208  if (sensor_plugin_field_->currentIndex() == 1)
209  {
210  config_data_->clearSensorPluginConfig();
211 
212  // Point Cloud plugin fields
213  config_data_->addGenericParameterToSensorPluginConfig("sensor_plugin", "occupancy_map_monitor/"
214  "PointCloudOctomapUpdater");
215  config_data_->addGenericParameterToSensorPluginConfig("point_cloud_topic",
216  point_cloud_topic_field_->text().trimmed().toStdString());
217  config_data_->addGenericParameterToSensorPluginConfig("max_range", max_range_field_->text().trimmed().toStdString());
218  config_data_->addGenericParameterToSensorPluginConfig("point_subsample",
219  point_subsample_field_->text().trimmed().toStdString());
220  config_data_->addGenericParameterToSensorPluginConfig("padding_offset",
221  padding_offset_field_->text().trimmed().toStdString());
222  config_data_->addGenericParameterToSensorPluginConfig("padding_scale",
223  padding_scale_field_->text().trimmed().toStdString());
224  config_data_->addGenericParameterToSensorPluginConfig("max_update_rate",
225  max_update_rate_field_->text().trimmed().toStdString());
226  config_data_->addGenericParameterToSensorPluginConfig("filtered_cloud_topic",
227  filtered_cloud_topic_field_->text().trimmed().toStdString());
228 
230  }
231  else if (sensor_plugin_field_->currentIndex() == 2)
232  {
233  config_data_->clearSensorPluginConfig();
234 
235  // Depth Map plugin fields
236  config_data_->addGenericParameterToSensorPluginConfig("sensor_plugin", "occupancy_map_monitor/"
237  "DepthImageOctomapUpdater");
238  config_data_->addGenericParameterToSensorPluginConfig("image_topic",
239  image_topic_field_->text().trimmed().toStdString());
240  config_data_->addGenericParameterToSensorPluginConfig("queue_size",
241  queue_size_field_->text().trimmed().toStdString());
242  config_data_->addGenericParameterToSensorPluginConfig("near_clipping_plane_distance",
243  near_clipping_field_->text().trimmed().toStdString());
244  config_data_->addGenericParameterToSensorPluginConfig("far_clipping_plane_distance",
245  far_clipping_field_->text().trimmed().toStdString());
246  config_data_->addGenericParameterToSensorPluginConfig("shadow_threshold",
247  shadow_threshold_field_->text().trimmed().toStdString());
248  config_data_->addGenericParameterToSensorPluginConfig("padding_scale",
249  depth_padding_scale_field_->text().trimmed().toStdString());
250  config_data_->addGenericParameterToSensorPluginConfig("padding_offset",
251  depth_padding_offset_field_->text().trimmed().toStdString());
252  config_data_->addGenericParameterToSensorPluginConfig(
253  "filtered_cloud_topic", depth_filtered_cloud_topic_field_->text().trimmed().toStdString());
254  config_data_->addGenericParameterToSensorPluginConfig("max_update_rate",
255  depth_max_update_rate_field_->text().trimmed().toStdString());
256 
258  }
259  else
260  {
261  // Clear the sensors_plugin_config data structure
262  config_data_->clearSensorPluginConfig();
264  }
265  return true;
266 }
267 
269 {
270  if (index == 1)
271  {
272  // Point cloud form visible, depth map form invisible
273  point_cloud_group_->setVisible(true);
274  depth_map_group_->setVisible(false);
275  }
276  else if (index == 2)
277  {
278  // Depth map form visible, point cloud form invisible
279  point_cloud_group_->setVisible(false);
280  depth_map_group_->setVisible(true);
281  }
282  else
283  {
284  // All forms invisible
285  point_cloud_group_->setVisible(false);
286  depth_map_group_->setVisible(false);
287  }
288 }
289 
290 uint PerceptionWidget::loadConfigIntoWidgets(std::map<std::string, GenericParameter> sensor_plugin_config)
291 {
292  if (sensor_plugin_config["sensor_plugin"].getValue() == "occupancy_map_monitor/PointCloudOctomapUpdater")
293  {
294  point_cloud_topic_field_->setText(QString(sensor_plugin_config["point_cloud_topic"].getValue().c_str()));
295  max_range_field_->setText(QString(sensor_plugin_config["max_range"].getValue().c_str()));
296  point_subsample_field_->setText(QString(sensor_plugin_config["point_subsample"].getValue().c_str()));
297  padding_offset_field_->setText(QString(sensor_plugin_config["padding_offset"].getValue().c_str()));
298  padding_scale_field_->setText(QString(sensor_plugin_config["padding_scale"].getValue().c_str()));
299  max_update_rate_field_->setText(QString(sensor_plugin_config["max_update_rate"].getValue().c_str()));
300  filtered_cloud_topic_field_->setText(QString(sensor_plugin_config["filtered_cloud_topic"].getValue().c_str()));
301  return 1;
302  }
303  else if (sensor_plugin_config["sensor_plugin"].getValue() == "occupancy_map_monitor/DepthImageOctomapUpdater")
304  {
305  image_topic_field_->setText(QString(sensor_plugin_config["image_topic"].getValue().c_str()));
306  queue_size_field_->setText(QString(sensor_plugin_config["queue_size"].getValue().c_str()));
307  near_clipping_field_->setText(QString(sensor_plugin_config["near_clipping_plane_distance"].getValue().c_str()));
308  far_clipping_field_->setText(QString(sensor_plugin_config["far_clipping_plane_distance"].getValue().c_str()));
309  shadow_threshold_field_->setText(QString(sensor_plugin_config["shadow_threshold"].getValue().c_str()));
310  depth_padding_scale_field_->setText(QString(sensor_plugin_config["padding_scale"].getValue().c_str()));
311  depth_padding_offset_field_->setText(QString(sensor_plugin_config["padding_offset"].getValue().c_str()));
312  depth_filtered_cloud_topic_field_->setText(QString(sensor_plugin_config["filtered_cloud_topic"].getValue().c_str()));
313  depth_max_update_rate_field_->setText(QString(sensor_plugin_config["max_update_rate"].getValue().c_str()));
314  return 2;
315  }
316  return 0;
317 }
318 
320 {
321  // Only load this combo box once
322  static bool has_loaded = false;
323  if (has_loaded)
324  return;
325  has_loaded = true;
326 
327  // Add None option, the default
328  sensor_plugin_field_->addItem("None");
329  sensor_plugin_field_->setCurrentIndex(0);
330 
331  // Add the two avilable plugins to combo box
332  sensor_plugin_field_->addItem("Point Cloud");
333  sensor_plugin_field_->addItem("Depth Map");
334 
335  // Load values from default config
336  auto default_config = MoveItConfigData::load3DSensorsYAML(
337  config_data_->setup_assistant_path_ + "/templates/moveit_config_pkg_template/config/sensors_3d.yaml");
338  for (const auto& sensor_plugin_config : default_config)
339  loadConfigIntoWidgets(sensor_plugin_config);
340 
341  // Load values from existing config
342  uint idx = 0;
343  for (const auto& sensor_plugin_config : config_data_->getSensorPluginConfig())
344  idx = loadConfigIntoWidgets(sensor_plugin_config);
345  sensor_plugin_field_->setCurrentIndex(idx);
346 }
347 
348 } // namespace moveit_setup_assistant
moveit_setup_assistant::PerceptionWidget::depth_padding_scale_field_
QLineEdit * depth_padding_scale_field_
Definition: perception_widget.h:101
moveit_setup_assistant::PerceptionWidget::config_data_
moveit_setup_assistant::MoveItConfigDataPtr config_data_
Contains all the configuration data for the setup assistant.
Definition: perception_widget.h:121
moveit_setup_assistant::MoveItConfigData::SENSORS_CONFIG
@ SENSORS_CONFIG
Definition: moveit_config_data.h:238
moveit_setup_assistant::PerceptionWidget::loadSensorPluginsComboBox
void loadSensorPluginsComboBox()
Populate the combo dropdown box with sensor plugins.
Definition: perception_widget.cpp:350
moveit_setup_assistant::PerceptionWidget::focusLost
bool focusLost() override
Received when another widget is chosen from the navigation menu.
Definition: perception_widget.cpp:236
moveit_setup_assistant::PerceptionWidget::PerceptionWidget
PerceptionWidget(QWidget *parent, const MoveItConfigDataPtr &config_data)
Definition: perception_widget.cpp:85
moveit_setup_assistant::PerceptionWidget::sensorPluginChanged
void sensorPluginChanged(int index)
Called when the selected item in the sensor_plugin_field_ combobox is changed.
Definition: perception_widget.cpp:299
moveit_setup_assistant::PerceptionWidget::padding_offset_field_
QLineEdit * padding_offset_field_
Definition: perception_widget.h:90
perception_widget.h
moveit_setup_assistant::PerceptionWidget::depth_padding_offset_field_
QLineEdit * depth_padding_offset_field_
Definition: perception_widget.h:102
moveit_setup_assistant::PerceptionWidget::filtered_cloud_topic_field_
QLineEdit * filtered_cloud_topic_field_
Definition: perception_widget.h:93
moveit_setup_assistant::PerceptionWidget::image_topic_field_
QLineEdit * image_topic_field_
Definition: perception_widget.h:96
moveit_setup_assistant::PerceptionWidget::padding_scale_field_
QLineEdit * padding_scale_field_
Definition: perception_widget.h:91
SetupScreenWidget
Definition: setup_screen_widget.h:44
moveit_setup_assistant::PerceptionWidget::shadow_threshold_field_
QLineEdit * shadow_threshold_field_
Definition: perception_widget.h:100
moveit_setup_assistant::PerceptionWidget::point_cloud_topic_field_
QLineEdit * point_cloud_topic_field_
Definition: perception_widget.h:87
moveit_setup_assistant::MoveItConfigData::load3DSensorsYAML
static std::vector< std::map< std::string, GenericParameter > > load3DSensorsYAML(const std::string &file_path)
Load perception sensor config.
Definition: moveit_config_data.cpp:1863
moveit_setup_assistant::PerceptionWidget::point_cloud_group_
QGroupBox * point_cloud_group_
Definition: perception_widget.h:83
moveit_setup_assistant::PerceptionWidget::depth_filtered_cloud_topic_field_
QLineEdit * depth_filtered_cloud_topic_field_
Definition: perception_widget.h:103
moveit_setup_assistant::PerceptionWidget::queue_size_field_
QLineEdit * queue_size_field_
Definition: perception_widget.h:97
moveit_setup_assistant::PerceptionWidget::near_clipping_field_
QLineEdit * near_clipping_field_
Definition: perception_widget.h:98
header_widget.h
moveit_setup_assistant
Definition: compute_default_collisions.h:46
moveit_setup_assistant::PerceptionWidget::depth_map_group_
QGroupBox * depth_map_group_
Definition: perception_widget.h:84
moveit_setup_assistant::PerceptionWidget::focusGiven
void focusGiven() override
Received when this widget is chosen from the navigation menu.
Definition: perception_widget.cpp:228
moveit_setup_assistant::PerceptionWidget::max_update_rate_field_
QLineEdit * max_update_rate_field_
Definition: perception_widget.h:92
moveit_setup_assistant::PerceptionWidget::sensor_plugin_field_
QComboBox * sensor_plugin_field_
Definition: perception_widget.h:80
moveit_setup_assistant::PerceptionWidget::point_subsample_field_
QLineEdit * point_subsample_field_
Definition: perception_widget.h:89
moveit_setup_assistant::PerceptionWidget::far_clipping_field_
QLineEdit * far_clipping_field_
Definition: perception_widget.h:99
header
const std::string header
moveit_setup_assistant::PerceptionWidget::max_range_field_
QLineEdit * max_range_field_
Definition: perception_widget.h:88
moveit_setup_assistant::PerceptionWidget::depth_max_update_rate_field_
QLineEdit * depth_max_update_rate_field_
Definition: perception_widget.h:104
moveit_setup_assistant::PerceptionWidget::loadConfigIntoWidgets
uint loadConfigIntoWidgets(std::map< std::string, GenericParameter > sensor_plugin_config)
Definition: perception_widget.cpp:321


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Sat May 3 2025 02:28:04