diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 8e3d27f423f..8a533d0c282 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(ProjectGenerator) +add_subdirectory(SelfCollisionChecker) if(USE_HRPSYSUTIL) add_subdirectory(simulator) add_subdirectory(viewer) diff --git a/util/SelfCollisionChecker/CMakeLists.txt b/util/SelfCollisionChecker/CMakeLists.txt new file mode 100644 index 00000000000..df0f8c0a6a8 --- /dev/null +++ b/util/SelfCollisionChecker/CMakeLists.txt @@ -0,0 +1,8 @@ +add_executable(hrpsys-self-collision-checker scc.cpp main.cpp) +target_link_libraries(hrpsys-self-collision-checker ${OPENHRP_LIBRARIES}) + +set(target hrpsys-self-collision-checker) + +install(TARGETS ${target} + RUNTIME DESTINATION bin +) diff --git a/util/SelfCollisionChecker/main.cpp b/util/SelfCollisionChecker/main.cpp new file mode 100644 index 00000000000..6417a4d2537 --- /dev/null +++ b/util/SelfCollisionChecker/main.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include "scc.h" + +int main(int argc, char *argv[]) +{ + if (argc < 3){ + std::cerr << "Usage: " << argv[0] << "[VRML model] [log file]" + << std::endl; + return 1; + } + + hrp::LinkNamePairList pairs; + for (int i=3; inumJoints()]; + + ifs >> tm; + while (!ifs.eof()){ + for (int i=0; inumJoints(); i++){ + ifs >> q[i]; + } + pairs = scc.check(q); + for (unsigned int i=0; i> tm; + } + + return 0; +} diff --git a/util/SelfCollisionChecker/scc.cpp b/util/SelfCollisionChecker/scc.cpp new file mode 100644 index 00000000000..846aa849163 --- /dev/null +++ b/util/SelfCollisionChecker/scc.cpp @@ -0,0 +1,52 @@ +#include +#include "scc.h" + +using namespace hrp; + +SelfCollisionChecker::SelfCollisionChecker(hrp::BodyPtr body, const hrp::LinkNamePairList &pairs) : m_robot(body) +{ + for (int i=0; inumLinks(); i++){ + Link *link1 = m_robot->link(i); + for (int j=i+1; jnumLinks(); j++){ + Link *link2 = m_robot->link(j); + if (link1->parent != link2 && link2->parent != link1){ + bool skip = false; + for (unsigned int k=0; kname + && pairs[k].second == link2->name) + ||(pairs[k].first == link2->name + && pairs[k].second == link1->name)){ + skip = true; + break; + } + } + if (!skip){ + m_checkPairs.push_back(ColdetModelPair(link1->coldetModel, + link2->coldetModel)); + } + } + } + } +} + + +LinkNamePairList SelfCollisionChecker::check(const double *q) +{ + LinkNamePairList pairs; + + for (int i=0; inumJoints(); i++){ + m_robot->joint(i)->q = q[i]; + } + m_robot->calcForwardKinematics(); + for (int i=0; inumLinks(); i++){ + Link *l = m_robot->link(i); + l->coldetModel->setPosition(l->attitude(), l->p); + } + for (unsigned int i=0; iname(), + m_checkPairs[i].model(1)->name())); + } + } + return pairs; +} diff --git a/util/SelfCollisionChecker/scc.h b/util/SelfCollisionChecker/scc.h new file mode 100644 index 00000000000..9242622b1b2 --- /dev/null +++ b/util/SelfCollisionChecker/scc.h @@ -0,0 +1,20 @@ +#include +#include + +namespace hrp{ + +typedef std::vector > LinkNamePairList; + +class SelfCollisionChecker +{ +public: + SelfCollisionChecker(hrp::BodyPtr body, + const LinkNamePairList& pairs=LinkNamePairList()); + LinkNamePairList check(const double *q); + unsigned int numOfCheckPairs() const { return m_checkPairs.size(); } +private: + hrp::BodyPtr m_robot; + std::vector m_checkPairs; +}; + +}