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

Initial implementation of kinematic World #243

Merged
merged 10 commits into from
Oct 20, 2017
Merged

Conversation

brianhou
Copy link
Contributor

@brianhou brianhou commented Oct 18, 2017

This is a first attempt at a kinematic version of dart::simulation::World. Using a DART World as our default environment representation forces users to instantiate a dynamics engine, which is unnecessary overhead for many of our tasks. We'll add more functionality in future PRs.


Before creating a pull request

  • Document new methods and classes
  • Format code with make format

Before merging a pull request

  • Set version target by selecting a milestone on the right side
  • Summarize this change in CHANGELOG.md
  • Add unit test(s) for this change

@brianhou brianhou added this to the Aikido 0.2.0 milestone Oct 18, 2017
@brianhou brianhou requested a review from jslee02 October 18, 2017 22:48
}

//==============================================================================
const std::string& World::setName(const std::string& newName)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to return the name. The reason we did this in DART was that the given name and the actual name can be different to manage all the names to be unique. If the given name was taken then the actual name would be the given name + "(1)" (the number will increase until the name becomes unique). However, I don't think we want the names of the kinematic world to be unique.

dart::dynamics::SkeletonPtr World::getSkeleton(const std::string& name) const
{
for (const auto& skeleton : mSkeletons)
if (skeleton->getName() == name)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: The convention is using curly parentheses if the for-state (or other control statements) is multiple-line.

//==============================================================================
std::string World::addSkeleton(const dart::dynamics::SkeletonPtr& skeleton)
{
std::lock_guard<std::mutex> lock(mMutex);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: It also looks safe even we lock after the below nullity check because it refers only the parameter.

virtual ~World() = default;

/// Create a clone of this World. All Skeletons will be copied over.
std::shared_ptr<World> clone(const std::string& name) const;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Need docstring for the parameter.

Also, I like you used newName in the source file for this parameter. It would be good to use the same name here too.

//==============================================================================
void World::removeSkeleton(const dart::dynamics::SkeletonPtr& skeleton)
{
std::lock_guard<std::mutex> lock(mMutex);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: It also looks safe even we lock after the below nullity check because it refers only the parameter.

@codecov
Copy link

codecov bot commented Oct 18, 2017

Codecov Report

Merging #243 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #243   +/-   ##
=======================================
  Coverage   70.78%   70.78%           
=======================================
  Files         172      172           
  Lines        5055     5055           
  Branches      802      802           
=======================================
  Hits         3578     3578           
  Misses        993      993           
  Partials      484      484

@brianhou brianhou requested a review from jslee02 October 19, 2017 17:52
Copy link

@prasbg prasbg left a comment

Choose a reason for hiding this comment

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

Nice, this seems like a straightforward little class.

{
public:
/// Construct a kinematic World.
World(const std::string& name);
Copy link

Choose a reason for hiding this comment

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

If we are creating or cloning worlds inside of an optimizer or something, does it really make sense to need to generate names for all of them? I think DART has some mechanisms for autogenerating IDs if names are not set, something like that might make sense here if this is just for semantic purposes.

, skel2{dart::dynamics::Skeleton::create("skel2")}
, skel3{dart::dynamics::Skeleton::create("skel3")}
{
mWorld = std::make_shared<aikido::planner::World>("test");
Copy link

Choose a reason for hiding this comment

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

Should World have a similar create() helper to the above one that Skeleton has?

@psigen
Copy link
Member

psigen commented Oct 19, 2017

Oops, posted PR review with wrong account 🤷‍♀️

Copy link
Member

@jslee02 jslee02 left a comment

Choose a reason for hiding this comment

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

I think the create() should return std::unique_ptr for the reason mentioned below. Other than that, it looks good to go!

mutable std::mutex mMutex;

/// NameManager for keeping track of Worlds
static dart::common::NameManager<World*> worldNameManager;
Copy link
Member

Choose a reason for hiding this comment

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

I believe our convention is mStaticVariable even for static member variables.

dart::common::NameManager<dart::dynamics::SkeletonPtr> mSkeletonNameManager;
};

typedef std::shared_ptr<World> WorldPtr;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Let's use C++11 style of type aliasing: using WorldPtr = std::shared_ptr<World>().

std::shared_ptr<World> clone(const std::string& newName = "") const;

/// Create a new World inside of a shared_ptr
static std::shared_ptr<World> create(const std::string& name = "");
Copy link
Member

@jslee02 jslee02 Oct 19, 2017

Choose a reason for hiding this comment

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

In case we provide one creator function, then it should be returning std::unique_ptr because we can convert std::unique_ptr to std::shared_ptr but the opposite is not allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I mostly copied this from DART 😅

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, DART also needs to be tweaked. 😞 There is (or was) ongoing discussion: dartsim/dart#845

@brianhou brianhou merged commit 677c719 into master Oct 20, 2017
@brianhou brianhou deleted the enhancement/brianhou/world branch October 24, 2017 01:35
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.

4 participants