19 #include <boost/property_tree/ptree.hpp> 20 #include <boost/property_tree/xml_parser.hpp> 28 namespace pt = boost::property_tree;
36 static naoqi_bridge_msgs::RobotInfo info;
37 static qi::Url robot_url;
39 if (robot_url == session->url())
44 robot_url = session->url();
47 std::cout <<
"Receiving information about robot model" << std::endl;
48 qi::AnyObject p_memory = session->service(
"ALMemory").value();
49 std::string robot = p_memory.call<std::string>(
"getData",
"RobotConfig/Body/Type" );
50 std::string hardware_version = p_memory.call<std::string>(
"getData",
"RobotConfig/Body/BaseVersion" );
52 std::transform(robot.begin(), robot.end(), robot.begin(), ::tolower);
56 if (std::string(robot) ==
"nao")
61 if (std::string(robot) ==
"pepper" || std::string(robot) ==
"juliette" )
66 if (std::string(robot) ==
"romeo" )
72 std::cout <<
BOLDCYAN <<
" / " << naoqi_version.text << RESETCOLOR << std::endl;
75 qi::AnyObject p_motion = session->service(
"ALMotion").value();
78 std::vector<std::vector<qi::AnyValue>> config = p_motion.call<std::vector<std::vector<qi::AnyValue>>>(
"getRobotConfig");
82 for (
size_t i = 0; i < config[0].size(); ++i)
84 if (config[0][i].as<std::string>() ==
"Model Type")
88 info.model = config[1][i].as<std::string>();
90 catch (
const std::exception &e)
92 std::cout <<
"Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
96 if (config[0][i].as<std::string>() ==
"Head Version")
100 info.head_version = config[1][i].as<std::string>();
102 catch (
const std::exception &e)
104 std::cout <<
"Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
108 if (config[0][i].as<std::string>() ==
"Body Version")
112 info.body_version = config[1][i].as<std::string>();
114 catch (
const std::exception &e)
116 std::cout <<
"Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
120 if (config[0][i].as<std::string>() ==
"Arm Version")
124 info.arm_version = config[1][i].as<std::string>();
126 catch (
const std::exception &e)
128 std::cout <<
"Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
132 if (config[0][i].as<std::string>() ==
"Laser")
136 info.has_laser = config[1][i].as<
bool>();
138 catch (
const std::exception &e)
140 std::cout <<
"Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
144 if (config[0][i].as<std::string>() ==
"Extended Arms")
148 info.has_extended_arms = config[1][i].as<
bool>();
150 catch (
const std::exception &e)
152 std::cout <<
"Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
156 if (config[0][i].as<std::string>() ==
"Number of Legs")
160 info.number_of_legs = config[1][i].as<
int>();
162 catch (
const std::exception &e)
164 std::cout <<
"Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
168 if (config[0][i].as<std::string>() ==
"Number of Arms")
172 info.number_of_arms = config[1][i].as<
int>();
174 catch (
const std::exception &e)
176 std::cout <<
"Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
180 if (config[0][i].as<std::string>() ==
"Number of Hands")
184 info.number_of_hands = config[1][i].as<
int>();
186 catch (
const std::exception &e)
188 std::cout <<
"Error in robot config variable " << (config[0][i]).as<std::string>() << std::endl;
196 std::cout <<
"ALMotion.getRobotConfig failed (" <<
"), trying with newer service ALRobotModel" << std::endl;
197 auto p_robot_model = session->service(
"ALRobotModel").value();
201 info.model = p_robot_model.call<std::string>(
"getRobotType");
203 catch (
const std::exception &e)
205 std::cout <<
"Error getting robot type (with ALRobotModel.getRobotType): " << e.what() << std::endl;
210 info.number_of_legs = p_robot_model.call<
bool>(
"hasLegs") ? 1 : 0;
212 catch (
const std::exception &e)
214 std::cout <<
"Error getting robot type (with ALRobotModel.getRobotType): " << e.what() << std::endl;
219 std::istringstream config_data(p_robot_model.call<std::string>(
"getConfig"));
221 pt::read_xml(config_data, tree);
223 auto preferences = tree.get_child(
"ModulePreference");
224 for (
const auto& pref: preferences) {
225 if (pref.first !=
"Preference")
227 const pt::ptree& attributes = pref.second.get_child(
"<xmlattr>", empty_ptree);
229 const auto& memory_key = attributes.get<std::string>(
"memoryName");
230 if (memory_key ==
"RobotConfig/Head/Version") {
231 info.head_version = attributes.get<std::string>(
"value");
232 }
else if (memory_key ==
"RobotConfig/Body/Version") {
233 info.body_version = attributes.get<std::string>(
"value");
234 }
else if (memory_key ==
"RobotConfig/Body/Device/LeftArm/Version") {
235 info.arm_version = attributes.get<std::string>(
"value");
239 catch (
const std::exception &e)
241 std::cout <<
"Error getting head version (with ALRobotModel.getConfig): " << e.what() << std::endl;
245 info.has_laser =
false;
246 info.has_extended_arms =
false;
247 info.number_of_arms = 2;
248 info.number_of_hands = 2;
285 qi::AnyObject p_system = session->service(
"ALSystem").value();
286 naoqi_version.
text = p_system.call<std::string>(
"systemVersion");
288 }
catch (
const std::exception& e) {
289 std::cerr <<
"Could not retrieve the version of NAOqi: " 293 naoqi_version.
text =
"unknown";
294 return naoqi_version;
297 std::string buff(
"");
298 std::vector<int> version_numbers;
300 for (std::string::size_type i = 0; i < naoqi_version.
text.size(); ++i)
302 if (naoqi_version.
text[i] !=
'.')
304 buff += naoqi_version.
text[i];
306 else if (naoqi_version.
text[i] ==
'.' && buff !=
"")
308 version_numbers.push_back(std::atoi(buff.c_str()));
315 version_numbers.push_back(std::atoi(buff.c_str()));
318 if (version_numbers.size() != 4)
320 std::cerr <<
"Unconsistent version number for NAOqi, should contain 4 " 322 << naoqi_version.
text 325 return naoqi_version;
328 naoqi_version.
major = version_numbers[0];
329 naoqi_version.
minor = version_numbers[1];
330 naoqi_version.
patch = version_numbers[2];
331 naoqi_version.
build = version_numbers[3];
332 return naoqi_version;
335 const naoqi_bridge_msgs::RobotInfo&
getRobotInfo(
const qi::SessionPtr& session )
343 bool&
setLanguage(
const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRequest req)
346 std::cout <<
"Receiving service call of setting speech language" << std::endl;
348 qi::AnyObject p_text_to_speech = session->service(
"ALTextToSpeech").value();
349 p_text_to_speech.call<
void>(
"setLanguage", req.data);
353 catch(
const std::exception& e){
363 static std::string language;
364 std::cout <<
"Receiving service call of getting speech language" << std::endl;
365 qi::AnyObject p_text_to_speech = session->service(
"ALTextToSpeech").value();
366 language = p_text_to_speech.call<std::string>(
"getLanguage");
374 std::vector<std::string> sensor_names;
377 qi::AnyObject p_motion = session->service(
"ALMotion").value();
378 sensor_names = p_motion.call<std::vector<std::string> >(
"getSensorNames");
380 if (std::find(sensor_names.begin(),
382 "CameraStereo") != sensor_names.end()) {
390 }
catch (
const std::exception &e) {
391 std::cerr << e.what() << std::endl;
415 if (naoqi_version.
major < major)
419 else if (naoqi_version.
minor < minor)
423 else if (naoqi_version.
patch < patch)
427 else if (naoqi_version.
build < build)
const naoqi_bridge_msgs::RobotInfo & getRobotInfo(const qi::SessionPtr &session)
const robot::NaoqiVersion & getNaoqiVersion(const qi::SessionPtr &session)
Function that retrieves the NAOqi version of the robot.
static naoqi_bridge_msgs::RobotInfo & getRobotInfoLocal(const qi::SessionPtr &session)
static pt::ptree empty_ptree
bool isDepthStereo(const qi::SessionPtr &session)
std::string & getLanguage(const qi::SessionPtr &session)
bool & setLanguage(const qi::SessionPtr &session, naoqi_bridge_msgs::SetStringRequest req)
const robot::Robot & getRobot(const qi::SessionPtr &session)
bool isNaoqiVersionLesser(const robot::NaoqiVersion &naoqi_version, const int &major, const int &minor, const int &patch, const int &build)
Function that returns true if the provided naoqi_version is (strictly) lesser than the specified one ...