Robowflex  v0.1
Making MoveIt Easy
robowflex::openrave Namespace Reference

Functions

bool fromXMLFile (moveit_msgs::PlanningScene &planning_scene, const std::string &file, const std::string &model_dir)
 Loads a planning_scene from an OpenRAVE Environment XML. More...
 

Function Documentation

◆ fromXMLFile()

bool robowflex::openrave::fromXMLFile ( moveit_msgs::PlanningScene &  planning_scene,
const std::string file,
const std::string model_dir 
)

Loads a planning_scene from an OpenRAVE Environment XML.

Parameters
[out]planning_sceneThe output MoveIt message that will be filled with the planning scene contents.
[in]fileThe path to the OpenRAVE environment XML.
[in]model_dirThe path to the models directory, which should contain files referenced by the passed in file. In OpenRAVE, "the root directory for all models files is the folder openrave is launched at."
Returns
True on success, false on failure.

Definition at line 208 of file openrave.cpp.

210 {
211  SceneParsingContext load_struct;
212  load_struct.directory_stack.push(model_dir);
213 
214  // Hardcoded offset on WAM (see wam7.kinbody.xml)
215  RobotPose tf;
216  tf.translation() = Eigen::Vector3d(0.0, 0.0, -0.346);
217  tf.linear() = Eigen::Quaterniond::Identity().toRotationMatrix();
218  load_struct.robot_offset = tf;
219 
220  tinyxml2::XMLDocument doc;
221  if (!doc.LoadFile(IO::resolvePath(file).c_str()))
222  {
223  RBX_ERROR("Cannot load file %s", file);
224  return false;
225  }
226 
227  auto *env = getFirstChild(&doc, "Environment");
228  auto *robot = getFirstChild(env, "Robot");
229  if (robot)
230  load_struct.robot_offset =
231  load_struct.robot_offset * TFfromXML(getFirstChild(robot, "Translation"), //
232  getFirstChild(robot, "RotationAxis"), nullptr);
233 
234  auto *elem = getFirstChild(env);
235  if (not elem)
236  {
237  RBX_ERROR("There is no/an empty environment element in this openrave scene.");
238  return false;
239  }
240 
241  for (; elem; elem = elem->NextSiblingElement())
242  {
243  const std::string p_key = std::string(elem->Value());
244  if (p_key == "KinBody")
245  {
246  if (!parseKinbody(load_struct, elem, load_struct.robot_offset.inverse(), planning_scene))
247  return false;
248  }
249  else
250  RBX_INFO("Ignoring elements of value %s", p_key);
251  }
252 
253  if (not load_struct.coll_objects.empty())
254  planning_scene.is_diff = true;
255 
256  return true;
257 }
T c_str(T... args)
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118
Functions for loading and animating robots in Blender.
std::string resolvePath(const std::string &path)
Resolves package:// URLs and relative file paths to their canonical form.
std::decay< decltype(std::declval< moveit::core::Transforms >().getTransform("")) >::type RobotPose
A pose (point in SE(3)) used in various functions. Defined from what MoveIt! uses.
Definition: adapter.h:24