47 static const rclcpp::Logger
LOGGER = rclcpp::get_logger(
"moveit.ros.warehouse.constraints_storage");
49 using warehouse_ros::Metadata;
50 using warehouse_ros::Query;
58 void moveit_warehouse::ConstraintsStorage::createCollections()
60 constraints_collection_ = conn_->openCollectionPtr<moveit_msgs::msg::Constraints>(DATABASE_NAME,
"constraints");
65 constraints_collection_.reset();
66 conn_->dropDatabase(DATABASE_NAME);
71 const std::string&
robot,
const std::string&
group)
79 Metadata::Ptr metadata = constraints_collection_->createMetadata();
80 metadata->append(CONSTRAINTS_ID_NAME, msg.name);
81 metadata->append(ROBOT_NAME,
robot);
82 metadata->append(CONSTRAINTS_GROUP_NAME,
group);
83 constraints_collection_->insert(msg, metadata);
84 RCLCPP_DEBUG(LOGGER,
"%s constraints '%s'", replace ?
"Replaced" :
"Added", msg.name.c_str());
88 const std::string&
group)
const
90 Query::Ptr q = constraints_collection_->createQuery();
91 q->append(CONSTRAINTS_ID_NAME,
name);
93 q->append(ROBOT_NAME,
robot);
95 q->append(CONSTRAINTS_GROUP_NAME,
group);
96 std::vector<ConstraintsWithMetadata> constr = constraints_collection_->queryList(q,
true);
97 return !constr.empty();
101 std::vector<std::string>& names,
102 const std::string&
robot,
const std::string&
group)
const
105 filterNames(regex, names);
109 const std::string&
robot,
const std::string&
group)
const
112 Query::Ptr q = constraints_collection_->createQuery();
114 q->append(ROBOT_NAME,
robot);
116 q->append(CONSTRAINTS_GROUP_NAME,
group);
117 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));
124 const std::string&
robot,
const std::string&
group)
const
126 Query::Ptr q = constraints_collection_->createQuery();
127 q->append(CONSTRAINTS_ID_NAME,
name);
129 q->append(ROBOT_NAME,
robot);
131 q->append(CONSTRAINTS_GROUP_NAME,
group);
132 std::vector<ConstraintsWithMetadata> constr = constraints_collection_->queryList(q,
false);
137 msg_m = constr.back();
139 const_cast<moveit_msgs::msg::Constraints*
>(
static_cast<const moveit_msgs::msg::Constraints*
>(msg_m.get()))->name =
146 const std::string&
robot,
const std::string&
group)
148 Query::Ptr q = constraints_collection_->createQuery();
149 q->append(CONSTRAINTS_ID_NAME, old_name);
151 q->append(ROBOT_NAME,
robot);
153 q->append(CONSTRAINTS_GROUP_NAME,
group);
154 Metadata::Ptr m = constraints_collection_->createMetadata();
155 m->append(CONSTRAINTS_ID_NAME, new_name);
156 constraints_collection_->modifyMetadata(q, m);
157 RCLCPP_DEBUG(LOGGER,
"Renamed constraints from '%s' to '%s'", old_name.c_str(), new_name.c_str());
161 const std::string&
group)
163 Query::Ptr q = constraints_collection_->createQuery();
164 q->append(CONSTRAINTS_ID_NAME,
name);
166 q->append(ROBOT_NAME,
robot);
168 q->append(CONSTRAINTS_GROUP_NAME,
group);
169 unsigned int rem = constraints_collection_->removeMessages(q);
170 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...
warehouse_ros::MessageWithMetadata< moveit_msgs::msg::Constraints >::ConstPtr ConstraintsWithMetadata
const rclcpp::Logger LOGGER