Robowflex  v0.1
Making MoveIt Easy
robowflex_dart/src/io.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #include <dart/utils/urdf/urdf.hpp>
4 
5 #include <robowflex_library/io.h>
6 
7 #include <robowflex_dart/io.h>
8 #include <robowflex_dart/robot.h>
9 
10 using namespace robowflex::darts;
11 
12 static dart::utils::DartLoader URDF;
13 static dart::utils::PackageResourceRetriever PACKAGE;
14 
15 void IO::addPackage(const std::string &package)
16 {
17  const auto path = robowflex::IO::resolvePackage("package://" + package);
18  if (not path.empty())
19  addPackage(package, path);
20 }
21 
22 void IO::addPackage(const std::string &package, const std::string &location)
23 {
24  URDF.addPackageDirectory(package, location);
25  PACKAGE.addPackageDirectory(package, location);
26 }
27 
28 bool IO::loadURDF(Robot &robot, const std::string &urdf)
29 {
30  // Pre-load URDF and extract all relevant ROS packages
31  const auto &file = IO::getPackageFile(urdf);
32  const auto &text = robowflex::IO::loadXMLToString(file);
33 
34  const auto packages = robowflex::IO::findPackageURIs(text);
35  for (const auto &package : packages)
36  IO::addPackage(package);
37 
38  auto skeleton = URDF.parseSkeletonString(text, "");
39  if (not skeleton)
40  return false;
41 
42  skeleton->setSelfCollisionCheck(true);
43 
44  for (auto *joint : skeleton->getJoints())
45  joint->setPositionLimitEnforced(true);
46 
47  robot.setSkeleton(skeleton);
48  return true;
49 }
50 
52 {
54  if (file.empty())
55  file = PACKAGE.getFilePath(uri);
56 
57  return file;
58 }
A sampleable goal region for OMPL for a set of TSRs. Samples goals in a separate thread using a clone...
T empty(T... args)
Functions for loading and animating robots in Blender.
std::set< std::string > findPackageURIs(const std::string &string)
Finds all package URIs within a string.
std::string resolvePackage(const std::string &path)
Resolves package:// URLs to their canonical form. The path does not need to exist,...
std::string loadXMLToString(const std::string &path)
Loads an XML or .xacro file to a string.
std::string getPackageFile(const std::string &uri)
Get the filename for a package URI using Dart's lookup.
bool loadURDF(Robot &robot, const std::string &urdf)
Loads a URDF at urdf into a robot.
void addPackage(const std::string &package)
Add a ROS package to Dart's searchable index. Looks up package with rospack.
DART-based robot modeling and planning.
Definition: acm.h:16
static dart::utils::PackageResourceRetriever PACKAGE
static dart::utils::DartLoader URDF