47 static const rclcpp::Logger
LOGGER = rclcpp::get_logger(
"moveit.ros.warehouse.trajectory_constraints_storage");
49 using warehouse_ros::Metadata;
50 using warehouse_ros::Query;
58 void moveit_warehouse::TrajectoryConstraintsStorage::createCollections()
60 constraints_collection_ =
61 conn_->openCollectionPtr<moveit_msgs::msg::TrajectoryConstraints>(DATABASE_NAME,
"trajectory_constraints");
66 constraints_collection_.reset();
67 conn_->dropDatabase(DATABASE_NAME);
72 const moveit_msgs::msg::TrajectoryConstraints& msg,
const std::string&
name,
const std::string&
robot,
73 const std::string&
group)
81 Metadata::Ptr metadata = constraints_collection_->createMetadata();
82 metadata->append(CONSTRAINTS_ID_NAME,
name);
83 metadata->append(ROBOT_NAME,
robot);
84 metadata->append(CONSTRAINTS_GROUP_NAME,
group);
85 constraints_collection_->insert(msg, metadata);
86 RCLCPP_DEBUG(LOGGER,
"%s constraints '%s'", replace ?
"Replaced" :
"Added",
name.c_str());
90 const std::string&
robot,
91 const std::string&
group)
const
93 Query::Ptr q = constraints_collection_->createQuery();
94 q->append(CONSTRAINTS_ID_NAME,
name);
96 q->append(ROBOT_NAME,
robot);
98 q->append(CONSTRAINTS_GROUP_NAME,
group);
99 std::vector<TrajectoryConstraintsWithMetadata> constr = constraints_collection_->queryList(q,
true);
100 return !constr.empty();
104 std::vector<std::string>& names,
105 const std::string&
robot,
106 const std::string&
group)
const
108 getKnownTrajectoryConstraints(names,
robot,
group);
109 filterNames(regex, names);
113 const std::string&
robot,
114 const std::string&
group)
const
117 Query::Ptr q = constraints_collection_->createQuery();
119 q->append(ROBOT_NAME,
robot);
121 q->append(CONSTRAINTS_GROUP_NAME,
group);
122 std::vector<TrajectoryConstraintsWithMetadata> constr =
123 constraints_collection_->queryList(q,
true, CONSTRAINTS_ID_NAME,
true);
125 if (traj_constraint->lookupField(CONSTRAINTS_ID_NAME))
126 names.push_back(traj_constraint->lookupString(CONSTRAINTS_ID_NAME));
130 const std::string&
name,
131 const std::string&
robot,
132 const std::string&
group)
const
134 Query::Ptr q = constraints_collection_->createQuery();
135 q->append(CONSTRAINTS_ID_NAME,
name);
137 q->append(ROBOT_NAME,
robot);
139 q->append(CONSTRAINTS_GROUP_NAME,
group);
140 std::vector<TrajectoryConstraintsWithMetadata> constr = constraints_collection_->queryList(q,
false);
145 msg_m = constr.back();
151 const std::string& new_name,
152 const std::string&
robot,
153 const std::string&
group)
155 Query::Ptr q = constraints_collection_->createQuery();
156 q->append(CONSTRAINTS_ID_NAME, old_name);
158 q->append(ROBOT_NAME,
robot);
160 q->append(CONSTRAINTS_GROUP_NAME,
group);
161 Metadata::Ptr m = constraints_collection_->createMetadata();
162 m->append(CONSTRAINTS_ID_NAME, new_name);
163 constraints_collection_->modifyMetadata(q, m);
164 RCLCPP_DEBUG(LOGGER,
"Renamed constraints from '%s' to '%s'", old_name.c_str(), new_name.c_str());
168 const std::string&
robot,
169 const std::string&
group)
171 Query::Ptr q = constraints_collection_->createQuery();
172 q->append(CONSTRAINTS_ID_NAME,
name);
174 q->append(ROBOT_NAME,
robot);
176 q->append(CONSTRAINTS_GROUP_NAME,
group);
177 unsigned int rem = constraints_collection_->removeMessages(q);
178 RCLCPP_DEBUG(LOGGER,
"Removed %u TrajectoryConstraints messages (named '%s')", rem,
name.c_str());
This class provides the mechanism to connect to a database and reads needed ROS parameters when appro...
TrajectoryConstraintsStorage(warehouse_ros::DatabaseConnection::Ptr conn)
static const std::string DATABASE_NAME
bool hasTrajectoryConstraints(const std::string &name, const std::string &robot="", const std::string &group="") const
void renameTrajectoryConstraints(const std::string &old_name, const std::string &new_name, const std::string &robot="", const std::string &group="")
void getKnownTrajectoryConstraints(std::vector< std::string > &names, const std::string &robot="", const std::string &group="") const
static const std::string CONSTRAINTS_ID_NAME
void removeTrajectoryConstraints(const std::string &name, const std::string &robot="", const std::string &group="")
static const std::string ROBOT_NAME
void addTrajectoryConstraints(const moveit_msgs::msg::TrajectoryConstraints &msg, const std::string &name, const std::string &robot="", const std::string &group="")
static const std::string CONSTRAINTS_GROUP_NAME
bool getTrajectoryConstraints(TrajectoryConstraintsWithMetadata &msg_m, const std::string &name, const std::string &robot="", const std::string &group="") const
Get the constraints named name. Return false on failure.
warehouse_ros::MessageWithMetadata< moveit_msgs::msg::TrajectoryConstraints >::ConstPtr TrajectoryConstraintsWithMetadata
const rclcpp::Logger LOGGER