controllerclientcpp  0.6.1
 全て クラス ネームスペース ファイル 関数 変数 型定義 列挙型 列挙型の値 マクロ定義 ページ
mujinbinpickingtask.cpp
説明を見る。
2 #include <iostream>
3 
4 using namespace mujinclient;
5 
6 #include <boost/program_options.hpp>
7 
8 int main(int argc, char ** argv)
9 {
10  // parse command line arguments
11  namespace bpo = boost::program_options;
12  bpo::options_description desc("Options");
13 
14  desc.add_options()
15  ("help,h", "produce help message")
16  ("controller_ip", bpo::value<std::string>()->required(), "ip of the mujin controller, e.g. controller3")
17  ("controller_port", bpo::value<unsigned int>()->default_value(80), "port of the mujin controller, e.g. 80")
18  ("controller_username_password", bpo::value<std::string>()->required(), "username and password to the mujin controller, e.g. username:password")
19  ("binpicking_task_zmq_port", bpo::value<unsigned int>()->required(), "port of the binpicking task on the mujin controller, e.g. 7100")
20  ("binpicking_task_heartbeat_port", bpo::value<unsigned int>()->required(), "port of the binpicking task's heartbeat signal on the mujin controller, e.g. 7101")
21  ("binpicking_task_scenepk", bpo::value<std::string>()->required(), "scene pk of the binpicking task on the mujin controller, e.g. irex2013.mujin.dae")
22  ("robotname", bpo::value<std::string>()->required(), "robot name, e.g. VP-5243I")
23  ("testobjectname", bpo::value<std::string>()->required(), "test object name in the scene, e.g. floor")
24  ;
25 
26  bpo::variables_map opts;
27  bpo::store(bpo::parse_command_line(argc, argv, desc), opts);
28  bool badargs = false;
29  try {
30  bpo::notify(opts);
31  }
32  catch(...) {
33  badargs = true;
34  }
35  if(opts.count("help") || badargs) {
36  std::cout << "Usage: " << argv[0] << " [OPTS]" << std::endl;
37  std::cout << std::endl;
38  std::cout << desc << std::endl;
39  return (1);
40  }
41 
42  const std::string controllerIp = opts["controller_ip"].as<std::string>();
43  const unsigned int controllerPort = opts["controller_port"].as<unsigned int>();
44  const std::string controllerUsernamePass = opts["controller_username_password"].as<std::string>();
45  const unsigned int binpickingTaskZmqPort = opts["binpicking_task_zmq_port"].as<unsigned int>();
46  const unsigned int binpickingTaskHeartbeatPort = opts["binpicking_task_heartbeat_port"].as<unsigned int>();
47  const std::string binpickingTaskScenePk = opts["binpicking_task_scenepk"].as<std::string>();
48  const std::string robotname = opts["robotname"].as<std::string>();
49  const std::string testobjectname = opts["testobjectname"].as<std::string>();
50 
51  // connect to mujin controller
52  std::stringstream url_ss;
53  url_ss << "http://"<< controllerIp << ":" << controllerPort;
54  ControllerClientPtr controller = CreateControllerClient(controllerUsernamePass, url_ss.str());
55  SceneResourcePtr scene(new SceneResource(controller, binpickingTaskScenePk));
56  BinPickingTaskResourcePtr binpickingzmq = scene->GetOrCreateBinPickingTaskFromName_UTF8("binpickingtask1", "binpicking", TRO_EnableZMQ);
57  boost::shared_ptr<zmq::context_t> zmqcontext(new zmq::context_t(2));
58  binpickingzmq->Initialize("", binpickingTaskZmqPort, binpickingTaskHeartbeatPort, zmqcontext);
59 
60  Transform t;
61  binpickingzmq->GetTransform(testobjectname,t);
62  std::cout << "testobject " << testobjectname << " pose: [" << t.quaternion[0] << ", " << t.quaternion[1] << ", " << t.quaternion[2] << ", " << t.quaternion[3] << ", " << t.translate[0] << ", " << t.translate[1] << ", " << t.translate[2] << "]";
63 }