nao_node.cpp
Go to the documentation of this file.
00001 #include <boost/program_options.hpp>
00002 #include <alerror/alerror.h>
00003 
00004 #include <ros/ros.h> // for logging macros
00005 
00006 #include <iostream>
00007 
00008 #include "nao_node.h"
00009 
00010 using namespace std;
00011 
00012 NaoNode::NaoNode(int argc, char ** argv) : 
00013     m_pip("nao.local"),
00014     m_ip("0.0.0.0"),
00015     m_port(16712),
00016     m_pport(9559),
00017     m_brokerName("NaoROSBroker")
00018 {
00019     parse_command_line(argc, argv);
00020 }
00021 
00022 NaoNode::~NaoNode()
00023 {}
00024 
00025 void NaoNode::parse_command_line(int argc, char ** argv)
00026 {
00027    string pip;
00028    string ip;
00029    int pport;
00030    int port;
00031    boost::program_options::options_description desc("Configuration");
00032    desc.add_options()
00033       ("help", "show this help message")
00034       ("ip", boost::program_options::value<string>(&ip)->default_value(m_ip),
00035        "IP/hostname of the broker")
00036       ("port", boost::program_options::value<int>(&port)->default_value(m_port),
00037        "Port of the broker")
00038       ("pip", boost::program_options::value<string>(&pip)->default_value(m_pip),
00039        "IP/hostname of parent broker")
00040       ("pport", boost::program_options::value<int>(&pport)->default_value(m_pport),
00041        "port of parent broker")
00042       ;
00043    boost::program_options::variables_map vm;
00044    boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
00045    boost::program_options::notify(vm);
00046    m_port = vm["port"].as<int>();
00047    m_pport = vm["pport"].as<int>();
00048    m_pip = vm["pip"].as<string>();
00049    m_ip = vm["ip"].as<string>();
00050    ROS_DEBUG_STREAM("pip is " << m_pip);
00051    ROS_DEBUG_STREAM("ip is " << m_ip);
00052    ROS_DEBUG_STREAM("port is " << m_port);
00053    ROS_DEBUG_STREAM("pport is " << m_pport);
00054 
00055    if (vm.count("help")) {
00056       cout << desc << "\n";
00057       return ;
00058    }
00059 }
00060 
00061 
00062 
00063 bool NaoNode::connectNaoQi()
00064 {
00065    // Need this to for SOAP serialization of floats to work
00066    setlocale(LC_NUMERIC, "C");
00067    // A broker needs a name, an IP and a port:
00068    // FIXME: would be a good idea to look for a free port first
00069    // listen port of the broker (here an anything)
00070    try
00071    {
00072       m_broker = AL::ALBroker::createBroker(m_brokerName, m_ip, m_port, m_pip, m_pport, false);
00073    }
00074    catch(const AL::ALError& e)
00075    {
00076       ROS_ERROR( "Failed to connect broker to: %s:%d",m_pip.c_str(),m_port);
00077       //AL::ALBrokerManager::getInstance()->killAllBroker();
00078       //AL::ALBrokerManager::kill();
00079       return false;
00080    }
00081    ROS_INFO("NAOqi broker ready.");
00082    return true;
00083 }
00084 


nao_sensors
Author(s): Séverin Lemaignan, Vincent Rabaud, Karsten Knese, Jack O'Quin, Ken Tossell, Patrick Beeson, Nate Koenig, Andrew Howard, Damien Douxchamps, Dan Dennedy, Daniel Maier
autogenerated on Mon Oct 6 2014 02:40:25