-
Notifications
You must be signed in to change notification settings - Fork 30
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
Testable Constraint Output #266
Changes from 12 commits
3fcb61f
46ed3d8
4dfa900
9368a14
235e0da
98ef161
9c36bae
62af07b
081e23e
d28417c
faffb52
3ecb343
a276c6a
c281a03
f83c72a
9863a86
924041b
a4a0309
2af9453
4ec21f8
4e2e20f
b8e0010
816e86e
4174efc
511555a
b3da15d
e061d63
e1ed415
6c2dbec
d3ada66
7b10b67
0868db7
cbc1b34
7a3b762
079b2f3
e990862
ce4160d
4768cda
43c8f92
e5e5d5b
354d3d5
18b2dda
cd9d522
2c67a67
0f6731b
d1b2040
ab1556f
b70af0a
9208f04
12647a3
2fae405
1357778
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,9 @@ class FrameTestable : public Testable | |
/// \param _state a MetaskeletonState to set the configuration of this | ||
/// constraint's metaskeketon. This state's StateSpace should match | ||
/// StateSpace returend by getStateSpace(). | ||
bool isSatisfied(const statespace::StateSpace::State* _state) const override; | ||
bool isSatisfied( | ||
const statespace::StateSpace::State* _state, | ||
TestableOutcome* _outcome = nullptr) const override; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Our convention is not to use a leading underscore for function parameter names. Please change |
||
|
||
// Documentation inhereted | ||
std::shared_ptr<statespace::StateSpace> getStateSpace() const override; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
#include <memory> | ||
#include "../statespace/StateSpace.hpp" | ||
#include "outcome/TestableOutcome.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: We don't need to include this header in favor of the forward declaration as namespace aikido {
namespace constraint {
class TestableOutcome;
/// Constraint which can be tested.
class Testable
{
... |
||
|
||
namespace aikido { | ||
namespace constraint { | ||
|
@@ -15,7 +16,8 @@ class Testable | |
|
||
/// Returns true if state satisfies this constraint. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document the |
||
virtual bool isSatisfied( | ||
const statespace::StateSpace::State* _state) const = 0; | ||
const statespace::StateSpace::State* _state, | ||
TestableOutcome* _outcome = nullptr) const = 0; | ||
|
||
/// Returns StateSpace in which this constraint operates. | ||
virtual statespace::StateSpacePtr getStateSpace() const = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef AIKIDO_CONSTRAINT_COLLISIONFREEOUTCOME_HPP_ | ||
#define AIKIDO_CONSTRAINT_COLLISIONFREEOUTCOME_HPP_ | ||
|
||
#include <sstream> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: It seems we need to include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate on this a bit? If is not included, then it looks like the string building in toString won't work (since a string stream is used there, and then converted to a string object). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The motivation behind this is that this way prevents unnecessarily including |
||
#include <vector> | ||
#include "TestableOutcome.hpp" | ||
|
||
namespace aikido { | ||
namespace constraint { | ||
|
||
class CollisionFreeOutcome : public TestableOutcome | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a simple docstring for this class like saying this class is a testable outcome for |
||
{ | ||
public: | ||
bool isSatisfied() const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Need |
||
std::string toString() const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Need |
||
void markCollisionBodyNode(const std::string& bodyNodeName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we call this |
||
void markSelfCollisionBodyNode(const std::string& bodyNodeName); | ||
|
||
private: | ||
std::vector<std::string> mCollisionBodyNodes; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...and then call this |
||
std::vector<std::string> mSelfCollisionBodyNodes; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have docstring for this class and its members? |
||
|
||
} // namespace constraint | ||
} // namespace aikido | ||
|
||
#endif // ifndef AIKIDO_CONSTRAINT_COLLISIONFREEOUTCOME_HPP_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef AIKIDO_CONSTRAINT_TESTABLEOUTCOME_HPP_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe our convention is that we use a subdirectory when the class is in a nested namespace. The only exception (off the top of my head) is putting implementations of template classes under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. My main reasoning here was that all of the things in the main directory seem to be constraints, and these new files aren't constraints- they're supposed to correspond to the outputs of constraints. If nobody else has strong feelings either way, I'll move the files into the main constraint directory before merging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually suggest putting this class definition directly in If you think this would clutter that file too much, then moving it up to |
||
#define AIKIDO_CONSTRAINT_TESTABLEOUTCOME_HPP_ | ||
|
||
#include <string> | ||
|
||
namespace aikido { | ||
namespace constraint { | ||
|
||
class TestableOutcome | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add docstring for this class? |
||
{ | ||
public: | ||
virtual bool isSatisfied() const = 0; | ||
virtual std::string toString() const = 0; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have docstring for this class and its members? |
||
|
||
} // namespace constraint | ||
} // namespace aikido | ||
|
||
#endif // ifndef AIKIDO_CONSTRAINT_TESTABLEOUTCOME_HPP_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,8 @@ statespace::StateSpacePtr CartesianProductTestable::getStateSpace() const | |
|
||
//============================================================================== | ||
bool CartesianProductTestable::isSatisfied( | ||
const aikido::statespace::StateSpace::State* _state) const | ||
const aikido::statespace::StateSpace::State* _state, | ||
TestableOutcome* _outcome) const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A general way to suppress warnings for unused parameter is simply commenting out the parameter name as bool CartesianProductTestable::isSatisfied(
const aikido::statespace::StateSpace::State* _state,
TestableOutcome* /*_outcome*/) const This is an answer to TODOs.1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! 😄 This is a super handy thing to know. |
||
{ | ||
const auto state | ||
= static_cast<const statespace::CartesianProduct::State*>(_state); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ statespace::StateSpacePtr CollisionFree::getStateSpace() const | |
|
||
//============================================================================== | ||
bool CollisionFree::isSatisfied( | ||
const aikido::statespace::StateSpace::State* _state) const | ||
const aikido::statespace::StateSpace::State* _state, | ||
TestableOutcome* _outcome) const | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function should clear the |
||
auto skelStatePtr = static_cast<const aikido::statespace::dart:: | ||
MetaSkeletonStateSpace::State*>(_state); | ||
|
@@ -42,16 +43,39 @@ bool CollisionFree::isSatisfied( | |
groups.second.get(), | ||
mCollisionOptions, | ||
&collisionResult); | ||
|
||
if (collision) | ||
{ | ||
if (_outcome != nullptr) | ||
{ | ||
auto collisionOutcome = static_cast<CollisionFreeOutcome*>(_outcome); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not guaranteed if I'm not sure what would be the preferred way here. @brianhou , @mkoval, @gilwoolee thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the only difference between (2) and (3) whether we silently fail or raise an exception when the My (limited) understanding is that we won't be passing a non-null There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with this logic (assuming that @brianhou's reasoning about (2) and (3) is correct). I'm going to with (3) right now, and we can change if people have strong feelings towards either approach. |
||
auto collidingBodies = collisionResult.getCollidingBodyNodes(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
for (const auto& elem : collidingBodies) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this should iterate over This isn't a problem now because our default |
||
{ | ||
collisionOutcome->markCollisionBodyNode(elem->getName()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: If you make collisionFreeOutcome->mContacts = collisionResult.getContacts(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for all the awesome feedback! 😄 I had a question about this one- when using Eigen::aligned_allocator (as mentioned in a previous comment), wouldn't this be not possible? The two vectors appear to use different allocators. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
return false; | ||
} | ||
} | ||
|
||
for (auto group : mGroupsToSelfCheck) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This is irrelevant to this PR, but let's avoid unnecessary copy here by changing this line to Also |
||
{ | ||
collision = mCollisionDetector->collide( | ||
group.get(), mCollisionOptions, &collisionResult); | ||
if (collision) | ||
{ | ||
if (_outcome != nullptr) | ||
{ | ||
auto collisionOutcome = static_cast<CollisionFreeOutcome*>(_outcome); | ||
auto collidingBodies = collisionResult.getCollidingBodyNodes(); | ||
for (const auto& elem : collidingBodies) | ||
{ | ||
collisionOutcome->markSelfCollisionBodyNode(elem->getName()); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: If you make collisionFreeOutcome->mSelfContacts = collisionResult.getContacts(); |
||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <aikido/constraint/outcome/CollisionFreeOutcome.hpp> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super nit: In a source file, we include the associated header very first then others in order of STL headers, 3rd party library headers, and AIKIDO headers. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to include |
||
namespace aikido { | ||
namespace constraint { | ||
|
||
//============================================================================== | ||
bool CollisionFreeOutcome::isSatisfied() const | ||
{ | ||
if (mCollisionBodyNodes.size() > 0 || mSelfCollisionBodyNodes.size() > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
//============================================================================== | ||
std::string CollisionFreeOutcome::toString() const | ||
{ | ||
std::stringstream ss; | ||
ss << "ALL COLLISIONS: " << std::endl; | ||
|
||
for (auto collBodyNodeName : mCollisionBodyNodes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
{ | ||
ss << "[COLLISION]: " << collBodyNodeName << std::endl; | ||
} | ||
|
||
for (auto selfCollBodyNodeName : mSelfCollisionBodyNodes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
{ | ||
ss << "[SELF COLLISION]: " << selfCollBodyNodeName << std::endl; | ||
} | ||
|
||
return std::move(ss.str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we don't need to use |
||
} | ||
|
||
//============================================================================== | ||
void CollisionFreeOutcome::markCollisionBodyNode( | ||
const std::string& bodyNodeName) | ||
{ | ||
mCollisionBodyNodes.push_back(bodyNodeName); | ||
} | ||
|
||
//============================================================================== | ||
void CollisionFreeOutcome::markSelfCollisionBodyNode( | ||
const std::string& bodyNodeName) | ||
{ | ||
mSelfCollisionBodyNodes.push_back(bodyNodeName); | ||
} | ||
|
||
} // namespace constraint | ||
} // namespace aikido |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,9 @@ class PassingConstraint : public aikido::constraint::Testable | |
} | ||
|
||
bool isSatisfied( | ||
const aikido::statespace::StateSpace::State* /*state*/) const override | ||
const aikido::statespace::StateSpace::State* /*state*/, | ||
aikido::constraint::TestableOutcome* = nullptr /*_outcome*/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
const override | ||
{ | ||
return true; | ||
} | ||
|
@@ -38,7 +40,9 @@ class FailingConstraint : public aikido::constraint::Testable | |
} | ||
|
||
bool isSatisfied( | ||
const aikido::statespace::StateSpace::State* /*state*/) const override | ||
const aikido::statespace::StateSpace::State* /*state*/, | ||
aikido::constraint::TestableOutcome* = nullptr /*_outcome*/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
const override | ||
{ | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document the
TestableOutcome
argument. I suggest making it simply return whateverTestableOutcome
is returned by the_poseConstraint
passed to this class' constructor.