memory.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 SoftBank Robotics Europe
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 // ROS Headers
00019 #include <ros/ros.h>
00020 
00021 #include "naoqi_dcm_driver/memory.hpp"
00022 #include "naoqi_dcm_driver/tools.hpp"
00023 
00024 Memory::Memory(const qi::SessionPtr& session)
00025 {
00026   try
00027   {
00028     memory_proxy_ = session->service("ALMemory");
00029   }
00030   catch (const std::exception& e)
00031   {
00032     ROS_ERROR("Memory: Failed to connect to Memory Proxy!\n\tTrace: %s", e.what());
00033   }
00034 }
00035 
00036 void Memory::init(const std::vector <std::string> &joints_names)
00037 {
00038   keys_positions_ = initMemoryKeys(joints_names);
00039 }
00040 
00041 std::vector <std::string> Memory::initMemoryKeys(const std::vector <std::string> &joints)
00042 {
00043   std::vector <std::string> keys;
00044   for(std::vector<std::string>::const_iterator it=joints.begin(); it!=joints.end(); ++it)
00045   {
00046     keys.push_back("Device/SubDeviceList/" + *it + "/Position/Sensor/Value");
00047   }
00048   return keys;
00049 }
00050 
00051 std::vector<float> Memory::getListData()
00052 {
00053   return getListData(keys_positions_);
00054 }
00055 
00056 std::vector<float> Memory::getListData(const std::vector <std::string> &keys)
00057 {
00058   qi::AnyValue keys_qi;
00059 
00060   try
00061   {
00062     keys_qi = memory_proxy_.call<qi::AnyValue>("getListData", keys);
00063   }
00064   catch(const std::exception& e)
00065   {
00066     ROS_ERROR("Memory: Could not read joints data from Memory Proxy \n\tTrace: %s", e.what());
00067   }
00068 
00069   std::vector<float> joint_positions = fromAnyValueToFloatVector(keys_qi);
00070   return joint_positions;
00071 }
00072 
00073 std::string Memory::getData(const std::string &str)
00074 {
00075   std::string res;
00076   try
00077   {
00078     res = memory_proxy_.call<std::string>("getData", str);
00079   }
00080   catch (const std::exception& e)
00081   {
00082     ROS_WARN("Memory: Failed to get the robot's name \n\tTrace: %s", e.what());
00083   }
00084   return res;
00085 }
00086 
00087 void Memory::subscribeToMicroEvent(const std::string &name,
00088                                    const std::string &callback_module,
00089                                    const std::string &callback_method,
00090                                    const std::string &callback_message)
00091 {
00092   try
00093   {
00094     memory_proxy_.call<int>("subscribeToMicroEvent", name, callback_module, callback_message, callback_method);
00095   }
00096   catch(const std::exception& e)
00097   {
00098     ROS_WARN("Memory: Failed to subscribe to micro-event '%s'.\n\tTrace: %s", name.c_str(), e.what());
00099   }
00100 }
00101 
00102 void Memory::unsubscribeFromMicroEvent(const std::string &name,
00103                                        const std::string &callback_module)
00104 {
00105   try
00106   {
00107     memory_proxy_.call<void>("unsubscribeToMicroEvent", name, callback_module);
00108   }
00109   catch(const std::exception& e)
00110   {
00111     ROS_WARN("Memory: Failed to unsubscribe from micro-event '%s'.\n\tTrace: %s", name.c_str(), e.what());
00112   }
00113 }


naoqi_dcm_driver
Author(s): Konstantinos Chatzilygeroudis , Mikael Arguedas , Karsten Knese , Natalia Lyubova
autogenerated on Thu Jun 6 2019 20:50:50