39#include <boost/property_tree/xml_parser.hpp>
40#include <boost/algorithm/string.hpp>
46namespace pt = boost::property_tree;
52 CmdReader(
const pt::ptree::value_type& node) : cmd_node_(node)
69 const pt::ptree::value_type& cmd_node_;
71 double default_velocity_scale_{ DEFAULT_VEL };
72 double default_acceleration_scale_{ DEFAULT_ACC };
92 return cmd_node_.second.get<std::string>(
END_POS_STR);
97 return cmd_node_.second.get<
double>(
VEL_STR, default_velocity_scale_);
102 return cmd_node_.second.get<
double>(
ACC_STR, default_acceleration_scale_);
107 default_velocity_scale_ = scale;
113 default_acceleration_scale_ = scale;
117template <
class CmdType>
121 using FuncType = std::function<CmdType(
const std::string&)>;
140 pt::read_xml(path_filename_, tree_, pt::xml_parser::no_comments);
142 using std::placeholders::_1;
143 cmd_getter_funcs_[
"ptp"] = AbstractCmdGetterUPtr(
145 cmd_getter_funcs_[
"ptp_joint_cart"] = AbstractCmdGetterUPtr(
147 cmd_getter_funcs_[
"ptp_cart_cart"] =
150 cmd_getter_funcs_[
"lin"] = AbstractCmdGetterUPtr(
152 cmd_getter_funcs_[
"lin_cart"] =
155 cmd_getter_funcs_[
"circ_center_cart"] = AbstractCmdGetterUPtr(
157 cmd_getter_funcs_[
"circ_interim_cart"] = AbstractCmdGetterUPtr(
162 cmd_getter_funcs_[
"gripper"] =
167 const moveit::core::RobotModelConstPtr& robot_model)
177const pt::ptree::value_type& XmlTestdataLoader::findNodeWithName(
const boost::property_tree::ptree& tree,
178 const std::string& name,
const std::string& key,
179 const std::string& path)
const
181 std::string path_str{ (path.empty() ?
NAME_PATH_STR : path) };
184 for (
const pt::ptree::value_type& val : tree)
192 if (val.first != key)
197 const auto& node{ val.second.get_child(path_str, empty_tree_) };
198 if (node == empty_tree_)
202 if (node.data() == name)
209 msg.append(
"Node of type \"")
219 throw TestDataLoaderReadingException(msg);
225 const auto& poses_tree{ tree_.get_child(
POSES_PATH_STR, empty_tree_) };
226 if (poses_tree == empty_tree_)
230 return getJoints(findNodeWithName(poses_tree, pos_name,
POSE_STR).second, group_name);
234 const std::string& group_name)
const
237 if (joints_tree == empty_tree_)
243 std::vector<std::string> strs;
244 boost::split(strs, joint_node.second.data(), boost::is_any_of(
" "));
245 return JointConfiguration(group_name, strVec2doubleVec(strs),
robot_model_);
250 const auto& all_poses_tree{ tree_.get_child(
POSES_PATH_STR, empty_tree_) };
251 if (all_poses_tree == empty_tree_)
255 const auto& pose_tree{ findNodeWithName(all_poses_tree, pos_name,
POSE_STR).second };
257 const boost::property_tree::ptree& link_name_attr{ xyz_quat_tree.get_child(
LINK_NAME_PATH_STR, empty_tree_) };
258 if (link_name_attr == empty_tree_)
264 std::string data{ xyz_quat_tree.data() };
267 std::vector<std::string> pos_ori_str;
268 boost::split(pos_ori_str, data, boost::is_any_of(
" "));
272 const auto& seeds_tree{ xyz_quat_tree.get_child(
SEED_STR, empty_tree_) };
273 if (seeds_tree != empty_tree_)
283 std::string planning_group{ cmd_reader.getPlanningGroup() };
299 std::string planning_group{ cmd_reader.getPlanningGroup() };
315 std::string planning_group{ cmd_reader.getPlanningGroup() };
331 std::string planning_group{ cmd_reader.getPlanningGroup() };
347 std::string planning_group{ cmd_reader.getPlanningGroup() };
363 std::string planning_group{ cmd_reader.getPlanningGroup() };
376const pt::ptree::value_type& XmlTestdataLoader::findCmd(
const std::string& cmd_name,
const std::string& cmd_path,
377 const std::string& cmd_key)
const
380 const boost::property_tree::ptree& cmds_tree{ tree_.get_child(cmd_path, empty_tree_) };
381 if (cmds_tree == empty_tree_)
383 throw TestDataLoaderReadingException(
"No list of commands of type \"" + cmd_key +
"\" found");
386 return findNodeWithName(cmds_tree, cmd_name, cmd_key);
389CartesianCenter XmlTestdataLoader::getCartesianCenter(
const std::string& cmd_name,
390 const std::string& planning_group)
const
393 std::string aux_pos_name;
400 throw TestDataLoaderReadingException(
"Did not find center of circ");
404 aux.setConfiguration(
getPose(aux_pos_name, planning_group));
408CartesianInterim XmlTestdataLoader::getCartesianInterim(
const std::string& cmd_name,
409 const std::string& planning_group)
const
412 std::string aux_pos_name;
419 throw TestDataLoaderReadingException(
"Did not find interim of circ");
423 aux.setConfiguration(
getPose(aux_pos_name, planning_group));
430 std::string planning_group{ cmd_reader.getPlanningGroup() };
447 std::string planning_group{ cmd_reader.getPlanningGroup() };
464 std::string planning_group{ cmd_reader.getPlanningGroup() };
481 std::string planning_group{ cmd_reader.getPlanningGroup() };
501 for (
const pt::ptree::value_type& seq_cmd : sequence_cmd_tree)
510 const boost::property_tree::ptree& cmd_name_attr = seq_cmd.second.get_child(
NAME_PATH_STR, empty_tree_);
511 if (cmd_name_attr == empty_tree_)
516 const std::string& cmd_name{ cmd_name_attr.data() };
519 const boost::property_tree::ptree& type_name_attr{ seq_cmd.second.get_child(
CMD_TYPE_PATH_STR, empty_tree_) };
520 if (type_name_attr == empty_tree_)
524 const std::string& cmd_type{ type_name_attr.data() };
530 seq.
add(cmd_getter_funcs_.at(cmd_type)->getCmd(cmd_name), blend_radius);
539 cmd_reader.setDefaultVelocityScale(DEFAULT_VEL_GRIPPER);
540 cmd_reader.setDefaultAccelerationScale(DEFAULT_ACC_GRIPPER);
541 std::string planning_group{ cmd_reader.getPlanningGroup() };
void setStartConfiguration(StartType start)
void setGoalConfiguration(GoalType goal)
Class to define a robot configuration in space with the help of cartesian coordinates.
void setSeed(const JointConfiguration &config)
Data class storing all information regarding a Circ command.
void setAuxiliaryConfiguration(AuxiliaryType auxiliary)
CmdGetterAdapter(FuncType func)
CmdVariant getCmd(const std::string &cmd_name) const override
std::function< CmdType(const std::string &)> FuncType
CmdReader & setDefaultAccelerationScale(double scale)
double getVelocityScale() const
std::string getTargetLink() const
CmdReader(const pt::ptree::value_type &node)
double getAccelerationScale() const
std::string getPlanningGroup() const
std::string getStartPoseName() const
CmdReader & setDefaultVelocityScale(double scale)
std::string getEndPoseName() const
Class to define a robot configuration in space with the help of joint values.
Data class storing all information regarding a linear command.
void setAccelerationScale(double acceleration_scale)
void setPlanningGroup(const std::string &planning_group)
void setVelocityScale(double velocity_scale)
Data class storing all information regarding a Sequence command.
void add(const CmdVariant &cmd, const double blend_radius=0.)
Adds a command to the end of the sequence.
Abstract base class describing the interface to access test data like robot poses and robot commands.
moveit::core::RobotModelConstPtr robot_model_
void setRobotModel(moveit::core::RobotModelConstPtr robot_model)
Abstract base class providing a GENERIC getter-function signature which can be used to load DIFFERENT...
AbstractCmdGetterAdapter()=default
Implements a test data loader which uses a xml file to store the test data.
CircCenterCart getCircCartCenterCart(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
JointConfiguration getJoints(const std::string &pos_name, const std::string &group_name) const override
LinJointCart getLinJointCart(const std::string &cmd_name) const override
PtpCart getPtpCart(const std::string &cmd_name) const override
CircInterimCart getCircCartInterimCart(const std::string &cmd_name) const override
~XmlTestdataLoader() override
CartesianConfiguration getPose(const std::string &pos_name, const std::string &group_name) const override
PtpJointCart getPtpJointCart(const std::string &cmd_name) const override
XmlTestdataLoader(const std::string &path_filename)
LinCart getLinCart(const std::string &cmd_name) const override
LinJoint getLinJoint(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
CircJointCenterCart getCircJointCenterCart(const std::string &cmd_name) const override
CircJointInterimCart getCircJointInterimCart(const std::string &cmd_name) const override
Sequence getSequence(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
Gripper getGripper(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
PtpJoint getPtpJoint(const std::string &cmd_name) const override
Returns the command with the specified name from the test data.
const std::string GRIPPER_STR
const std::string LINS_PATH_STR
const std::string INTERMEDIATE_POS_STR
const std::string PTPS_PATH_STR
const std::string PTP_STR
const std::string POSE_STR
const std::string BLEND_STR
const std::string VEL_STR
const std::string GROUP_NAME_PATH_STR
const std::string XML_ATTR_STR
Interim< CartesianConfiguration, CartesianPathConstraintsBuilder > CartesianInterim
const std::string PLANNING_GROUP_STR
const std::string XYZ_QUAT_STR
const std::string END_POS_STR
const std::string TARGET_LINK_STR
const std::string NAME_PATH_STR
std::variant< PtpJoint, PtpJointCart, PtpCart, LinJoint, LinCart, CircCenterCart, CircInterimCart, CircJointCenterCart, CircJointInterimCart, Gripper > CmdVariant
const std::string SEQUENCE_PATH_STR
const std::string GRIPPERS_PATH_STR
const std::string CIRCS_PATH_STR
const std::string POSES_PATH_STR
const std::string LINK_NAME_PATH_STR
const std::string CIRC_STR
const std::string JOINT_STR
const std::string CMD_TYPE_PATH_STR
const std::string START_POS_STR
const std::string SEED_STR
const std::string BLEND_RADIUS_PATH_STR
const std::string LIN_STR
Center< CartesianConfiguration, CartesianPathConstraintsBuilder > CartesianCenter
const std::string ACC_STR
const std::string CENTER_POS_STR