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

Fix WorldInteractiveMarkerViewer bug when removing Skeletons #252

Merged
merged 6 commits into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

* Planner

* Added World class: [#243](https://github.com/personalrobotics/aikido/pull/243)
* Added World class: [#243](https://github.com/personalrobotics/aikido/pull/243), [#252](https://github.com/personalrobotics/aikido/pull/252)
* Added vector field planner [#246](https://github.com/personalrobotics/aikido/pull/246)

* RViz
Expand Down
5 changes: 5 additions & 0 deletions include/aikido/planner/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class World
/// \param name Name of desired Skeleton
dart::dynamics::SkeletonPtr getSkeleton(const std::string& name) const;

/// Returns true if the Skeleton is in this World.
/// \param skel Desired Skeleton
/// \return True if succeeded to find the Skeleton
bool hasSkeleton(const dart::dynamics::SkeletonPtr& skel) const;

/// Get the number of Skeletons
std::size_t getNumSkeletons() const;

Expand Down
4 changes: 2 additions & 2 deletions include/aikido/rviz/WorldInteractiveMarkerViewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class WorldInteractiveMarkerViewer : public InteractiveMarkerViewer
/// Thread target for auto-updating the viewer
void autoUpdate();

/// Mapping of Skeleton names to SkeletonMarkers
std::map<std::string, SkeletonMarkerPtr> mSkeletonMarkers;
/// Mapping of Skeletons to SkeletonMarkers
std::map<dart::dynamics::SkeletonPtr, SkeletonMarkerPtr> mSkeletonMarkers;
Copy link
Member

Choose a reason for hiding this comment

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

Although this is a stopgap solution (over using callbacks), we might want to use std::weak_pointer<...> here because this class doesn't need to have the ownership as it just uses the skeletons only when they still exist in mWorld.


/// World that automatically updates the viewer
aikido::planner::WorldPtr mWorld;
Expand Down
7 changes: 7 additions & 0 deletions src/planner/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ dart::dynamics::SkeletonPtr World::getSkeleton(const std::string& name) const
return mSkeletonNameManager.getObject(name);
}

//==============================================================================
bool World::hasSkeleton(const dart::dynamics::SkeletonPtr& skel) const
{
return std::find(mSkeletons.begin(), mSkeletons.end(), skel)
!= mSkeletons.end();
}

//==============================================================================
std::size_t World::getNumSkeletons() const
{
Expand Down
4 changes: 2 additions & 2 deletions src/rviz/WorldInteractiveMarkerViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void WorldInteractiveMarkerViewer::update()
{
// Either a new SkeletonMarker or a previously-inserted SkeletonMarker
auto result = mSkeletonMarkers.emplace(
skeleton->getName(), CreateSkeletonMarker(skeleton, mFrameId));
skeleton, CreateSkeletonMarker(skeleton, mFrameId));

std::unique_lock<std::mutex> lock(skeleton->getMutex(), std::try_to_lock);
if (lock.owns_lock())
Expand All @@ -76,7 +76,7 @@ void WorldInteractiveMarkerViewer::update()
while (it != std::end(mSkeletonMarkers))
{
// Skeleton still exists in the World, do nothing.
if (mWorld->getSkeleton(it->first))
if (mWorld->hasSkeleton(it->first))
{
++it;
}
Expand Down