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

Conversation

Ponzel
Copy link

@Ponzel Ponzel commented Apr 28, 2018

Implemented for the Herbathon. I thought a small util file would be appropriate for stuff like this. What do you think?

I tested the function with the food manipulation demo.

@Ponzel Ponzel requested review from brianhou and gilwoolee April 28, 2018 00:04
Copy link
Contributor

@brianhou brianhou left a comment

Choose a reason for hiding this comment

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

Looks good! I just had a few minor suggestions.

namespace io {

const SkeletonPtr makeBodyFromURDF(
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.

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.

const std::shared_ptr<aikido::io::CatkinResourceRetriever>
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 aikido {
namespace io {

const SkeletonPtr makeBodyFromURDF(
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.

#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.

#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

src/io/util.cpp Outdated
throw std::runtime_error("unable to load '" + uri + "'");

dynamic_cast<dart::dynamics::FreeJoint*>(skeleton->getJoint(0))
->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.

src/io/util.cpp Outdated
if (!skeleton)
throw std::runtime_error("unable to load '" + uri + "'");

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.

@codecov
Copy link

codecov bot commented May 3, 2018

Codecov Report

Merging #388 into master will decrease coverage by 0.15%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master     #388      +/-   ##
==========================================
- Coverage   81.11%   80.96%   -0.16%     
==========================================
  Files         200      201       +1     
  Lines        5693     5705      +12     
==========================================
+ Hits         4618     4619       +1     
- Misses       1075     1086      +11
Impacted Files Coverage Δ
src/io/util.cpp 0% <0%> (ø)
src/planner/ompl/CRRT.cpp 76.16% <0%> (+0.58%) ⬆️

namespace aikido {
namespace io {

dart::dynamics::SkeletonPtr loadSkeletonFromURDF(
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs docstring.

src/io/util.cpp Outdated
namespace aikido {
namespace io {

dart::dynamics::SkeletonPtr loadSkeletonFromURDF(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We typically put "//==================================" at the beginning of a new method. Please check other cpp files.

src/io/util.cpp Outdated
dart::dynamics::SkeletonPtr loadSkeletonFromURDF(
const dart::common::ResourceRetrieverPtr resourceRetriever,
const std::string& uri,
const Eigen::Isometry3d& transform = Eigen::Isometry3d::Identity())
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer making the default param Eigen::Isometry3d::identity() be specified at the header file to make it more explicit.

src/io/util.cpp Outdated
= 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

src/io/util.cpp Outdated
if (freeJoint == nullptr)
{
throw std::runtime_error(
"unable to cast Skeleton's root joint to FreeJoint.");
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

@jslee02 jslee02 added this to the Aikido 0.3.0 milestone May 4, 2018
@brianhou brianhou merged commit 1762546 into master May 6, 2018
@brianhou brianhou deleted the makeBodyFromURDF branch May 6, 2018 17:49
gilwoolee pushed a commit that referenced this pull request Jan 21, 2019
* added makeBodyFromURDF convenience function (see herbathon trello)

* added cpp, configured CMakeLists

* integrated PR feedback about loadSkeletonFromUrdf

* formatting

* documentation

* Minor cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants