controllerclientcpp  0.6.1
 全て クラス ネームスペース ファイル 関数 変数 型定義 列挙型 列挙型の値 マクロ定義 ページ
mujinhandeyecalibration.cpp
説明を見る。
1 // -*- coding: utf-8 -*-
5 
6 #include <boost/thread/thread.hpp> // for sleep
7 #include <boost/program_options.hpp>
8 
9 #include <iostream>
10 
11 using namespace mujinclient;
12 
13 int main(int argc, char ** argv)
14 {
15  // parse command line arguments
16  namespace bpo = boost::program_options;
17  bpo::options_description desc("Options");
18 
19  desc.add_options()
20  ("help,h", "produce help message")
21  ("controller_ip", bpo::value<std::string>()->default_value("controller3"), "ip of the mujin controller, e.g. controller3")
22  ("controller_port", bpo::value<unsigned int>()->default_value(80), "port of the mujin controller, e.g. 80")
23  ("controller_username_password", bpo::value<std::string>()->required(), "username and password to the mujin controller, e.g. username:password")
24  ("robot_controller_ip", bpo::value<std::string>()->default_value("192.168.13.201"), "ip of the robot controller, e.g. 192.168.13.201")
25  ("robot_controller_port", bpo::value<unsigned int>()->default_value(5007), "port of the robot controller, e.g. 5007")
26  ("binpicking_task_zmq_port", bpo::value<unsigned int>()->default_value(7100), "port of the binpicking task on the mujin controller, e.g. 7101")
27  ("binpicking_task_heartbeat_port", bpo::value<unsigned int>()->default_value(7100), "port of the binpicking task's heartbeat signal on the mujin controller, e.g. 7101")
28  ("binpicking_task_scenepk", bpo::value<std::string>()->default_value("irex2013.mujin.dae"), "scene pk of the binpicking task on the mujin controller, e.g. irex2013.mujin.dae")
29  ;
30  bpo::variables_map opts;
31  bpo::store(bpo::parse_command_line(argc, argv, desc), opts);
32  bool badargs = false;
33  try {
34  bpo::notify(opts);
35  }
36  catch(...) {
37  badargs = true;
38  }
39  if(opts.count("help") || badargs) {
40  std::cout << "Usage: " << argv[0] << " [OPTS]" << std::endl;
41  std::cout << std::endl;
42  std::cout << desc << std::endl;
43  return (1);
44  }
45  const std::string controllerIp = opts["controller_ip"].as<std::string>();
46  const unsigned int controllerPort = opts["controller_port"].as<unsigned int>();
47  const std::string controllerUsernamePass = opts["controller_username_password"].as<std::string>();
48  const std::string robotControllerIp = opts["robot_controller_ip"].as<std::string>();
49  const unsigned int binpickingTaskZmqPort = opts["binpicking_task_zmq_port"].as<unsigned int>();
50  const unsigned int binpickingTaskHeartbeatPort = opts["binpicking_task_heartbeat_port"].as<unsigned int>();
51  const std::string binpickingTaskScenePk = opts["binpicking_task_scenepk"].as<std::string>();
52 
53  // connect to mujin controller
54  std::stringstream url_ss;
55  url_ss << "http://"<< controllerIp << ":" << controllerPort;
56  ControllerClientPtr controller = CreateControllerClient(controllerUsernamePass, url_ss.str());
57  std::cout << "connected to mujin controller at " << url_ss.str() << std::endl;
58  SceneResourcePtr scene(new SceneResource(controller,binpickingTaskScenePk));
59  BinPickingTaskResourcePtr binpicking = scene->GetOrCreateBinPickingTaskFromName_UTF8("binpickingtask1");
60 
62  boost::shared_ptr<zmq::context_t> zmqcontext(new zmq::context_t(2));
63  binpicking->Initialize("", binpickingTaskZmqPort, binpickingTaskHeartbeatPort, zmqcontext);
64  calib.reset(new HandEyeCalibrationTaskResource(std::string("calibtask1"), controller,scene));
66  binpicking->GetJointValues(jointvaluesresult);
67 
69  calibparam.SetDefaults();
70  calibparam.cameraname = "camera2";
71  calibparam.numsamples = 15;
72  calibparam.distances[0] = 0.6;
73  calibparam.distances[1] = 0.9;
74  calibparam.distances[2] = 0.1;
75  calibparam.transform.translate[0] = -170;
76  calibparam.transform.translate[1] = 0;
77  calibparam.transform.translate[2] = 0;
78  calibparam.transform.quaternion[0] = 0.70710678;
79  calibparam.transform.quaternion[1] = 0;
80  calibparam.transform.quaternion[2] = 0;
81  calibparam.transform.quaternion[3] = -0.70710678;
82 
84  calib->ComputeCalibrationPoses(30, calibparam, result);
85  std::cout << "poses: " << std::endl;
86  for (size_t i = 0; i < result.poses.size(); i++) {
87  for (int j = 0; j < 7; j++) {
88  std::cout << result.poses[i][j] << ", ";
89  }
90  std::cout << std::endl;
91  }
92  std::cout << "configs: " << std::endl;
93  for (size_t i = 0; i < result.configs.size(); i++) {
94  for (size_t j = 0; j < result.configs[i].size(); j++) {
95  std::cout << result.configs[i][j] << ", ";
96  }
97  std::cout << std::endl;
98  }
99  std::cout << "jointindices: " << std::endl;
100  for (size_t i = 0; i < result.jointindices.size(); i++) {
101  std::cout << result.jointindices[i] << ", ";
102  }
103  std::cout << std::endl;
105 }