Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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::string version = p_memory.call<std::string>("getData", "RobotConfig/Body/BaseVersion" );
00046 std::transform(robot.begin(), robot.end(), robot.begin(), ::tolower);
00047
00048 if (std::string(robot) == "nao")
00049 {
00050 info.type = naoqi_bridge_msgs::RobotInfo::NAO;
00051 std::cout << BOLDYELLOW << "Robot detected: "
00052 << BOLDCYAN << "NAO " << version
00053 << RESETCOLOR << std::endl;
00054 }
00055 if (std::string(robot) == "pepper" || std::string(robot) == "juliette" )
00056 {
00057 info.type = naoqi_bridge_msgs::RobotInfo::PEPPER;
00058 std::cout << BOLDYELLOW << "Robot detected: "
00059 << BOLDCYAN << "Pepper " << version
00060 << RESETCOLOR << std::endl;
00061 }
00062 if (std::string(robot) == "romeo" )
00063 {
00064 info.type = naoqi_bridge_msgs::RobotInfo::ROMEO;
00065 std::cout << BOLDYELLOW << "Robot detected: "
00066 << BOLDCYAN << "Romeo " << version
00067 << RESETCOLOR << std::endl;
00068 }
00069
00070
00071 qi::AnyObject p_motion = session->service("ALMotion");
00072 std::vector<std::vector<qi::AnyValue> > config = p_motion.call<std::vector<std::vector<qi::AnyValue> > >("getRobotConfig");
00073
00074
00075
00076 for (size_t i=0; i<config[0].size();++i)
00077 {
00078 if (config[0][i].as<std::string>() == "Model Type")
00079 {
00080 try{
00081 info.model = config[1][i].as<std::string>();
00082 }
00083 catch(const std::exception& e)
00084 {
00085 std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00086 }
00087 }
00088
00089 if (config[0][i].as<std::string>() == "Head Version")
00090 {
00091 try{
00092 info.head_version = config[1][i].as<std::string>();
00093 }
00094 catch(const std::exception& e)
00095 {
00096 std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00097 }
00098 }
00099
00100 if (config[0][i].as<std::string>() == "Body Version")
00101 {
00102 try{
00103 info.body_version = config[1][i].as<std::string>();
00104 }
00105 catch(const std::exception& e)
00106 {
00107 std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00108 }
00109 }
00110
00111 if (config[0][i].as<std::string>() == "Arm Version")
00112 {
00113 try{
00114 info.arm_version = config[1][i].as<std::string>();
00115 }
00116 catch(const std::exception& e)
00117 {
00118 std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00119 }
00120 }
00121
00122 if (config[0][i].as<std::string>() == "Laser")
00123 {
00124 try{
00125 info.has_laser = config[1][i].as<bool>();
00126 }
00127 catch(const std::exception& e)
00128 {
00129 std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00130 }
00131 }
00132
00133 if (config[0][i].as<std::string>() == "Extended Arms")
00134 {
00135 try{
00136 info.has_extended_arms = config[1][i].as<bool>();
00137 }
00138 catch(const std::exception& e)
00139 {
00140 std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00141 }
00142 }
00143
00144 if (config[0][i].as<std::string>() == "Number of Legs")
00145 {
00146 try{
00147 info.number_of_legs = config[1][i].as<int>();
00148 }
00149 catch(const std::exception& e)
00150 {
00151 std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00152 }
00153 }
00154
00155 if (config[0][i].as<std::string>() == "Number of Arms")
00156 {
00157 try{
00158 info.number_of_arms = config[1][i].as<int>();
00159 }
00160 catch(const std::exception& e)
00161 {
00162 std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00163 }
00164 }
00165
00166 if (config[0][i].as<std::string>() == "Number of Hands")
00167 {
00168 try{
00169 info.number_of_hands = config[1][i].as<int>();
00170 }
00171 catch(const std::exception& e)
00172 {
00173 std::cout << "Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
00174 }
00175 }
00176
00177 }
00178 return info;
00179 }
00180
00181 const robot::Robot& getRobot( const qi::SessionPtr& session )
00182 {
00183 static robot::Robot robot = robot::UNIDENTIFIED;
00184
00185 if ( getRobotInfo(session).type == naoqi_bridge_msgs::RobotInfo::NAO )
00186 {
00187 robot = robot::NAO;
00188 }
00189 if ( getRobotInfo(session).type == naoqi_bridge_msgs::RobotInfo::PEPPER )
00190 {
00191 robot = robot::PEPPER;
00192 }
00193 if ( getRobotInfo(session).type == naoqi_bridge_msgs::RobotInfo::ROMEO )
00194 {
00195 robot = robot::ROMEO;
00196 }
00197
00198 return robot;
00199 }
00200
00201 const naoqi_bridge_msgs::RobotInfo& getRobotInfo( const qi::SessionPtr& session )
00202 {
00203 static naoqi_bridge_msgs::RobotInfo robot_info = getRobotInfoLocal(session);
00204 return robot_info;
00205 }
00206
00209 bool& setLanguage( const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRequest req)
00210 {
00211 static bool success;
00212 std::cout << "Receiving service call of setting speech language" << std::endl;
00213 try{
00214 qi::AnyObject p_text_to_speech = session->service("ALTextToSpeech");
00215 p_text_to_speech.call<void>("setLanguage", req.data);
00216 success = true;
00217 return success;
00218 }
00219 catch(const std::exception& e){
00220 success = false;
00221 return success;
00222 }
00223 }
00224
00227 std::string& getLanguage( const qi::SessionPtr& session )
00228 {
00229 static std::string language;
00230 std::cout << "Receiving service call of getting speech language" << std::endl;
00231 qi::AnyObject p_text_to_speech = session->service("ALTextToSpeech");
00232 language = p_text_to_speech.call<std::string>("getLanguage");
00233 return language;
00234 }
00235
00239 bool isDepthStereo(const qi::SessionPtr &session) {
00240 std::vector<std::string> sensor_names;
00241
00242 try {
00243 qi::AnyObject p_motion = session->service("ALMotion");
00244 sensor_names = p_motion.call<std::vector<std::string> >("getSensorNames");
00245
00246 if (std::find(sensor_names.begin(),
00247 sensor_names.end(),
00248 "CameraStereo") != sensor_names.end()) {
00249 return true;
00250 }
00251
00252 else {
00253 return false;
00254 }
00255
00256 } catch (const std::exception &e) {
00257 std::cerr << e.what() << std::endl;
00258 return false;
00259 }
00260 }
00261
00262 }
00263 }
00264 }