41 const std::string
LOGNAME =
"handeye_target_widget";
89 , calibration_display_(pdisplay)
92 , target_plugins_loader_(nullptr)
94 , target_param_layout_(new QFormLayout())
97 QHBoxLayout* layout =
new QHBoxLayout();
98 this->setLayout(layout);
99 QVBoxLayout* layout_left =
new QVBoxLayout();
100 layout->addLayout(layout_left);
103 QGroupBox* group_left_top =
new QGroupBox(
"Target Params",
this);
105 layout_left->addWidget(group_left_top);
106 group_left_top->setLayout(target_param_layout_);
108 target_type_ =
new QComboBox();
109 connect(target_type_, SIGNAL(activated(
const QString&)),
this, SLOT(targetTypeComboboxChanged(
const QString&)));
110 target_param_layout_->addRow(
"Target Type", target_type_);
113 QGroupBox* group_left_bottom =
new QGroupBox(
"Target Pose Detection",
this);
114 layout_left->addWidget(group_left_bottom);
115 QFormLayout* layout_left_bottom =
new QFormLayout();
116 group_left_bottom->setLayout(layout_left_bottom);
118 ros_topics_.insert(std::make_pair(
"image_topic",
new RosTopicComboBox(
this)));
119 ros_topics_[
"image_topic"]->addMsgsFilterType(
"sensor_msgs/Image");
120 layout_left_bottom->addRow(
"Image Topic", ros_topics_[
"image_topic"]);
121 connect(ros_topics_[
"image_topic"], SIGNAL(activated(
const QString&)),
this,
122 SLOT(imageTopicComboboxChanged(
const QString&)));
124 ros_topics_.insert(std::make_pair(
"camera_info_topic",
new RosTopicComboBox(
this)));
125 ros_topics_[
"camera_info_topic"]->addMsgsFilterType(
"sensor_msgs/CameraInfo");
126 layout_left_bottom->addRow(
"CameraInfo Topic", ros_topics_[
"camera_info_topic"]);
127 connect(ros_topics_[
"camera_info_topic"], SIGNAL(activated(
const QString&)),
this,
128 SLOT(cameraInfoComboBoxChanged(
const QString&)));
131 QGroupBox* group_right =
new QGroupBox(
"Target",
this);
132 group_right->setMinimumWidth(330);
133 layout->addWidget(group_right);
134 QVBoxLayout* layout_right =
new QVBoxLayout();
135 group_right->setLayout(layout_right);
137 target_display_label_ =
new QLabel();
138 target_display_label_->setAlignment(Qt::AlignHCenter);
139 layout_right->addWidget(target_display_label_);
141 QPushButton* create_target_btn =
new QPushButton(
"Create Target");
142 layout_right->addWidget(create_target_btn);
143 connect(create_target_btn, SIGNAL(clicked(
bool)),
this, SLOT(createTargetImageBtnClicked(
bool)));
145 QPushButton* save_target_btn =
new QPushButton(
"Save Target");
146 layout_right->addWidget(save_target_btn);
147 connect(save_target_btn, SIGNAL(clicked(
bool)),
this, SLOT(saveTargetImageBtnClicked(
bool)));
150 loadAvailableTargetPlugins();
153 image_pub_ = it_.advertise(
"/handeye_calibration/target_detection", 1);
156 qRegisterMetaType<sensor_msgs::CameraInfo>();
157 qRegisterMetaType<std::string>();
168 if (
config.mapGetString(
"target_type", &type) &&
target_type_->findText(type, Qt::MatchCaseSensitive) != -1)
180 switch (
param.parameter_type_)
182 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Int:
183 if (
config.mapGetInt(
param.name_.c_str(), ¶m_int))
186 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Float:
187 if (
config.mapGetFloat(
param.name_.c_str(), ¶m_float))
190 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Enum:
191 if (
config.mapGetString(
param.name_.c_str(), ¶m_enum))
200 for (
const std::pair<const std::string, RosTopicComboBox*>& topic :
ros_topics_)
203 if (
config.mapGetString(topic.first.c_str(), &topic_name))
205 if (topic.second->hasTopic(topic_name))
207 topic.second->setCurrentText(topic_name);
210 if (!topic.first.compare(
"image_topic"))
216 if (!topic.first.compare(
"camera_info_topic"))
238 switch (
param.parameter_type_)
240 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Int:
241 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Float:
243 config.mapSetValue(
param.name_.c_str(), param_value);
245 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Enum:
247 config.mapSetValue(
param.name_.c_str(), param_value);
252 for (
const std::pair<const std::string, RosTopicComboBox*>& topic :
ros_topics_)
253 config.mapSetValue(topic.first.c_str(), topic.second->currentText());
263 "moveit_calibration_plugins",
"moveit_handeye_calibration::HandEyeTargetBase"));
267 QMessageBox::warning(
this, tr(
"Exception while creating handeye target plugin loader "), tr(ex.what()));
278 QMessageBox::warning(
this, tr(
"Missing target plugins"),
"No MoveIt handeye calibration target plugin found.");
282 for (
const std::string& it : classes)
291 if (plugin_name.empty())
306 switch (
param.parameter_type_)
308 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Int:
313 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Float:
318 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Enum:
319 QComboBox* combo_box =
new QComboBox();
320 for (
const std::string&
value :
param.enum_values_)
322 combo_box->addItem(tr(
value.c_str()));
333 QMessageBox::warning(
this, tr(
"Exception while loading a handeye target plugin"), tr(ex.what()));
350 switch (
param.parameter_type_)
352 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Int:
355 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Float:
359 case moveit_handeye_calibration::HandEyeTargetBase::Parameter::ParameterType::Enum:
369 QMessageBox::warning(
this, tr(
"Exception while loading a handeye target plugin"), tr(ex.what()));
382 if (msg->encoding ==
"16UC1")
385 "Received 16-bit image, which cannot be processed.");
389 std::string frame_id = msg->header.frame_id;
390 if (!frame_id.empty())
402 "Image message has empty frame ID.");
406 if (msg->data.empty())
418 sensor_msgs::ImagePtr pub_msg;
425 if (!
target_->areIntrinsicsReasonable())
429 "Target detector has not received reasonable intrinsics. Attempted detection anyway.");
445 std::string error_message =
"cv_bridge exception: " + std::string(e.what());
449 catch (cv::Exception& e)
451 std::string error_message =
"cv exception: " + std::string(e.what());
459 if (
target_ && msg->height > 0 && msg->width > 0 && !msg->K.empty() && !msg->D.empty() &&
489 QMessageBox::warning(
this, tr(
"Fail to create a target image."),
"No available target plugin.");
496 qimage = qimage.scaledToWidth(320, Qt::SmoothTransformation);
498 qimage = qimage.scaledToHeight(260, Qt::SmoothTransformation);
507 QMessageBox::warning(
this, tr(
"Unable to save image"), tr(
"Please create a target at first."));
513 QFileDialog::getSaveFileName(
this, tr(
"Save Target Image"),
"", tr(
"Target Image (*.png);;All Files (*)"),
514 nullptr, QFileDialog::DontUseNativeDialog);
516 if (fileName.isEmpty())
519 if (!fileName.endsWith(
".png"))
522 QFile file(fileName);
523 if (!file.open(QIODevice::WriteOnly))
525 QMessageBox::warning(
this, tr(
"Unable to open file"), file.errorString());
529 if (!cv::imwrite(cv::String(fileName.toStdString()),
target_image_))
538 if (!topic.isNull() and !topic.isEmpty())
548 "Failed to subscribe to image topic.");
557 "Not subscribed to camera info topic.");
558 if (!topic.isNull() and !topic.isEmpty())
567 "Subscribe to camera info topic: " << topic.toStdString() <<
" failed. " << e.what());
569 "Failed to subscribe to camera info topic.");