memory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016 SoftBank Robotics Europe
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 // ROS Headers
19 #include <ros/ros.h>
20 
23 
24 Memory::Memory(const qi::SessionPtr& session)
25 {
26  try
27  {
28  memory_proxy_ = session->service("ALMemory");
29  }
30  catch (const std::exception& e)
31  {
32  ROS_ERROR("Memory: Failed to connect to Memory Proxy!\n\tTrace: %s", e.what());
33  }
34 }
35 
36 void Memory::init(const std::vector <std::string> &joints_names)
37 {
38  keys_positions_ = initMemoryKeys(joints_names);
39 }
40 
41 std::vector <std::string> Memory::initMemoryKeys(const std::vector <std::string> &joints)
42 {
43  std::vector <std::string> keys;
44  for(std::vector<std::string>::const_iterator it=joints.begin(); it!=joints.end(); ++it)
45  {
46  keys.push_back("Device/SubDeviceList/" + *it + "/Position/Sensor/Value");
47  }
48  return keys;
49 }
50 
51 std::vector<float> Memory::getListData()
52 {
54 }
55 
56 std::vector<float> Memory::getListData(const std::vector <std::string> &keys)
57 {
58  qi::AnyValue keys_qi;
59 
60  try
61  {
62  keys_qi = memory_proxy_.call<qi::AnyValue>("getListData", keys);
63  }
64  catch(const std::exception& e)
65  {
66  ROS_ERROR("Memory: Could not read joints data from Memory Proxy \n\tTrace: %s", e.what());
67  }
68 
69  std::vector<float> joint_positions = fromAnyValueToFloatVector(keys_qi);
70  return joint_positions;
71 }
72 
73 std::string Memory::getData(const std::string &str)
74 {
75  std::string res;
76  try
77  {
78  res = memory_proxy_.call<std::string>("getData", str);
79  }
80  catch (const std::exception& e)
81  {
82  ROS_WARN("Memory: Failed to get the robot's name \n\tTrace: %s", e.what());
83  }
84  return res;
85 }
86 
87 void Memory::subscribeToMicroEvent(const std::string &name,
88  const std::string &callback_module,
89  const std::string &callback_method,
90  const std::string &callback_message)
91 {
92  try
93  {
94  memory_proxy_.call<int>("subscribeToMicroEvent", name, callback_module, callback_message, callback_method);
95  }
96  catch(const std::exception& e)
97  {
98  ROS_WARN("Memory: Failed to subscribe to micro-event '%s'.\n\tTrace: %s", name.c_str(), e.what());
99  }
100 }
101 
102 void Memory::unsubscribeFromMicroEvent(const std::string &name,
103  const std::string &callback_module)
104 {
105  try
106  {
107  memory_proxy_.call<void>("unsubscribeToMicroEvent", name, callback_module);
108  }
109  catch(const std::exception& e)
110  {
111  ROS_WARN("Memory: Failed to unsubscribe from micro-event '%s'.\n\tTrace: %s", name.c_str(), e.what());
112  }
113 }
qi::AnyObject memory_proxy_
Definition: memory.hpp:59
void unsubscribeFromMicroEvent(const std::string &name, const std::string &callback_module)
unsubscribe from a micro-event
Definition: memory.cpp:102
#define ROS_WARN(...)
std::vector< float > getListData()
Get values of keys.
Definition: memory.cpp:51
std::string getData(const std::string &str)
get a key-value pair stored in memory
Definition: memory.cpp:73
void subscribeToMicroEvent(const std::string &name, const std::string &callback_module, const std::string &callback_method, const std::string &callback_message)
subscribe to a micro-event
Definition: memory.cpp:87
std::vector< std::string > initMemoryKeys(const std::vector< std::string > &joints)
initialize memory keys to read
Definition: memory.cpp:41
std::vector< float > fromAnyValueToFloatVector(qi::AnyValue &value)
Definition: tools.cpp:70
void init(const std::vector< std::string > &joints_names)
initialize with joints names to control
Definition: memory.cpp:36
std::vector< std::string > keys_positions_
Definition: memory.hpp:62
#define ROS_ERROR(...)
Memory(const qi::SessionPtr &session)
Definition: memory.cpp:24


naoqi_dcm_driver
Author(s): Konstantinos Chatzilygeroudis , Mikael Arguedas , Karsten Knese , Natalia Lyubova
autogenerated on Thu Jul 25 2019 03:49:27