Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Herbathon: add makeBodyFromUrdf convenience function #388

Merged
merged 10 commits into from
May 6, 2018
1 change: 1 addition & 0 deletions include/aikido/io.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "io/CatkinResourceRetriever.hpp"
#include "io/KinBodyParser.hpp"
#include "io/yaml.hpp"
#include "io/util.hpp"
22 changes: 22 additions & 0 deletions include/aikido/io/util.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef AIKIDO_IO_UTIL_HPP_
#define AIKIDO_IO_UTIL_HPP_

#include <aikido/io/CatkinResourceRetriever.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Our convention is to:
(1) use "..." for including AIKIDO headers
(2) include headers in order (in header file): (a) system headers (i.e., STL), (2) 3rd party libraries, (3) AIKIDO headers.

So this should be:

#include <dart/dart.hpp>
#include <dart/utils/urdf/DartLoader.hpp>
#include "aikido/io/CatkinResourceRetriever.hpp"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it but could you tell me if there is a specific reason for the header include order? Does it have an advantage to do it this way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header ordering generally follows the Google C++ style convention:
https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes

#include <dart/dart.hpp>
#include <dart/utils/urdf/DartLoader.hpp>

using dart::dynamics::SkeletonPtr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using in headers because it can pollute namespaces by including this header. Let's remove and use explicitly dart::dynamics::SkeletonPtr in headers. You could use using in sources.


namespace aikido {
namespace io {

const SkeletonPtr makeBodyFromURDF(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to loadSkeletonFromURDF.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Returning by const value is generally unnecessary. Let's just return SkeletonPtr.

const std::shared_ptr<aikido::io::CatkinResourceRetriever>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be a dart::common::ResourceRetrieverPtr, since that's what the DART URDF loader is expecting.

resourceRetriever,
const std::string& uri,
const Eigen::Isometry3d& transform);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can make this an optional argument by setting its default value to identity.


} // namespace io
} // namespace aikido

#endif // AIKIDO_IO_UTIL_HPP_
1 change: 1 addition & 0 deletions src/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(sources
CatkinResourceRetriever.cpp
KinBodyParser.cpp
yaml.cpp
util.cpp
)

add_library("${PROJECT_NAME}_io" SHARED ${sources})
Expand Down
24 changes: 24 additions & 0 deletions src/io/util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "aikido/io/util.hpp"

namespace aikido {
namespace io {

const SkeletonPtr makeBodyFromURDF(
const std::shared_ptr<aikido::io::CatkinResourceRetriever>
resourceRetriever,
const std::string& uri,
const Eigen::Isometry3d& transform)
{
dart::utils::DartLoader urdfLoader;
const SkeletonPtr skeleton = urdfLoader.parseSkeleton(uri, resourceRetriever);

if (!skeleton)
throw std::runtime_error("unable to load '" + uri + "'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: unable-> Unable


dynamic_cast<dart::dynamics::FreeJoint*>(skeleton->getJoint(0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also make this skeleton->getRootJoint() instead of skeleton->getJoint(0). @jslee02 can you confirm?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!

Also, we should check whether skeleton is not empty.

->setTransform(transform);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need nullity check after dynamic casting.

return skeleton;
}

} // namespace io
} // namespace aikido