1+ /* ********************************************************************
2+ * Software License Agreement (BSD License)
3+ *
4+ * Copyright (c) 2019, Intel Corporation.
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+ * * Neither the name of Willow Garage nor the names of its
18+ * contributors may be used to endorse or promote products derived
19+ * from this software without specific prior written permission.
20+ *
21+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THEsensorPoseUpdate
25+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+ * POSSIBILITY OF SUCH DAMAGE.
33+ *********************************************************************/
34+
35+ /* Author: Yu Yan */
36+
37+ #ifndef MOVEIT_HANDEYE_CALIBRATION_RVIZ_PLUGIN_HANDEYE_CALIBRATE_WIDGET_
38+ #define MOVEIT_HANDEYE_CALIBRATION_RVIZ_PLUGIN_HANDEYE_CALIBRATE_WIDGET_
39+
40+ // qt
41+ #include < QFile>
42+ #include < QLabel>
43+ #include < QString>
44+ #include < QTreeView>
45+ #include < QComboBox>
46+ #include < QGroupBox>
47+ #include < QTextStream>
48+ #include < QFileDialog>
49+ #include < QHBoxLayout>
50+ #include < QFormLayout>
51+ #include < QVBoxLayout>
52+ #include < QPushButton>
53+ #include < QMessageBox>
54+ #include < QProgressBar>
55+ #include < QtConcurrent/QtConcurrent>
56+ #include < QStandardItemModel>
57+
58+ // ros
59+ #include < tf2_eigen/tf2_eigen.h>
60+ #include < pluginlib/class_loader.hpp>
61+ #include < tf2_ros/transform_listener.h>
62+ #include < rviz_visual_tools/tf_visual_tools.h>
63+ #include < moveit/move_group_interface/move_group_interface.h>
64+ #include < moveit/planning_scene_monitor/planning_scene_monitor.h>
65+ #include < moveit/handeye_calibration_solver/handeye_solver_base.h>
66+ #include < moveit/background_processing/background_processing.h>
67+ #include < moveit/motion_planning_rviz_plugin/motion_planning_display.h>
68+
69+ #ifndef Q_MOC_RUN
70+ #include < ros/ros.h>
71+ #include < rviz/panel.h>
72+ #endif
73+
74+ #include < yaml-cpp/yaml.h>
75+
76+ namespace mhc = moveit_handeye_calibration;
77+
78+ namespace moveit_rviz_plugin
79+ {
80+ class ProgressBarWidget : public QWidget
81+ {
82+ Q_OBJECT
83+
84+ public:
85+ ProgressBarWidget (QWidget* parent, int min = 0 , int max = 0 , int value = 0 );
86+
87+ ~ProgressBarWidget () override = default ;
88+
89+ void setMax (int value);
90+ void setMin (int value);
91+ void setValue (int value);
92+ int getValue ();
93+
94+ QLabel* name_label_;
95+ QLabel* value_label_;
96+ QLabel* max_label_;
97+ QProgressBar* bar_;
98+ };
99+
100+ class ControlTabWidget : public QWidget
101+ {
102+ Q_OBJECT
103+ public:
104+ explicit ControlTabWidget (QWidget* parent = Q_NULLPTR);
105+ ~ControlTabWidget ()
106+ {
107+ tf_tools_.reset ();
108+ tf_buffer_.reset ();
109+ solver_.reset ();
110+ solver_plugins_loader_.reset ();
111+ move_group_.reset ();
112+ planning_scene_monitor_.reset ();
113+ }
114+
115+ void loadWidget (const rviz::Config& config);
116+ void saveWidget (rviz::Config& config);
117+
118+ void setTFTool (rviz_visual_tools::TFVisualToolsPtr& tf_pub);
119+
120+ void addPoseSampleToTreeView (const geometry_msgs::TransformStamped& cTo, const geometry_msgs::TransformStamped& bTe,
121+ int id);
122+
123+ bool loadSolverPlugin (std::vector<std::string>& plugins);
124+
125+ bool createSolverInstance (const std::string& plugin_name);
126+
127+ void fillSolverTypes (const std::vector<std::string>& plugins);
128+
129+ std::string parseSolverName (const std::string& solver_name, char delimiter);
130+
131+ bool takeTranformSamples ();
132+
133+ bool solveCameraRobotPose ();
134+
135+ bool frameNamesEmpty ();
136+
137+ bool checkJointStates ();
138+
139+ void computePlan ();
140+
141+ void computeExecution ();
142+
143+ Q_SIGNALS:
144+
145+ void sensorPoseUpdate (double x, double y, double z, double rx, double ry, double rz);
146+
147+ public Q_SLOTS:
148+
149+ void UpdateSensorMountType (int index);
150+
151+ void updateFrameNames (std::map<std::string, std::string> names);
152+
153+ private Q_SLOTS:
154+
155+ void takeSampleBtnClicked (bool clicked);
156+
157+ void resetSampleBtnClicked (bool clicked);
158+
159+ void saveCameraPoseBtnClicked (bool clicked);
160+
161+ void planningGroupNameChanged (const QString& text);
162+
163+ void saveJointStateBtnClicked (bool clicked);
164+
165+ void loadJointStateBtnClicked (bool clicked);
166+
167+ void autoPlanBtnClicked (bool clicked);
168+
169+ void autoExecuteBtnClicked (bool clicked);
170+
171+ void autoSkipBtnClicked (bool clicked);
172+
173+ void planFinished ();
174+
175+ void executeFinished ();
176+
177+ private:
178+ // **************************************************************
179+ // Qt components
180+ // **************************************************************
181+
182+ QTreeView* sample_tree_view_;
183+ QStandardItemModel* tree_view_model_;
184+
185+ QComboBox* calibration_solver_;
186+
187+ // Load & save pose samples and joint goals
188+ QPushButton* save_joint_state_btn_;
189+ QPushButton* load_joint_state_btn_;
190+ QPushButton* save_camera_pose_btn_;
191+
192+ // Manual calibration
193+ QPushButton* take_sample_btn_;
194+ QPushButton* reset_sample_btn_;
195+
196+ // Auto calibration
197+ QComboBox* group_name_;
198+ QPushButton* auto_plan_btn_;
199+ QPushButton* auto_execute_btn_;
200+ QPushButton* auto_skip_btn_;
201+
202+ // Progress of finished joint states for auto calibration
203+ ProgressBarWidget* auto_progress_;
204+
205+ QFutureWatcher<void >* plan_watcher_;
206+ QFutureWatcher<void >* execution_watcher_;
207+
208+ // **************************************************************
209+ // Variables
210+ // **************************************************************
211+
212+ mhc::SensorMountType sensor_mount_type_;
213+ std::map<std::string, std::string> frame_names_;
214+ // Transform samples
215+ std::vector<Eigen::Isometry3d> effector_wrt_world_;
216+ std::vector<Eigen::Isometry3d> object_wrt_sensor_;
217+ std::string from_frame_tag_;
218+ Eigen::Isometry3d camera_robot_pose_;
219+ std::vector<std::vector<double >> joint_states_;
220+ std::vector<std::string> joint_names_;
221+ bool auto_started_;
222+ bool planning_res_;
223+
224+ // **************************************************************
225+ // Ros components
226+ // **************************************************************
227+
228+ ros::NodeHandle nh_;
229+ // ros::CallbackQueue callback_queue_;
230+ // ros::AsyncSpinner spinner_;
231+ std::shared_ptr<tf2_ros::Buffer> tf_buffer_;
232+ tf2_ros::TransformListener tf_listener_;
233+ rviz_visual_tools::TFVisualToolsPtr tf_tools_;
234+ std::unique_ptr<pluginlib::ClassLoader<moveit_handeye_calibration::HandEyeSolverBase>> solver_plugins_loader_;
235+ pluginlib::UniquePtr<moveit_handeye_calibration::HandEyeSolverBase> solver_;
236+ planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor_;
237+ moveit::planning_interface::MoveGroupInterfacePtr move_group_;
238+ moveit::planning_interface::MoveGroupInterface::PlanPtr current_plan_;
239+ };
240+
241+ } // namespace moveit_rviz_plugin
242+ #endif
0 commit comments