moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
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#pragma once
38
39#include <QWidget>
40#include <QTreeWidgetItem>
41#include <QListWidgetItem>
42
43#ifndef Q_MOC_RUN
49// TODO (ddengster): Enable when moveit_ros_perception is ported
50// #include <moveit/semantic_world/semantic_world.h>
51
52#include <interactive_markers/interactive_marker_server.hpp>
53#include <rviz_default_plugins/displays/interactive_markers/interactive_marker.hpp>
54#include <moveit_msgs/msg/motion_plan_request.hpp>
55#include <rclcpp_action/rclcpp_action.hpp>
56#include <object_recognition_msgs/action/object_recognition.hpp>
57
58#include <std_msgs/msg/bool.hpp>
59#include <std_msgs/msg/empty.hpp>
60#include <std_srvs/srv/empty.hpp>
61#include <rclcpp/logger.hpp>
62#endif
63
64#include <map>
65#include <string>
66#include <memory>
67
68namespace rviz_common
69{
70class DisplayContext;
71}
72
73namespace Ui
74{
75class MotionPlanningUI;
76}
77
79{
80MOVEIT_CLASS_FORWARD(PlanningSceneStorage); // Defines PlanningSceneStoragePtr, ConstPtr, WeakPtr... etc
81MOVEIT_CLASS_FORWARD(ConstraintsStorage); // Defines ConstraintsStoragePtr, ConstPtr, WeakPtr... etc
82MOVEIT_CLASS_FORWARD(RobotStateStorage); // Defines RobotStateStoragePtr, ConstPtr, WeakPtr... etc
83} // namespace moveit_warehouse
84
85namespace moveit_rviz_plugin
86{
87class MotionPlanningDisplay;
88class MotionPlanningFrameJointsWidget;
89
90const std::string OBJECT_RECOGNITION_ACTION = "/recognize_objects";
91
92static const std::string TAB_CONTEXT = "Context";
93static const std::string TAB_PLANNING = "Planning";
94static const std::string TAB_MANIPULATION = "Manipulation";
95static const std::string TAB_OBJECTS = "Scene Objects";
96static const std::string TAB_SCENES = "Stored Scenes";
97static const std::string TAB_STATES = "Stored States";
98static const std::string TAB_STATUS = "Status";
99
100static const double LARGE_MESH_THRESHOLD = 10.0;
101
102class MotionPlanningFrame : public QWidget
103{
105 Q_OBJECT
106
107public:
109 MotionPlanningFrame(MotionPlanningDisplay* pdisplay, rviz_common::DisplayContext* context, QWidget* parent = nullptr);
110 ~MotionPlanningFrame() override;
111
112 void clearRobotModel();
113 void changePlanningGroup();
114 void enable();
115 void disable();
117
118protected:
119 static const int ITEM_TYPE_SCENE = 1;
120 static const int ITEM_TYPE_QUERY = 2;
121
122 void initFromMoveGroupNS();
123 void constructPlanningRequest(moveit_msgs::msg::MotionPlanRequest& mreq);
124
125 void updateSceneMarkers(double wall_dt, double ros_dt);
126
128
130 rviz_common::DisplayContext* context_;
131 Ui::MotionPlanningUI* ui_;
133
134 moveit::planning_interface::MoveGroupInterfacePtr move_group_;
135 // TODO (ddengster): Enable when moveit_ros_perception is ported
136 // moveit::semantic_world::SemanticWorldPtr semantic_world_;
137
138 moveit::planning_interface::MoveGroupInterface::PlanPtr current_plan_;
139 moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage_;
140 moveit_warehouse::ConstraintsStoragePtr constraints_storage_;
141 moveit_warehouse::RobotStateStoragePtr robot_state_storage_;
142
143 std::shared_ptr<rviz_default_plugins::displays::InteractiveMarker> scene_marker_;
144
145 typedef std::map<std::string, moveit_msgs::msg::RobotState> RobotStateMap;
146 typedef std::pair<std::string, moveit_msgs::msg::RobotState> RobotStatePair;
149 std::vector<moveit_msgs::msg::PlannerInterfaceDescription> planner_descriptions_;
150
151Q_SIGNALS:
154
155private Q_SLOTS:
156
157 // Context tab
158 void databaseConnectButtonClicked();
159 void planningPipelineIndexChanged(int index);
160 void planningAlgorithmIndexChanged(int index);
161 void resetDbButtonClicked();
162 void approximateIKChanged(int state);
163
164 // Planning tab
165 bool computeCartesianPlan();
166 bool computeJointSpacePlan();
167 void planButtonClicked();
168 void executeButtonClicked();
169 void planAndExecuteButtonClicked();
170 void stopButtonClicked();
171 void allowReplanningToggled(bool checked);
172 void allowLookingToggled(bool checked);
173 void allowExternalProgramCommunication(bool enable);
174 void pathConstraintsIndexChanged(int index);
175 void onNewPlanningSceneState();
176 void startStateTextChanged(const QString& start_state);
177 void goalStateTextChanged(const QString& goal_state);
178 void planningGroupTextChanged(const QString& planning_group);
179 void onClearOctomapClicked();
180
181 // Scene Objects tab
182 void clearScene();
183 void publishScene();
184 void publishSceneIfNeeded();
185 void setLocalSceneEdited(bool dirty = true);
186 bool isLocalSceneDirty() const;
187 void sceneScaleChanged(int value);
188 void sceneScaleStartChange();
189 void sceneScaleEndChange();
190 void shapesComboBoxChanged(const QString& text);
191 void addSceneObject();
192 void removeSceneObject();
193 void selectedCollisionObjectChanged();
194 void objectPoseValueChanged(double value);
195 void collisionObjectChanged(QListWidgetItem* item);
196 void imProcessFeedback(visualization_msgs::msg::InteractiveMarkerFeedback& feedback);
197 void copySelectedCollisionObject();
198 void exportGeometryAsTextButtonClicked();
199 void importGeometryFromTextButtonClicked();
200
201 // Stored scenes tab
202 void saveSceneButtonClicked();
203 void planningSceneItemClicked();
204 void saveQueryButtonClicked();
205 void deleteSceneButtonClicked();
206 void deleteQueryButtonClicked();
207 void loadSceneButtonClicked();
208 void loadQueryButtonClicked();
209 void warehouseItemNameChanged(QTreeWidgetItem* item, int column);
210
211 // States tab
212 void loadStateButtonClicked();
213 void saveStartStateButtonClicked();
214 void saveGoalStateButtonClicked();
215 void removeStateButtonClicked();
216 void clearStatesButtonClicked();
217 void setAsStartStateButtonClicked();
218 void setAsGoalStateButtonClicked();
219
220 // Pick and place
221 void detectObjectsButtonClicked();
222 void pickObjectButtonClicked();
223 void placeObjectButtonClicked();
224 void selectedDetectedObjectChanged();
225 void detectedObjectChanged(QListWidgetItem* item);
226 void selectedSupportSurfaceChanged();
227
228 // General
229 void tabChanged(int index);
230
231private:
232 // Context tab
233 void computeDatabaseConnectButtonClicked();
234 void computeDatabaseConnectButtonClickedHelper(int mode);
235 void computeResetDbButtonClicked(const std::string& db);
236 void populatePlannersList(const std::vector<moveit_msgs::msg::PlannerInterfaceDescription>& desc);
237 void populatePlannerDescription(const moveit_msgs::msg::PlannerInterfaceDescription& desc);
238
239 // Planning tab
240 void computePlanButtonClicked();
241 void computeExecuteButtonClicked();
242 void computePlanAndExecuteButtonClicked();
243 void computePlanAndExecuteButtonClickedDisplayHelper();
244 void computeStopButtonClicked();
245 void onFinishedExecution(bool success);
246 void populateConstraintsList();
247 void populateConstraintsList(const std::vector<std::string>& constr);
248 void configureForPlanning();
249 void configureWorkspace();
250 void updateQueryStateHelper(moveit::core::RobotState& state, const std::string& v);
251 void fillStateSelectionOptions();
252 void fillPlanningGroupOptions();
253 void startStateTextChangedExec(const std::string& start_state);
254 void goalStateTextChangedExec(const std::string& goal_state);
255
256 // Scene objects tab
257 void updateCollisionObjectPose(bool update_marker_position);
258 void createSceneInteractiveMarker();
259 void renameCollisionObject(QListWidgetItem* item);
260 void attachDetachCollisionObject(QListWidgetItem* item);
261 void populateCollisionObjectsList();
262 void computeImportGeometryFromText(const std::string& path);
263 void computeExportGeometryAsText(const std::string& path);
264 visualization_msgs::msg::InteractiveMarker
265 createObjectMarkerMsg(const collision_detection::CollisionEnv::ObjectConstPtr& obj);
266
267 // Stored scenes tab
268 void computeSaveSceneButtonClicked();
269 void computeSaveQueryButtonClicked(const std::string& scene, const std::string& query_name);
270 void computeLoadSceneButtonClicked();
271 void computeLoadQueryButtonClicked();
272 void populatePlanningSceneTreeView();
273 void computeDeleteSceneButtonClicked();
274 void computeDeleteQueryButtonClicked();
275 void computeDeleteQueryButtonClickedHelper(QTreeWidgetItem* s);
276 void checkPlanningSceneTreeEnabledButtons();
277
278 // States tab
279 void saveRobotStateButtonClicked(const moveit::core::RobotState& state);
280 void populateRobotStatesList();
281
282 // Pick and place
283 void processDetectedObjects();
284 void updateDetectedObjectsList(const std::vector<std::string>& object_ids);
285 void publishTables();
286 void updateSupportSurfacesList();
287
288 std::map<std::string, std::string> pick_object_name_;
289 std::string place_object_name_;
290 std::vector<geometry_msgs::msg::PoseStamped> place_poses_;
291 // void pickObject();
292 // void placeObject();
293 void triggerObjectDetection();
294 void updateTables();
295 std::string support_surface_name_;
296 // For coloring
297 std::string selected_object_name_;
298 std::string selected_support_surface_name_;
299
300 rclcpp_action::Client<object_recognition_msgs::action::ObjectRecognition>::SharedPtr object_recognition_client_;
301 void listenDetectedObjects(const object_recognition_msgs::msg::RecognizedObjectArray::ConstSharedPtr& msg);
302 rclcpp::Subscription<object_recognition_msgs::msg::RecognizedObjectArray>::SharedPtr object_recognition_subscriber_;
303
304 rclcpp::Subscription<std_msgs::msg::Empty>::SharedPtr plan_subscriber_;
305 rclcpp::Subscription<std_msgs::msg::Empty>::SharedPtr execute_subscriber_;
306 rclcpp::Subscription<std_msgs::msg::Empty>::SharedPtr stop_subscriber_;
307 rclcpp::Subscription<std_msgs::msg::Empty>::SharedPtr update_start_state_subscriber_;
308 rclcpp::Subscription<std_msgs::msg::Empty>::SharedPtr update_goal_state_subscriber_;
309 rclcpp::Subscription<moveit_msgs::msg::RobotState>::SharedPtr update_custom_start_state_subscriber_;
310 rclcpp::Subscription<moveit_msgs::msg::RobotState>::SharedPtr update_custom_goal_state_subscriber_;
311
312 // General
313 void changePlanningGroupHelper();
314 shapes::ShapePtr loadMeshResource(const std::string& url);
315 void loadStoredStates(const std::string& pattern);
316
317 void remotePlanCallback(const std_msgs::msg::Empty::ConstSharedPtr& msg);
318 void remoteExecuteCallback(const std_msgs::msg::Empty::ConstSharedPtr& msg);
319 void remoteStopCallback(const std_msgs::msg::Empty::ConstSharedPtr& msg);
320 void remoteUpdateStartStateCallback(const std_msgs::msg::Empty::ConstSharedPtr& msg);
321 void remoteUpdateGoalStateCallback(const std_msgs::msg::Empty::ConstSharedPtr& msg);
322 void remoteUpdateCustomStartStateCallback(const moveit_msgs::msg::RobotState::ConstSharedPtr& msg);
323 void remoteUpdateCustomGoalStateCallback(const moveit_msgs::msg::RobotState::ConstSharedPtr& msg);
324
325 /* Selects or unselects a item in a list by the item name */
326 void setItemSelectionInList(const std::string& item_name, bool selection, QListWidget* list);
327
328 rclcpp::Node::SharedPtr node_;
329 rclcpp::Logger logger_;
330 rclcpp::Publisher<moveit_msgs::msg::PlanningScene>::SharedPtr planning_scene_publisher_;
331 rclcpp::Publisher<moveit_msgs::msg::PlanningSceneWorld>::SharedPtr planning_scene_world_publisher_;
332
334 moveit::core::FixedTransformsMap scaled_object_subframes_;
335 EigenSTL::vector_Isometry3d scaled_object_shape_poses_;
336
337 std::vector<std::pair<std::string, bool> > known_collision_objects_;
338 long unsigned int known_collision_objects_version_;
339 bool first_time_;
340 rclcpp::Client<std_srvs::srv::Empty>::SharedPtr clear_octomap_service_client_;
341};
342} // namespace moveit_rviz_plugin
#define MOVEIT_CLASS_FORWARD(C)
World::ObjectConstPtr ObjectConstPtr
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Definition robot_state.h:90
moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage_
std::shared_ptr< rviz_default_plugins::displays::InteractiveMarker > scene_marker_
std::pair< std::string, moveit_msgs::msg::RobotState > RobotStatePair
moveit::planning_interface::MoveGroupInterface::PlanPtr current_plan_
void updateSceneMarkers(double wall_dt, double ros_dt)
MotionPlanningFrameJointsWidget * joints_tab_
std::vector< moveit_msgs::msg::PlannerInterfaceDescription > planner_descriptions_
moveit_warehouse::ConstraintsStoragePtr constraints_storage_
moveit::planning_interface::MoveGroupInterfacePtr move_group_
std::map< std::string, moveit_msgs::msg::RobotState > RobotStateMap
void constructPlanningRequest(moveit_msgs::msg::MotionPlanRequest &mreq)
void sceneUpdate(planning_scene_monitor::PlanningSceneMonitor::SceneUpdateType update_type)
MotionPlanningFrame(const MotionPlanningFrame &)=delete
moveit_warehouse::RobotStateStoragePtr robot_state_storage_
std::map< std::string, Eigen::Isometry3d, std::less< std::string >, Eigen::aligned_allocator< std::pair< const std::string, Eigen::Isometry3d > > > FixedTransformsMap
Map frame names to the transformation matrix that can transform objects from the frame name to the pl...
Definition transforms.h:53
const std::string OBJECT_RECOGNITION_ACTION