moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
trajectory_constraints_storage.cpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2013, 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: Mario Prats, Ioan Sucan */
36
39
40#include <utility>
41
42const std::string moveit_warehouse::TrajectoryConstraintsStorage::DATABASE_NAME = "moveit_trajectory_constraints";
43
47
48using warehouse_ros::Metadata;
49using warehouse_ros::Query;
50
52 : MoveItMessageStorage(std::move(conn))
53 , logger_(moveit::getLogger("moveit.ros.warehouse_trajectory_constraints_storage"))
54{
55 createCollections();
56}
57
58void moveit_warehouse::TrajectoryConstraintsStorage::createCollections()
59{
60 constraints_collection_ =
61 conn_->openCollectionPtr<moveit_msgs::msg::TrajectoryConstraints>(DATABASE_NAME, "trajectory_constraints");
62}
63
65{
66 constraints_collection_.reset();
67 conn_->dropDatabase(DATABASE_NAME);
68 createCollections();
69}
70
72 const moveit_msgs::msg::TrajectoryConstraints& msg, const std::string& name, const std::string& robot,
73 const std::string& group)
74{
75 bool replace = false;
76 if (hasTrajectoryConstraints(name, robot, group))
77 {
78 removeTrajectoryConstraints(name, robot, group);
79 replace = true;
80 }
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());
87}
88
90 const std::string& robot,
91 const std::string& group) const
92{
93 Query::Ptr q = constraints_collection_->createQuery();
94 q->append(CONSTRAINTS_ID_NAME, name);
95 if (!robot.empty())
96 q->append(ROBOT_NAME, robot);
97 if (!group.empty())
98 q->append(CONSTRAINTS_GROUP_NAME, group);
99 std::vector<TrajectoryConstraintsWithMetadata> constr = constraints_collection_->queryList(q, true);
100 return !constr.empty();
101}
102
104 std::vector<std::string>& names,
105 const std::string& robot,
106 const std::string& group) const
107{
108 getKnownTrajectoryConstraints(names, robot, group);
109 filterNames(regex, names);
110}
111
113 const std::string& robot,
114 const std::string& group) const
115{
116 names.clear();
117 Query::Ptr q = constraints_collection_->createQuery();
118 if (!robot.empty())
119 q->append(ROBOT_NAME, robot);
120 if (!group.empty())
121 q->append(CONSTRAINTS_GROUP_NAME, group);
122 std::vector<TrajectoryConstraintsWithMetadata> constr =
123 constraints_collection_->queryList(q, true, CONSTRAINTS_ID_NAME, true);
124 for (TrajectoryConstraintsWithMetadata& traj_constraint : constr)
125 {
126 if (traj_constraint->lookupField(CONSTRAINTS_ID_NAME))
127 names.push_back(traj_constraint->lookupString(CONSTRAINTS_ID_NAME));
128 }
129}
130
132 const std::string& name,
133 const std::string& robot,
134 const std::string& group) const
135{
136 Query::Ptr q = constraints_collection_->createQuery();
137 q->append(CONSTRAINTS_ID_NAME, name);
138 if (!robot.empty())
139 q->append(ROBOT_NAME, robot);
140 if (!group.empty())
141 q->append(CONSTRAINTS_GROUP_NAME, group);
142 std::vector<TrajectoryConstraintsWithMetadata> constr = constraints_collection_->queryList(q, false);
143 if (constr.empty())
144 {
145 return false;
146 }
147 else
148 {
149 msg_m = constr.back();
150 return true;
151 }
152}
153
155 const std::string& new_name,
156 const std::string& robot,
157 const std::string& group)
158{
159 Query::Ptr q = constraints_collection_->createQuery();
160 q->append(CONSTRAINTS_ID_NAME, old_name);
161 if (!robot.empty())
162 q->append(ROBOT_NAME, robot);
163 if (!group.empty())
164 q->append(CONSTRAINTS_GROUP_NAME, group);
165 Metadata::Ptr m = constraints_collection_->createMetadata();
166 m->append(CONSTRAINTS_ID_NAME, new_name);
167 constraints_collection_->modifyMetadata(q, m);
168 RCLCPP_DEBUG(logger_, "Renamed constraints from '%s' to '%s'", old_name.c_str(), new_name.c_str());
169}
170
172 const std::string& robot,
173 const std::string& group)
174{
175 Query::Ptr q = constraints_collection_->createQuery();
176 q->append(CONSTRAINTS_ID_NAME, name);
177 if (!robot.empty())
178 q->append(ROBOT_NAME, robot);
179 if (!group.empty())
180 q->append(CONSTRAINTS_GROUP_NAME, group);
181 unsigned int rem = constraints_collection_->removeMessages(q);
182 RCLCPP_DEBUG(logger_, "Removed %u TrajectoryConstraints messages (named '%s')", rem, name.c_str());
183}
This class provides the mechanism to connect to a database and reads needed ROS parameters when appro...
TrajectoryConstraintsStorage(warehouse_ros::DatabaseConnection::Ptr conn)
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
void removeTrajectoryConstraints(const std::string &name, const std::string &robot="", const std::string &group="")
void addTrajectoryConstraints(const moveit_msgs::msg::TrajectoryConstraints &msg, const std::string &name, const std::string &robot="", const std::string &group="")
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
Main namespace for MoveIt.
Definition exceptions.h:43
const std::string ROBOT_NAME