planning_scene_world_storage.cpp
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 
38 
39 const std::string moveit_warehouse::PlanningSceneWorldStorage::DATABASE_NAME = "moveit_planning_scene_worlds";
41 
44 
46  : MoveItMessageStorage(conn)
47 {
49 }
50 
52 {
54  conn_->openCollectionPtr<moveit_msgs::PlanningSceneWorld>(DATABASE_NAME, "planning_scene_worlds");
55 }
56 
58 {
60  conn_->dropDatabase(DATABASE_NAME);
62 }
63 
64 void moveit_warehouse::PlanningSceneWorldStorage::addPlanningSceneWorld(const moveit_msgs::PlanningSceneWorld& msg,
65  const std::string& name)
66 {
67  bool replace = false;
68  if (hasPlanningSceneWorld(name))
69  {
71  replace = true;
72  }
73  Metadata::Ptr metadata = planning_scene_world_collection_->createMetadata();
74  metadata->append(PLANNING_SCENE_WORLD_ID_NAME, name);
75  planning_scene_world_collection_->insert(msg, metadata);
76  ROS_DEBUG("%s planning scene world '%s'", replace ? "Replaced" : "Added", name.c_str());
77 }
78 
80 {
81  Query::Ptr q = planning_scene_world_collection_->createQuery();
82  q->append(PLANNING_SCENE_WORLD_ID_NAME, name);
83  std::vector<PlanningSceneWorldWithMetadata> psw = planning_scene_world_collection_->queryList(q, true);
84  return !psw.empty();
85 }
86 
88  std::vector<std::string>& names) const
89 {
91  filterNames(regex, names);
92 }
93 
95 {
96  names.clear();
97  Query::Ptr q = planning_scene_world_collection_->createQuery();
98  std::vector<PlanningSceneWorldWithMetadata> constr =
100  for (std::size_t i = 0; i < constr.size(); ++i)
101  if (constr[i]->lookupField(PLANNING_SCENE_WORLD_ID_NAME))
102  names.push_back(constr[i]->lookupString(PLANNING_SCENE_WORLD_ID_NAME));
103 }
104 
106  const std::string& name) const
107 {
108  Query::Ptr q = planning_scene_world_collection_->createQuery();
109  q->append(PLANNING_SCENE_WORLD_ID_NAME, name);
110  std::vector<PlanningSceneWorldWithMetadata> psw = planning_scene_world_collection_->queryList(q, false);
111  if (psw.empty())
112  return false;
113  else
114  {
115  msg_m = psw.front();
116  return true;
117  }
118 }
119 
121  const std::string& new_name)
122 {
123  Query::Ptr q = planning_scene_world_collection_->createQuery();
124  q->append(PLANNING_SCENE_WORLD_ID_NAME, old_name);
125  Metadata::Ptr m = planning_scene_world_collection_->createMetadata();
126  m->append(PLANNING_SCENE_WORLD_ID_NAME, new_name);
127  planning_scene_world_collection_->modifyMetadata(q, m);
128  ROS_DEBUG("Renamed planning scene world from '%s' to '%s'", old_name.c_str(), new_name.c_str());
129 }
130 
132 {
133  Query::Ptr q = planning_scene_world_collection_->createQuery();
134  q->append(PLANNING_SCENE_WORLD_ID_NAME, name);
135  unsigned int rem = planning_scene_world_collection_->removeMessages(q);
136  ROS_DEBUG("Removed %u PlanningSceneWorld messages (named '%s')", rem, name.c_str());
137 }
void filterNames(const std::string &regex, std::vector< std::string > &names) const
Keep only the names that match regex.
void addPlanningSceneWorld(const moveit_msgs::PlanningSceneWorld &msg, const std::string &name)
bool getPlanningSceneWorld(PlanningSceneWorldWithMetadata &msg_m, const std::string &name) const
Get the constraints named name. Return false on failure.
warehouse_ros::DatabaseConnection::Ptr conn_
This class provides the mechanism to connect to a database and reads needed ROS parameters when appro...
void getKnownPlanningSceneWorlds(std::vector< std::string > &names) const
bool hasPlanningSceneWorld(const std::string &name) const
void renamePlanningSceneWorld(const std::string &old_name, const std::string &new_name)
PlanningSceneWorldStorage(warehouse_ros::DatabaseConnection::Ptr conn)
#define ROS_DEBUG(...)


warehouse
Author(s): Ioan Sucan
autogenerated on Wed Jul 10 2019 04:04:05