controllerclientcpp  0.6.1
 全て クラス ネームスペース ファイル 関数 変数 型定義 列挙型 列挙型の値 マクロ定義 ページ
mujincalibrationstuff.cpp
説明を見る。
1 // -*- coding: utf-8 -*-
4 
5 #include <boost/thread/thread.hpp> // for sleep
6 
7 #include <iostream>
8 
9 using namespace mujinclient;
10 
11 int main(int argc, char ** argv)
12 {
13  if( argc < 2 ) {
14  std::cout << "need username:password. Example: mujinclienttest myuser:mypass [url]\n\nurl - [optional] For example https://controller.mujin.co.jp/" << std::endl;
15  return 1;
16  }
17  ControllerClientPtr controller;
18  if( argc >= 5 ) {
19  controller = CreateControllerClient(argv[1], argv[2], argv[3], argv[4]);
20  }
21  if( argc == 4 ) {
22  controller = CreateControllerClient(argv[1], argv[2], argv[3]);
23  }
24  else if( argc == 3 ) {
25  controller = CreateControllerClient(argv[1], argv[2]);
26  }
27  else {
28  controller = CreateControllerClient(argv[1]);
29  }
30  std::cout << "connected to controller v" << controller->GetVersion() << std::endl;
31  std::string sceneuri = "mujin:/irex2013.mujin.dae";
32  std::string scenepk = controller->GetScenePrimaryKeyFromURI_UTF8(sceneuri);
33  SceneResourcePtr scene, newscene;
34  std::string robotname = "VP-5243I";
35  scene.reset(new SceneResource(controller,scenepk));
36  std::vector<SceneResource::InstObjectPtr> instobjects;
37 
38  std::cout << "scenename: " << scene->Get("name") << std::endl;
39 
40  //newscene = scene->Copy("irex2013_copied");
41  //std::cout << "newname: " << newscene->Get("name") << std::endl;
42 
43  scene->GetInstObjects(instobjects);
44  int robotinstindex = -1;
45  for(size_t i = 0; i < instobjects.size(); ++i) {
46  //std::cout << "==============" << std::endl;
47  //instobjects[i]->Print();
48  if (instobjects[i]->name == robotname)
49  {
50  robotinstindex = i;
51  }
52  }
53  if (robotinstindex == -1) {
54  std::cout << "no such kind of robot: " << robotname << std::endl;
55  exit(1);
56  }
57  std::cout << "links: " << std::endl;
58  for (size_t i = 0; i < instobjects[robotinstindex]->links.size(); i++) {
59  std::cout << "\tname: " << instobjects[robotinstindex]->links[i].name << std::endl;
60  std::cout << "\tquaternion: ";
61  for (int j = 0; j < 4; j++) {
62  std::cout << instobjects[robotinstindex]->links[i].quaternion[j] << ", ";
63  }
64  std::cout << std::endl;
65  std::cout << "\ttranslate: ";
66  for (int j = 0; j < 3; j++) {
67  std::cout << instobjects[robotinstindex]->links[i].translate[j] << ", ";
68  }
69  std::cout << std::endl;
70  }
71 
72  std::cout << "instobjects[robotinstindex]->tools: " << std::endl;
73  for (size_t i = 0; i < instobjects[robotinstindex]->tools.size(); i++) {
74  std::cout << "tool" << i << std::endl;
75  std::cout << "\tname: " << instobjects[robotinstindex]->tools[i].name << std::endl;
76 
77  std::cout << "\tquaternion: ";
78  for (int j = 0; j < 4; j++) {
79  std::cout << instobjects[robotinstindex]->tools[i].quaternion[j] << ", ";
80  }
81  std::cout << std::endl;
82 
83  std::cout << "\ttranslate: ";
84  for (int j = 0; j < 3; j++) {
85  std::cout << instobjects[robotinstindex]->tools[i].translate[j] << ", ";
86  }
87  std::cout << std::endl;
88 
89  std::cout << "\tdirection: ";
90  for (int j = 0; j < 3; j++) {
91  std::cout << instobjects[robotinstindex]->tools[i].direction[j] << ", ";
92  }
93  std::cout << std::endl;
94  }
95 
96  /*
97  ObjectResourcePtr object;
98  RobotResourcePtr robot;
99  robot.reset(new RobotResource(controller, instobjects[robotinstindex]->object_pk));
100  object.reset(new ObjectResource(controller, instobjects[objectinstndex]->object_pk));
101 
102  std::vector<RobotResource::ToolResourcePtr> tools;
103  std::vector<ObjectResource::LinkResourcePtr> robotlinks, objectlinks;
104  robot->GetTools(tools);
105  size_t flangeindex;
106  for(size_t i = 0; i < tools.size(); ++i) {
107  if(tools[i]->name == "FlangeBase"){
108  flangeindex = i;
109  }
110  //std::cout << "------" << std::endl;
111  //std::cout << tools[i]->name << std::endl;
112  //std::cout << tools[i]->frame_origin<< std::endl;
113  //std::cout << tools[i]->frame_tip<< std::endl;
114  //std::cout << tools[i]->pk<< std::endl;
115  }
116  robot->GetLinks(robotlinks);
117  object->GetLinks(objectlinks);
118 
119  for(size_t i = 0; i < robotlinks.size(); ++i) {
120  //std::cout << "------" << std::endl;
121  //std::cout << robotlinks[i]->name << std::endl;
122  //std::cout << robotlinks[i]->pk<< std::endl;
123  //for (size_t j = 0; j < robotlinks[i]->attachmentpks.size(); j++) {
124  // std::cout << robotlinks[i]->attachmentpks[j] << std::endl;
125  //}
126  }
127 
128  std::cout << "original grabs: " << instobjects[robotinstindex]->grabs.size() << std::endl;
129  for(size_t i = 0; i < instobjects[robotinstindex]->grabs.size(); ++i) {
130  std::cout << instobjects[robotinstindex]->grabs[i].Serialize() << std::endl;
131  }
132 
133  instobjects[robotinstindex]->GrabObject(instobjects[objectinstndex], objectlinks[0]->pk, robotlinks[0]->pk);
134  newscene->GetInstObjects(instobjects);
135  std::cout << "new grabs: " << instobjects[robotinstindex]->grabs.size() << std::endl;
136  for(size_t i = 0; i < instobjects[robotinstindex]->grabs.size(); ++i) {
137  std::cout << instobjects[robotinstindex]->grabs[i].Serialize() << std::endl;
138  }
139  */
141 }