xml_testdata_loader.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018 Pilz GmbH & Co. KG
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 Pilz GmbH & Co. KG 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 #ifndef XML_TESTDATA_LOADER_H
36 #define XML_TESTDATA_LOADER_H
37 
38 #include <string>
39 #include <vector>
40 #include <functional>
41 #include <map>
42 #include <memory>
43 
44 #include <boost/property_tree/ptree.hpp>
45 
47 
48 namespace pt = boost::property_tree;
50 {
120 class XmlTestdataLoader : public TestdataLoader
121 {
122 public:
123  XmlTestdataLoader(const std::string& path_filename);
124  XmlTestdataLoader(const std::string& path_filename, const moveit::core::RobotModelConstPtr& robot_model);
125  ~XmlTestdataLoader() override;
126 
127 public:
128  JointConfiguration getJoints(const std::string& pos_name, const std::string& group_name) const override;
129 
130  CartesianConfiguration getPose(const std::string& pos_name, const std::string& group_name) const override;
131 
132  PtpJoint getPtpJoint(const std::string& cmd_name) const override;
133  PtpCart getPtpCart(const std::string& cmd_name) const override;
134  PtpJointCart getPtpJointCart(const std::string& cmd_name) const override;
135 
136  LinJoint getLinJoint(const std::string& cmd_name) const override;
137  LinCart getLinCart(const std::string& cmd_name) const override;
138  LinJointCart getLinJointCart(const std::string& cmd_name) const override;
139 
140  CircCenterCart getCircCartCenterCart(const std::string& cmd_name) const override;
141  CircInterimCart getCircCartInterimCart(const std::string& cmd_name) const override;
142  CircJointCenterCart getCircJointCenterCart(const std::string& cmd_name) const override;
143  CircJointInterimCart getCircJointInterimCart(const std::string& cmd_name) const override;
144 
145  Sequence getSequence(const std::string& cmd_name) const override;
146 
147  Gripper getGripper(const std::string& cmd_name) const override;
148 
149 private:
157  const pt::ptree::value_type& findNodeWithName(const boost::property_tree::ptree& tree, const std::string& name,
158  const std::string& key, const std::string& path = "") const;
159 
163  const pt::ptree::value_type& findCmd(const std::string& cmd_name, const std::string& cmd_path,
164  const std::string& cmd_key) const;
165 
166  CartesianCenter getCartesianCenter(const std::string& cmd_name, const std::string& planning_group) const;
167 
168  CartesianInterim getCartesianInterim(const std::string& cmd_name, const std::string& planning_group) const;
169 
170 private:
171  JointConfiguration getJoints(const boost::property_tree::ptree& joints_tree, const std::string& group_name) const;
172 
173 private:
177  inline static std::vector<double> strVec2doubleVec(std::vector<std::string>& strVec);
178 
179 public:
185  class AbstractCmdGetterAdapter
186  {
187  public:
188  virtual CmdVariant getCmd(const std::string& /*cmd_name*/) const = 0;
189  virtual ~AbstractCmdGetterAdapter() = default;
190  };
191 
192 private:
193  std::string path_filename_;
194  pt::ptree tree_{};
195 
196  using AbstractCmdGetterUPtr = std::unique_ptr<AbstractCmdGetterAdapter>;
197 
203  std::map<std::string, AbstractCmdGetterUPtr> cmd_getter_funcs_;
204 
205 private:
206  const pt::ptree::value_type empty_value_type_{};
207  const pt::ptree empty_tree_{};
208 };
209 
210 std::vector<double> XmlTestdataLoader::strVec2doubleVec(std::vector<std::string>& strVec)
211 {
212  std::vector<double> vec;
213 
214  vec.resize(strVec.size());
215  std::transform(strVec.begin(), strVec.end(), vec.begin(), [](const std::string& val) { return std::stod(val); });
216 
217  return vec;
218 }
219 
220 using XmlTestDataLoaderUPtr = std::unique_ptr<TestdataLoader>;
221 } // namespace pilz_industrial_motion_planner_testutils
222 
223 #endif // XML_TESTDATA_LOADER_H
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::tree_
pt::ptree tree_
Definition: xml_testdata_loader.h:258
pilz_industrial_motion_planner_testutils::CircCenterCart
Circ< CartesianConfiguration, CartesianCenter, CartesianConfiguration > CircCenterCart
Definition: command_types_typedef.h:90
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::cmd_getter_funcs_
std::map< std::string, AbstractCmdGetterUPtr > cmd_getter_funcs_
Definition: xml_testdata_loader.h:267
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getCircCartCenterCart
CircCenterCart getCircCartCenterCart(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
Definition: xml_testdata_loader.cpp:460
pilz_industrial_motion_planner_testutils::CircJointInterimCart
Circ< JointConfiguration, CartesianInterim, JointConfiguration > CircJointInterimCart
Definition: command_types_typedef.h:94
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::AbstractCmdGetterUPtr
std::unique_ptr< AbstractCmdGetterAdapter > AbstractCmdGetterUPtr
Definition: xml_testdata_loader.h:260
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getGripper
Gripper getGripper(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
Definition: xml_testdata_loader.cpp:569
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::empty_tree_
const pt::ptree empty_tree_
Definition: xml_testdata_loader.h:271
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getSequence
Sequence getSequence(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
Definition: xml_testdata_loader.cpp:528
pilz_industrial_motion_planner_testutils::PtpJoint
Ptp< JointConfiguration, JointConfiguration > PtpJoint
Definition: command_types_typedef.h:82
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::empty_value_type_
const pt::ptree::value_type empty_value_type_
Definition: xml_testdata_loader.h:270
vec
vec
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::AbstractCmdGetterAdapter::getCmd
virtual CmdVariant getCmd(const std::string &) const =0
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getPtpCart
PtpCart getPtpCart(const std::string &cmd_name) const override
Definition: xml_testdata_loader.cpp:345
pilz_industrial_motion_planner_testutils::LinCart
Lin< CartesianConfiguration, CartesianConfiguration > LinCart
Definition: command_types_typedef.h:88
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getJoints
JointConfiguration getJoints(const std::string &pos_name, const std::string &group_name) const override
Definition: xml_testdata_loader.cpp:255
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getCircJointInterimCart
CircJointInterimCart getCircJointInterimCart(const std::string &cmd_name) const override
Definition: xml_testdata_loader.cpp:494
pilz_industrial_motion_planner_testutils::CartesianInterim
Interim< CartesianConfiguration, CartesianPathConstraintsBuilder > CartesianInterim
Definition: circ_auxiliary_types.h:78
pilz_industrial_motion_planner_testutils::XmlTestDataLoaderUPtr
std::unique_ptr< TestdataLoader > XmlTestDataLoaderUPtr
Definition: xml_testdata_loader.h:252
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getLinJointCart
LinJointCart getLinJointCart(const std::string &cmd_name) const override
Definition: xml_testdata_loader.cpp:393
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::strVec2doubleVec
static std::vector< double > strVec2doubleVec(std::vector< std::string > &strVec)
Converts string vector to double vector.
Definition: xml_testdata_loader.h:242
pilz_industrial_motion_planner_testutils
Definition: basecmd.h:42
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::findNodeWithName
const pt::ptree::value_type & findNodeWithName(const boost::property_tree::ptree &tree, const std::string &name, const std::string &key, const std::string &path="") const
Use this function to search for a node (like an pos or cmd) with a given name.
Definition: xml_testdata_loader.cpp:210
pilz_industrial_motion_planner_testutils::CmdVariant
boost::variant< PtpJoint, PtpJointCart, PtpCart, LinJoint, LinCart, CircCenterCart, CircInterimCart, CircJointCenterCart, CircJointInterimCart, Gripper > CmdVariant
Definition: command_types_typedef.h:98
pilz_industrial_motion_planner_testutils::LinJoint
Lin< JointConfiguration, JointConfiguration > LinJoint
Definition: command_types_typedef.h:86
pilz_industrial_motion_planner_testutils::PtpJointCart
Ptp< JointConfiguration, CartesianConfiguration > PtpJointCart
Definition: command_types_typedef.h:83
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getCircJointCenterCart
CircJointCenterCart getCircJointCenterCart(const std::string &cmd_name) const override
Definition: xml_testdata_loader.cpp:511
testdata_loader.h
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::findCmd
const pt::ptree::value_type & findCmd(const std::string &cmd_name, const std::string &cmd_path, const std::string &cmd_key) const
Use this function to search for a cmd-node with a given name.
Definition: xml_testdata_loader.cpp:409
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::XmlTestdataLoader
XmlTestdataLoader(const std::string &path_filename)
Definition: xml_testdata_loader.cpp:170
pilz_industrial_motion_planner_testutils::CartesianCenter
Center< CartesianConfiguration, CartesianPathConstraintsBuilder > CartesianCenter
Definition: circ_auxiliary_types.h:77
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::~XmlTestdataLoader
~XmlTestdataLoader() override
Definition: xml_testdata_loader.cpp:206
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getPtpJointCart
PtpJointCart getPtpJointCart(const std::string &cmd_name) const override
Definition: xml_testdata_loader.cpp:329
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getPose
CartesianConfiguration getPose(const std::string &pos_name, const std::string &group_name) const override
Definition: xml_testdata_loader.cpp:281
pilz_industrial_motion_planner_testutils::CircJointCenterCart
Circ< JointConfiguration, CartesianCenter, JointConfiguration > CircJointCenterCart
Definition: command_types_typedef.h:93
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::path_filename_
std::string path_filename_
Definition: xml_testdata_loader.h:257
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getPtpJoint
PtpJoint getPtpJoint(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
Definition: xml_testdata_loader.cpp:313
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getCartesianCenter
CartesianCenter getCartesianCenter(const std::string &cmd_name, const std::string &planning_group) const
Definition: xml_testdata_loader.cpp:422
pilz_industrial_motion_planner_testutils::CircInterimCart
Circ< CartesianConfiguration, CartesianInterim, CartesianConfiguration > CircInterimCart
Definition: command_types_typedef.h:91
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::AbstractCmdGetterAdapter::~AbstractCmdGetterAdapter
virtual ~AbstractCmdGetterAdapter()=default
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getCartesianInterim
CartesianInterim getCartesianInterim(const std::string &cmd_name, const std::string &planning_group) const
Definition: xml_testdata_loader.cpp:441
pilz_industrial_motion_planner_testutils::PtpCart
Ptp< CartesianConfiguration, CartesianConfiguration > PtpCart
Definition: command_types_typedef.h:84
pilz_industrial_motion_planner_testutils::LinJointCart
Lin< JointConfiguration, CartesianConfiguration > LinJointCart
Definition: command_types_typedef.h:87
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getCircCartInterimCart
CircInterimCart getCircCartInterimCart(const std::string &cmd_name) const override
Definition: xml_testdata_loader.cpp:477
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getLinCart
LinCart getLinCart(const std::string &cmd_name) const override
Definition: xml_testdata_loader.cpp:377
pilz_industrial_motion_planner_testutils::XmlTestdataLoader::getLinJoint
LinJoint getLinJoint(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
Definition: xml_testdata_loader.cpp:361


pilz_industrial_motion_planner_testutils
Author(s):
autogenerated on Sat May 3 2025 02:28:27