15 #include <yarp/os/Log.h>
16 #include <yarp/os/LogStream.h>
17 #include <yarp/os/LogComponent.h>
21 YARP_LOG_COMPONENT(FAKERAWVALUESPUBLISHER,
"iCub.debugLibrary.fakeRawvaluespublisher")
29 yCError(FAKERAWVALUESPUBLISHER) << txt <<
"has not yet been emplemented";
35 yCError(FAKERAWVALUESPUBLISHER) << txt <<
"has been deprecated";
39 #undef DEBUG_RAW_VALUES_MACRO
45 m_sawtoothThreshold = 128;
46 m_sawthootTestVal = 0;
47 m_rawValuesVectorTag =
"rawJomoEncoderValues";
48 m_rawDataAuxVector = {};
49 m_rawValuesMetadataMap = {};
54 for (
auto it = m_rawValuesMetadataMap.begin(); it != m_rawValuesMetadataMap.end(); it++)
56 if(!getRawData_core(it->first, m_rawDataAuxVector))
58 yCError(FAKERAWVALUESPUBLISHER) <<
"getRawData_core() failed. Cannot retrieve all data from local memory";
61 map.insert({it->first, m_rawDataAuxVector});
66 bool FakeRawValuesPublisher::getRawData_core(std::string key, std::vector<std::int32_t> &
data)
71 m_sawthootTestVal = (m_sawthootTestVal < m_sawtoothThreshold) ? (++m_sawthootTestVal) : 0;
72 for (uint8_t i = 0; i < m_rawValuesMetadataMap[key].size; i++)
74 data.push_back(m_sawthootTestVal);
81 if (m_rawValuesMetadataMap.find(key) != m_rawValuesMetadataMap.end())
83 getRawData_core(key,
data);
87 yCError(FAKERAWVALUESPUBLISHER) <<
"Request key:" << key <<
"is not available. Cannot retrieve get raw data.";
97 for (
const auto &
p : m_rawValuesMetadataMap)
99 keys.push_back(
p.first);
107 return m_rawValuesMetadataMap.size();
114 #ifdef DEBUG_RAW_VALUES_MACRO
115 for (
auto [k, v] : m_rawValuesMetadataMap)
117 yCDebug(FAKERAWVALUESPUBLISHER) <<
"size of elements name at key:" << k <<
"is:" << v.rawValueNames.size();
118 for (
size_t e = 0;
e < v.rawValueNames.size();
e++)
120 yCDebug(FAKERAWVALUESPUBLISHER) <<
"GOT to rawValueNames:" << v.rawValueNames[
e];
126 if (m_rawValuesMetadataMap.empty())
128 yCError(FAKERAWVALUESPUBLISHER) <<
"embObjMotionControl Map is empty. No reason to proceed...";
137 if(m_rawValuesMetadataMap.find(key) != m_rawValuesMetadataMap.end())
139 meta = m_rawValuesMetadataMap[key];
143 yCError(FAKERAWVALUESPUBLISHER) <<
"Requested key" << key <<
"is not available in the map. Exiting";
149 bool FakeRawValuesPublisher::open(yarp::os::Searchable& config)
151 if (!parseParams(config))
153 yCError(FAKERAWVALUESPUBLISHER) <<
"Failed to parse parameters from configuration";
157 m_numberOfJomos = m_njomos;
159 m_sawtoothThreshold = m_threshold;
162 m_rawValuesMetadataMap.insert({m_rawValuesVectorTag,
rawValuesKeyMetadata({}, m_numberOfJomos)});
163 for (
int i = 0; i < m_numberOfJomos; i++)
165 m_rawValuesMetadataMap[m_rawValuesVectorTag].rawValueNames.push_back(
"fake_jomo_"+std::to_string(i));
168 m_rawDataAuxVector.resize(m_numberOfJomos);
172 bool FakeRawValuesPublisher::close()
174 yCInfo(FAKERAWVALUESPUBLISHER) <<
"Closing the device.";
static bool NOT_YET_IMPLEMENTED(const char *txt)
static bool DEPRECATED(const char *txt)
virtual bool getKeys(std::vector< std::string > &keys) override
virtual bool getRawData(std::string key, std::vector< std::int32_t > &data) override
virtual bool getKeyMetadata(std::string key, rawValuesKeyMetadata &meta) override
virtual bool getRawDataMap(std::map< std::string, std::vector< std::int32_t >> &map) override
virtual int getNumberOfKeys() override
virtual bool getMetadataMap(rawValuesKeyMetadataMap &metamap) override
yarp::sig::Vector & map(yarp::sig::Vector &v, double(op)(double))
Performs a unary operator inplace on each element of a vector.