motion_planning_frame.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
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 THE
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: Ioan Sucan */
36 
37 #ifndef MOVEIT_MOTION_PLANNING_RVIZ_PLUGIN_MOTION_PLANNING_FRAME_
38 #define MOVEIT_MOTION_PLANNING_RVIZ_PLUGIN_MOTION_PLANNING_FRAME_
39 
40 #include <QWidget>
41 #include <QTreeWidgetItem>
42 #include <QListWidgetItem>
43 
44 #ifndef Q_MOC_RUN
54 #include <moveit_msgs/MotionPlanRequest.h>
56 #include <object_recognition_msgs/ObjectRecognitionAction.h>
57 
58 #include <std_msgs/Bool.h>
59 #include <std_msgs/Empty.h>
60 #endif
61 
62 #include <map>
63 #include <string>
64 #include <memory>
65 
66 namespace rviz
67 {
68 class DisplayContext;
69 }
70 
71 namespace Ui
72 {
73 class MotionPlanningUI;
74 }
75 
76 namespace moveit_warehouse
77 {
78 MOVEIT_CLASS_FORWARD(PlanningSceneStorage);
79 MOVEIT_CLASS_FORWARD(ConstraintsStorage);
80 MOVEIT_CLASS_FORWARD(RobotStateStorage);
81 }
82 
83 namespace moveit_rviz_plugin
84 {
85 class MotionPlanningDisplay;
86 
87 const std::string OBJECT_RECOGNITION_ACTION = "/recognize_objects";
88 
89 static const std::string TAB_CONTEXT = "Context";
90 static const std::string TAB_PLANNING = "Planning";
91 static const std::string TAB_MANIPULATION = "Manipulation";
92 static const std::string TAB_OBJECTS = "Scene Objects";
93 static const std::string TAB_SCENES = "Stored Scenes";
94 static const std::string TAB_STATES = "Stored States";
95 static const std::string TAB_STATUS = "Status";
96 
97 class MotionPlanningFrame : public QWidget
98 {
99  friend class MotionPlanningDisplay;
100  Q_OBJECT
101 
102 public:
103  MotionPlanningFrame(MotionPlanningDisplay* pdisplay, rviz::DisplayContext* context, QWidget* parent = 0);
105 
106  void changePlanningGroup();
107  void enable();
108  void disable();
110 
111 protected:
112  static const int ITEM_TYPE_SCENE = 1;
113  static const int ITEM_TYPE_QUERY = 2;
114 
115  void constructPlanningRequest(moveit_msgs::MotionPlanRequest& mreq);
116 
117  void updateSceneMarkers(float wall_dt, float ros_dt);
118 
119  void updateExternalCommunication();
120 
123  Ui::MotionPlanningUI* ui_;
124 
125  moveit::planning_interface::MoveGroupInterfacePtr move_group_;
126  moveit::planning_interface::PlanningSceneInterfacePtr planning_scene_interface_;
127  moveit::semantic_world::SemanticWorldPtr semantic_world_;
128 
129  moveit::planning_interface::MoveGroupInterface::PlanPtr current_plan_;
130  moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage_;
131  moveit_warehouse::ConstraintsStoragePtr constraints_storage_;
132  moveit_warehouse::RobotStateStoragePtr robot_state_storage_;
133 
134  std::shared_ptr<rviz::InteractiveMarker> scene_marker_;
135 
136  typedef std::map<std::string, moveit_msgs::RobotState> RobotStateMap;
137  typedef std::pair<std::string, moveit_msgs::RobotState> RobotStatePair;
138  RobotStateMap robot_states_;
139 
140 Q_SIGNALS:
141  void planningFinished();
142 
143 private Q_SLOTS:
144 
145  // Context tab
146  void databaseConnectButtonClicked();
147  void publishSceneButtonClicked();
148  void planningAlgorithmIndexChanged(int index);
149  void resetDbButtonClicked();
150  void approximateIKChanged(int state);
151 
152  // Planning tab
153  void planButtonClicked();
154  void executeButtonClicked();
155  void planAndExecuteButtonClicked();
156  void stopButtonClicked();
157  void allowReplanningToggled(bool checked);
158  void allowLookingToggled(bool checked);
159  void allowExternalProgramCommunication(bool enable);
160  void pathConstraintsIndexChanged(int index);
161  void useStartStateButtonClicked();
162  void useGoalStateButtonClicked();
163  void onClearOctomapClicked();
164 
165  // Scene Objects tab
166  void importFileButtonClicked();
167  void importUrlButtonClicked();
168  void clearSceneButtonClicked();
169  void sceneScaleChanged(int value);
170  void sceneScaleStartChange();
171  void sceneScaleEndChange();
172  void removeObjectButtonClicked();
173  void selectedCollisionObjectChanged();
174  void objectPoseValueChanged(double value);
175  void collisionObjectChanged(QListWidgetItem* item);
176  void imProcessFeedback(visualization_msgs::InteractiveMarkerFeedback& feedback);
177  void copySelectedCollisionObject();
178  void exportAsTextButtonClicked();
179  void importFromTextButtonClicked();
180 
181  // Stored scenes tab
182  void saveSceneButtonClicked();
183  void planningSceneItemClicked();
184  void saveQueryButtonClicked();
185  void deleteSceneButtonClicked();
186  void deleteQueryButtonClicked();
187  void loadSceneButtonClicked();
188  void loadQueryButtonClicked();
189  void warehouseItemNameChanged(QTreeWidgetItem* item, int column);
190 
191  // States tab
192  void loadStateButtonClicked();
193  void saveStartStateButtonClicked();
194  void saveGoalStateButtonClicked();
195  void removeStateButtonClicked();
196  void clearStatesButtonClicked();
197  void setAsStartStateButtonClicked();
198  void setAsGoalStateButtonClicked();
199 
200  // Pick and place
201  void detectObjectsButtonClicked();
202  void pickObjectButtonClicked();
203  void placeObjectButtonClicked();
204  void selectedDetectedObjectChanged();
205  void detectedObjectChanged(QListWidgetItem* item);
206  void selectedSupportSurfaceChanged();
207 
208  // General
209  void tabChanged(int index);
210 
211 private:
212  // Context tab
213  void computeDatabaseConnectButtonClicked();
214  void computeDatabaseConnectButtonClickedHelper(int mode);
215  void computeResetDbButtonClicked(const std::string& db);
216  void populatePlannersList(const moveit_msgs::PlannerInterfaceDescription& desc);
217 
218  // Planning tab
219  void computePlanButtonClicked();
220  void computeExecuteButtonClicked();
221  void computePlanAndExecuteButtonClicked();
222  void computePlanAndExecuteButtonClickedDisplayHelper();
223  void computeStopButtonClicked();
224  void onFinishedExecution(bool success);
225  void populateConstraintsList();
226  void populateConstraintsList(const std::vector<std::string>& constr);
227  void configureForPlanning();
228  void configureWorkspace();
229  void updateQueryStateHelper(robot_state::RobotState& state, const std::string& v);
230  void fillStateSelectionOptions();
231  void useStartStateButtonExec();
232  void useGoalStateButtonExec();
233 
234  // Scene objects tab
235  void addObject(const collision_detection::WorldPtr& world, const std::string& id, const shapes::ShapeConstPtr& shape,
236  const Eigen::Affine3d& pose);
237  void updateCollisionObjectPose(bool update_marker_position);
238  void createSceneInteractiveMarker();
239  void renameCollisionObject(QListWidgetItem* item);
240  void attachDetachCollisionObject(QListWidgetItem* item);
241  void populateCollisionObjectsList();
242  void computeImportFromText(const std::string& path);
243  void computeExportAsText(const std::string& path);
244 
245  // Stored scenes tab
246  void computeSaveSceneButtonClicked();
247  void computeSaveQueryButtonClicked(const std::string& scene, const std::string& query_name);
248  void computeLoadSceneButtonClicked();
249  void computeLoadQueryButtonClicked();
250  void populatePlanningSceneTreeView();
251  void computeDeleteSceneButtonClicked();
252  void computeDeleteQueryButtonClicked();
253  void computeDeleteQueryButtonClickedHelper(QTreeWidgetItem* s);
254  void checkPlanningSceneTreeEnabledButtons();
255 
256  // States tab
257  void saveRobotStateButtonClicked(const robot_state::RobotState& state);
258  void populateRobotStatesList();
259 
260  // Pick and place
261  void processDetectedObjects();
262  void updateDetectedObjectsList(const std::vector<std::string>& object_ids, const std::vector<std::string>& objects);
263  void publishTables();
264  void updateSupportSurfacesList();
266  std::map<std::string, std::string> pick_object_name_;
267  std::string place_object_name_;
268  std::vector<geometry_msgs::PoseStamped> place_poses_;
269  void pickObject();
270  void placeObject();
271  void triggerObjectDetection();
272  void updateTables();
274  // For coloring
277 
278  std::unique_ptr<actionlib::SimpleActionClient<object_recognition_msgs::ObjectRecognitionAction> >
280  template <typename T>
281  void waitForAction(const T& action, const ros::NodeHandle& node_handle, const ros::Duration& wait_for_server,
282  const std::string& name);
283  void listenDetectedObjects(const object_recognition_msgs::RecognizedObjectArrayPtr& msg);
285 
293  // General
294  void changePlanningGroupHelper();
295  void importResource(const std::string& path);
296  void loadStoredStates(const std::string& pattern);
297 
298  void remotePlanCallback(const std_msgs::EmptyConstPtr& msg);
299  void remoteExecuteCallback(const std_msgs::EmptyConstPtr& msg);
300  void remoteStopCallback(const std_msgs::EmptyConstPtr& msg);
301  void remoteUpdateStartStateCallback(const std_msgs::EmptyConstPtr& msg);
302  void remoteUpdateGoalStateCallback(const std_msgs::EmptyConstPtr& msg);
303  void remoteUpdateCustomStartStateCallback(const moveit_msgs::RobotStateConstPtr& msg);
304  void remoteUpdateCustomGoalStateCallback(const moveit_msgs::RobotStateConstPtr& msg);
305 
306  /* Selects or unselects a item in a list by the item name */
307  void setItemSelectionInList(const std::string& item_name, bool selection, QListWidget* list);
308 
312 
314 
315  std::vector<std::pair<std::string, bool> > known_collision_objects_;
319 };
320 
321 // \todo THIS IS REALLY BAD. NEED TO MOVE THIS AND RELATED FUNCTIONALITY OUT OF HERE
322 template <typename T>
323 void MotionPlanningFrame::waitForAction(const T& action, const ros::NodeHandle& node_handle,
324  const ros::Duration& wait_for_server, const std::string& name)
325 {
326  ROS_DEBUG("Waiting for MoveGroup action server (%s)...", name.c_str());
327 
328  // in case ROS time is published, wait for the time data to arrive
329  ros::Time start_time = ros::Time::now();
330  while (start_time == ros::Time::now())
331  {
332  ros::WallDuration(0.01).sleep();
333  ros::spinOnce();
334  }
335 
336  // wait for the server (and spin as needed)
337  if (wait_for_server == ros::Duration(0, 0))
338  {
339  // wait forever until action server connects
340  while (node_handle.ok() && !action->isServerConnected())
341  {
342  ros::WallDuration(0.02).sleep();
343  ros::spinOnce();
344  }
345  }
346  else
347  {
348  // wait for a limited amount of non-simulated time
349  ros::WallTime final_time = ros::WallTime::now() + ros::WallDuration(wait_for_server.toSec());
350  while (node_handle.ok() && !action->isServerConnected() && final_time > ros::WallTime::now())
351  {
352  ros::WallDuration(0.02).sleep();
353  ros::spinOnce();
354  }
355  }
356 
357  if (!action->isServerConnected())
358  throw std::runtime_error("Unable to connect to move_group action server within allotted time");
359  else
360  ROS_DEBUG("Connected to '%s'", name.c_str());
361 };
362 }
363 
364 #endif
MOVEIT_CLASS_FORWARD(RobotStateVisualization)
moveit::planning_interface::MoveGroupInterface::PlanPtr current_plan_
std::map< std::string, moveit_msgs::RobotState > RobotStateMap
static const std::string TAB_OBJECTS
static const std::string TAB_CONTEXT
static const std::string TAB_STATES
World::ObjectConstPtr ObjectConstPtr
moveit::planning_interface::MoveGroupInterfacePtr move_group_
bool sleep() const
moveit_warehouse::RobotStateStoragePtr robot_state_storage_
moveit_warehouse::ConstraintsStoragePtr constraints_storage_
static const std::string TAB_SCENES
const std::string OBJECT_RECOGNITION_ACTION
std::vector< std::pair< std::string, bool > > known_collision_objects_
static WallTime now()
std::shared_ptr< rviz::InteractiveMarker > scene_marker_
std::pair< std::string, moveit_msgs::RobotState > RobotStatePair
static Time now()
std::vector< geometry_msgs::PoseStamped > place_poses_
std::map< std::string, std::string > pick_object_name_
static const std::string TAB_MANIPULATION
static const std::string TAB_PLANNING
bool ok() const
ROSCPP_DECL void spinOnce()
collision_detection::CollisionWorld::ObjectConstPtr scaled_object_
static const std::string TAB_STATUS
moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage_
std::unique_ptr< actionlib::SimpleActionClient< object_recognition_msgs::ObjectRecognitionAction > > object_recognition_client_
moveit::planning_interface::PlanningSceneInterfacePtr planning_scene_interface_
moveit::semantic_world::SemanticWorldPtr semantic_world_
#define ROS_DEBUG(...)
std::shared_ptr< const Shape > ShapeConstPtr


visualization
Author(s): Ioan Sucan , Dave Coleman , Sachin Chitta
autogenerated on Sun Oct 18 2020 13:19:08