48 using warehouse_ros::Metadata;
49 using warehouse_ros::Query;
57 void moveit_warehouse::ConstraintsStorage::createCollections()
59 constraints_collection_ = conn_->openCollectionPtr<moveit_msgs::msg::Constraints>(DATABASE_NAME,
"constraints");
64 constraints_collection_.reset();
65 conn_->dropDatabase(DATABASE_NAME);
70 const std::string& robot,
const std::string& group)
73 if (hasConstraints(msg.name, robot, group))
75 removeConstraints(msg.name, robot, group);
78 Metadata::Ptr metadata = constraints_collection_->createMetadata();
79 metadata->append(CONSTRAINTS_ID_NAME, msg.name);
81 metadata->append(CONSTRAINTS_GROUP_NAME, group);
82 constraints_collection_->insert(msg, metadata);
83 RCLCPP_DEBUG(logger_,
"%s constraints '%s'", replace ?
"Replaced" :
"Added", msg.name.c_str());
87 const std::string& group)
const
89 Query::Ptr q = constraints_collection_->createQuery();
90 q->append(CONSTRAINTS_ID_NAME,
name);
94 q->append(CONSTRAINTS_GROUP_NAME, group);
95 std::vector<ConstraintsWithMetadata> constr = constraints_collection_->queryList(q,
true);
96 return !constr.empty();
100 std::vector<std::string>& names,
101 const std::string& robot,
const std::string& group)
const
103 getKnownConstraints(names, robot, group);
104 filterNames(regex, names);
108 const std::string& robot,
const std::string& group)
const
111 Query::Ptr q = constraints_collection_->createQuery();
115 q->append(CONSTRAINTS_GROUP_NAME, group);
116 std::vector<ConstraintsWithMetadata> constr = constraints_collection_->queryList(q,
true, CONSTRAINTS_ID_NAME,
true);
119 if (it->lookupField(CONSTRAINTS_ID_NAME))
120 names.push_back(it->lookupString(CONSTRAINTS_ID_NAME));
125 const std::string& robot,
const std::string& group)
const
127 Query::Ptr q = constraints_collection_->createQuery();
128 q->append(CONSTRAINTS_ID_NAME,
name);
132 q->append(CONSTRAINTS_GROUP_NAME, group);
133 std::vector<ConstraintsWithMetadata> constr = constraints_collection_->queryList(q,
false);
140 msg_m = constr.back();
142 const_cast<moveit_msgs::msg::Constraints*
>(
static_cast<const moveit_msgs::msg::Constraints*
>(msg_m.get()))->name =
149 const std::string& robot,
const std::string& group)
151 Query::Ptr q = constraints_collection_->createQuery();
152 q->append(CONSTRAINTS_ID_NAME, old_name);
156 q->append(CONSTRAINTS_GROUP_NAME, group);
157 Metadata::Ptr m = constraints_collection_->createMetadata();
158 m->append(CONSTRAINTS_ID_NAME, new_name);
159 constraints_collection_->modifyMetadata(q, m);
160 RCLCPP_DEBUG(logger_,
"Renamed constraints from '%s' to '%s'", old_name.c_str(), new_name.c_str());
164 const std::string& group)
166 Query::Ptr q = constraints_collection_->createQuery();
167 q->append(CONSTRAINTS_ID_NAME,
name);
171 q->append(CONSTRAINTS_GROUP_NAME, group);
172 unsigned int rem = constraints_collection_->removeMessages(q);
173 RCLCPP_DEBUG(logger_,
"Removed %u Constraints messages (named '%s')", rem,
name.c_str());
void removeConstraints(const std::string &name, const std::string &robot="", const std::string &group="")
ConstraintsStorage(warehouse_ros::DatabaseConnection::Ptr conn)
bool hasConstraints(const std::string &name, const std::string &robot="", const std::string &group="") const
static const std::string DATABASE_NAME
bool getConstraints(ConstraintsWithMetadata &msg_m, const std::string &name, const std::string &robot="", const std::string &group="") const
Get the constraints named name. Return false on failure.
void renameConstraints(const std::string &old_name, const std::string &new_name, const std::string &robot="", const std::string &group="")
void getKnownConstraints(std::vector< std::string > &names, const std::string &robot="", const std::string &group="") const
static const std::string CONSTRAINTS_ID_NAME
void addConstraints(const moveit_msgs::msg::Constraints &msg, const std::string &robot="", const std::string &group="")
static const std::string CONSTRAINTS_GROUP_NAME
static const std::string ROBOT_NAME
This class provides the mechanism to connect to a database and reads needed ROS parameters when appro...
rclcpp::Logger getLogger()
warehouse_ros::MessageWithMetadata< moveit_msgs::msg::Constraints >::ConstPtr ConstraintsWithMetadata
Main namespace for MoveIt.
const std::string ROBOT_NAME