SelfCollisionChecker/main.cpp
Go to the documentation of this file.
1 #include <hrpModel/ModelLoaderUtil.h>
2 #include <hrpModel/Link.h>
3 #include <hrpUtil/OnlineViewerUtil.h>
4 #include <hrpModel/OnlineViewerUtil.h>
5 #include <iostream>
6 #include <fstream>
7 #include "scc.h"
8 
9 using namespace OpenHRP;
10 using namespace hrp;
11 
12 int main(int argc, char *argv[])
13 {
14  if (argc < 3){
15  std::cerr << "Usage: " << argv[0] << "[VRML model] [log file] [-olv] [linkName1:linkNam2 ...]"
16  << std::endl;
17  return 1;
18  }
19 
21  bool useOLV=false;
22  for (int i=3; i<argc; i++){
23  std::string str = argv[i];
24  std::string::size_type pos;
25  if ((pos = str.find(":")) != std::string::npos){
26  std::string link1 = str.substr(0, pos);
27  std::string link2 = str.substr(pos+1);
28  std::cerr << "[" << link1 << "],[" << link2 << "]" << std::endl;
29  pairs.push_back(std::make_pair(link1, link2));
30  }else if(str=="-olv"){
31  useOLV=true;
32  }
33  }
34 
36  if (!loadBodyFromModelLoader(robot, argv[1],
37  argc, argv, true)){
38  std::cerr << "Error: failed to load model[" << argv[1] << "]"
39  << std::endl;
40  return 2;
41  }
42 
43  hrp::SelfCollisionChecker scc(robot, pairs);
44  std::cerr << scc.numOfCheckPairs() << " pairs are defined" << std::endl;
45 
46  OpenHRP::OnlineViewer_var olv;
47  if (useOLV){
48  olv = getOnlineViewer(argc, argv);
49  olv->load(robot->name().c_str(), argv[1]);
50  olv->clearLog();
51  }
52  OpenHRP::WorldState wstate;
53  wstate.characterPositions.length(1);
54  setupCharacterPosition(wstate.characterPositions[0], robot);
55 
56  std::ifstream ifs(argv[2]);
57  double tm, q[robot->numJoints()];
58 
59  int ret = 0;
60  ifs >> tm;
61  while (!ifs.eof()){
62  for (unsigned int i=0; i<robot->numJoints(); i++){
63  ifs >> q[i];
64  }
65  pairs = scc.check(q);
66  for (unsigned int i=0; i<pairs.size(); i++){
67  std::cout << tm << " " << pairs[i].first << ":" << pairs[i].second
68  << std::endl;
69  ret = 3;
70  }
71  if (useOLV){
72  wstate.time = tm;
73  updateCharacterPosition(wstate.characterPositions[0], robot);
74  olv->update(wstate);
75  }
76  ifs >> tm;
77  }
78 
79  return ret;
80 }
int main(int argc, char *argv[])
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
ifs
png_uint_32 i
boost::shared_ptr< Body > BodyPtr
void setupCharacterPosition(CharacterPosition &characterPosition, BodyPtr body)
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
LinkNamePairList check(const double *q)
Definition: scc.cpp:33
std::vector< std::pair< std::string, std::string > > LinkNamePairList
Definition: scc.h:6
void updateCharacterPosition(CharacterPosition &characterPosition, BodyPtr body)
HRP_UTIL_EXPORT OpenHRP::OnlineViewer_var getOnlineViewer(int argc, char **argv)
unsigned int numOfCheckPairs() const
Definition: scc.h:14


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50