external_registration.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Aldebaran
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 
19 #include <qi/applicationsession.hpp>
20 #include <qi/anymodule.hpp>
22 
23 #include <boost/program_options.hpp>
24 
25 #include "naoqi_env.hpp"
27 
28 int main(int argc, char** argv)
29 {
30  /* launch naoqi service */
31  qi::ApplicationSession app(argc, argv);
32  /* In case you launch via roslaunch/rosrun we remove the ros args */
33  std::vector<std::string> args_out;
34  ros::removeROSArgs( argc, argv, args_out );
35 
36  namespace po = boost::program_options;
37  po::options_description desc("Options");
38  desc.add_options()
39  ("help,h", "print help message")
40  ("roscore_ip,r", po::value<std::string>(), "set the ip of the roscore to use")
41  ("network_interface,i", po::value<std::string>()->default_value("eth0"), "set the network interface over which to connect")
42  ("namespace,n", po::value<std::string>()->default_value("naoqi_driver_node"), "set an explicit namespace in case ROS namespace variables cannot be used");
43 
44  po::variables_map vm;
45  try
46  {
47  po::store( po::parse_command_line(argc, argv, desc), vm );
48  }
49  catch (boost::program_options::invalid_command_line_syntax& e)
50  {
51  std::cout << "error " << e.what() << std::endl;
52  throw ros::Exception(e.what());
53  }
54  catch (boost::program_options::unknown_option& e)
55  {
56  std::cout << "error 2 " << e.what() << std::endl;
57  throw ros::Exception(e.what());
58  }
59 
60  if( vm.count("help") )
61  {
62  std::cout << "This is the help message for the ROS-Driver C++ bridge" << std::endl << desc << std::endl;
63  exit(0);
64  }
65 
66 
67  // everything's correctly parsed - let's start the app!
68 #if LIBQI_VERSION>24
69  app.startSession();
70 #else
71  app.start();
72 #endif
73  boost::shared_ptr<naoqi::Driver> bs = boost::make_shared<naoqi::Driver>(app.session(), vm["namespace"].as<std::string>());
74 
75  app.session()->registerService("ROS-Driver", bs);
76 
77  // set ros paramters directly upfront if available
78  if ( vm.count("roscore_ip") )
79  {
80  std::string roscore_ip = vm["roscore_ip"].as<std::string>();
81  std::string network_interface = vm["network_interface"].as<std::string>();
82 
83  std::cout << BOLDYELLOW << "using ip address: "
84  << BOLDCYAN << roscore_ip << " @ " << network_interface << RESETCOLOR << std::endl;
85  bs->init();
86  bs->setMasterURINet( "http://"+roscore_ip+":11311", network_interface);
87  }
88  else
89  {
90  std::cout << BOLDRED << "No ip address given. Run qicli call to set the master uri" << RESETCOLOR << std::endl;
91  bs->init();
92  }
93 
94  std::cout << BOLDYELLOW << "naoqi_driver initialized" << RESETCOLOR << std::endl;
95  app.run();
96  bs->stopService();
97  app.session()->close();
98  return 0;
99 }
app
#define BOLDRED
Definition: tools.hpp:25
#define RESETCOLOR
Definition: tools.hpp:22
int main(int argc, char **argv)
#define BOLDCYAN
Definition: tools.hpp:28
#define BOLDYELLOW
Definition: tools.hpp:27
ROSCPP_DECL void removeROSArgs(int argc, const char *const *argv, V_string &args_out)


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 15 2020 03:24:26