19 #include <qi/application.hpp> 23 static std::string
getROSIP(std::string network_interface)
25 if (network_interface.empty())
26 network_interface =
"eth0";
28 typedef std::map< std::string, std::vector<std::string> > Map_IP;
29 Map_IP map_ip =
static_cast<Map_IP
>(qi::os::hostIPAddrs());
30 if ( map_ip.find(network_interface) == map_ip.end() ) {
31 std::cerr <<
"Could not find network interface named " << network_interface <<
", possible interfaces are ... ";
32 for (Map_IP::iterator it=map_ip.begin(); it!=map_ip.end(); ++it) std::cerr << it->first <<
" ";
33 std::cerr << std::endl;
37 static const std::string ip = map_ip[network_interface][0];
41 static void setMasterURINet(
const std::string& uri,
const std::string& network_interface )
43 setenv(
"ROS_MASTER_URI", uri.c_str(), 1);
45 std::string my_master =
"__master="+uri;
46 std::map< std::string, std::string >
remap;
47 remap[
"__master"] = uri;
48 remap[
"__ip"] =
getROSIP(network_interface);
50 const char* ns_env = std::getenv(
"ROS_NAMESPACE");
55 int main(
int argc,
char** argv)
58 setlocale(LC_NUMERIC,
"C");
61 qi::Application
app(argc, argv);
63 ros::init(argc, argv,
"naoqi_dcm_driver");
68 ROS_ERROR(
"Could not contact master!\nQuitting... ");
74 std::string pip =
"127.0.0.1";
75 std::string roscore_ip =
"127.0.0.1";
76 std::string network_interface =
"eth0";
79 nh.
getParam(
"DriverBrokerIP", roscore_ip);
80 nh.
getParam(
"network_interface", network_interface);
84 qi::SessionPtr session = qi::makeSession();
87 std::stringstream strstr;
88 strstr <<
"tcp://" << pip <<
":" << pport;
90 session->connect(strstr.str()).
wait();
92 catch(
const std::exception &e)
94 ROS_ERROR(
"Cannot connect to session, %s", e.what());
99 if (!session->connected)
112 qi::AnyObject touch_proxy = session->service(
"ALTouch");
113 touch_proxy.call<
void>(
"exit");
116 catch (
const std::exception& e)
118 ROS_DEBUG(
"Did not stop ALTouch: %s", e.what());
124 qi::AnyObject life_proxy = session->service(
"ALAutonomousLife");
125 if (life_proxy.call<std::string>(
"getState") !=
"disabled")
127 life_proxy.call<
void>(
"setState",
"disabled");
132 catch (
const std::exception& e)
134 ROS_DEBUG(
"Did not stop AutonomousLife: %s", e.what());
137 session->registerService(
"naoqi_dcm_driver", robot);
140 if (!robot->connect())
154 robot->stopService();
static std::string getROSIP(std::string network_interface)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
ROSCPP_DECL std::string remap(const std::string &name)
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
static void setMasterURINet(const std::string &uri, const std::string &network_interface)