driver_helpers.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2015 Aldebaran
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 
00018 #include "driver_helpers.hpp"
00019 
00020 namespace naoqi
00021 {
00022 namespace helpers
00023 {
00024 namespace driver
00025 {
00026 
00029 static naoqi_bridge_msgs::RobotInfo& getRobotInfoLocal( const qi::SessionPtr& session)
00030 {
00031   static naoqi_bridge_msgs::RobotInfo info;
00032   static qi::Url robot_url;
00033 
00034   if (robot_url == session->url())
00035   {
00036     return info;
00037   }
00038 
00039   robot_url = session->url();
00040 
00041   // Get the robot type
00042   std::cout << "Receiving information about robot model" << std::endl;
00043   qi::AnyObject p_memory = session->service("ALMemory");
00044   std::string robot = p_memory.call<std::string>("getData", "RobotConfig/Body/Type" );
00045   std::transform(robot.begin(), robot.end(), robot.begin(), ::tolower);
00046 
00047   if (std::string(robot) == "nao")
00048   {
00049     info.type = naoqi_bridge_msgs::RobotInfo::NAO;
00050   }
00051   if (std::string(robot) == "pepper" || std::string(robot) == "juliette" )
00052   {
00053     info.type = naoqi_bridge_msgs::RobotInfo::PEPPER;
00054   }
00055   if (std::string(robot) == "romeo" )
00056   {
00057     info.type = naoqi_bridge_msgs::RobotInfo::ROMEO;
00058   }
00059 
00060   // Get the data from RobotConfig
00061   qi::AnyObject p_motion = session->service("ALMotion");
00062   std::vector<std::vector<qi::AnyValue> > config = p_motion.call<std::vector<std::vector<qi::AnyValue> > >("getRobotConfig");
00063 
00064   // TODO, fill with the proper string matches from http://doc.aldebaran.com/2-1/naoqi/motion/tools-general-api.html#ALMotionProxy::getRobotConfig
00065 
00066   for (size_t i=0; i<config[0].size();++i)
00067   {
00068     if (config[0][i].as<std::string>() == "Model Type")
00069     {
00070       try{
00071         info.model = config[1][i].as<std::string>();
00072       }
00073       catch(const std::exception& e)
00074       {
00075         std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00076       }
00077     }
00078 
00079     if (config[0][i].as<std::string>() == "Head Version")
00080     {
00081       try{
00082         info.head_version = config[1][i].as<std::string>();
00083       }
00084       catch(const std::exception& e)
00085       {
00086         std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00087       }
00088     }
00089 
00090     if (config[0][i].as<std::string>() == "Body Version")
00091     {
00092       try{
00093         info.body_version = config[1][i].as<std::string>();
00094       }
00095       catch(const std::exception& e)
00096       {
00097         std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00098       }
00099     }
00100 
00101     if (config[0][i].as<std::string>() == "Arm Version")
00102     {
00103       try{
00104         info.arm_version = config[1][i].as<std::string>();
00105       }
00106       catch(const std::exception& e)
00107       {
00108         std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00109       }
00110     }
00111 
00112     if (config[0][i].as<std::string>() == "Laser")
00113     {
00114       try{
00115         info.has_laser = config[1][i].as<bool>();
00116       }
00117       catch(const std::exception& e)
00118       {
00119         std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00120       }
00121     }
00122 
00123     if (config[0][i].as<std::string>() == "Extended Arms")
00124     {
00125       try{
00126         info.has_extended_arms = config[1][i].as<bool>();
00127       }
00128       catch(const std::exception& e)
00129       {
00130         std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00131       }
00132     }
00133 
00134     if (config[0][i].as<std::string>() == "Number of Legs")
00135     {
00136       try{
00137         info.number_of_legs = config[1][i].as<int>();
00138       }
00139       catch(const std::exception& e)
00140       {
00141         std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00142       }
00143     }
00144 
00145     if (config[0][i].as<std::string>() == "Number of Arms")
00146     {
00147       try{
00148         info.number_of_arms = config[1][i].as<int>();
00149       }
00150       catch(const std::exception& e)
00151       {
00152         std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00153       }
00154     }
00155 
00156     if (config[0][i].as<std::string>() == "Number of Hands")
00157     {
00158       try{
00159         info.number_of_hands = config[1][i].as<int>();
00160       }
00161       catch(const std::exception& e)
00162       {
00163         std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00164       }
00165     }
00166 
00167   }
00168   return info;
00169 }
00170 
00171 const robot::Robot& getRobot( const qi::SessionPtr& session )
00172 {
00173   static robot::Robot robot = robot::UNIDENTIFIED;
00174 
00175   if ( getRobotInfo(session).type == naoqi_bridge_msgs::RobotInfo::NAO )
00176   {
00177     robot = robot::NAO;
00178   }
00179   if ( getRobotInfo(session).type == naoqi_bridge_msgs::RobotInfo::PEPPER )
00180   {
00181     robot = robot::PEPPER;
00182   }
00183   if ( getRobotInfo(session).type == naoqi_bridge_msgs::RobotInfo::ROMEO )
00184   {
00185     robot = robot::ROMEO;
00186   }
00187 
00188   return robot;
00189 }
00190 
00191 const naoqi_bridge_msgs::RobotInfo& getRobotInfo( const qi::SessionPtr& session )
00192 {
00193   static naoqi_bridge_msgs::RobotInfo robot_info =  getRobotInfoLocal(session);
00194   return robot_info;
00195 }
00196 
00197 } // driver
00198 } // helpers
00199 } // naoqi


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sun Sep 17 2017 02:57:14