35#include <SimoxUtility/algorithm/string/string_tools.h>
36#include <SimoxUtility/math/convert/mat4f_to_rpy.h>
50 properties(properties), services(services)
52 services.debugObserver.setDebugObserverBatchModeEnabled(
true);
113 template <
class ValueT>
122 template <
class ValueT>
133 std::map<std::string, std::set<std::string>>
pushed;
144 std::map<std::string, std::set<std::string>>
147 Visitor visitor(services.debugObserver);
149 std::stringstream log;
152 std::map<MemoryID, std::vector<const MemoryValueID*>> valuesPerProviderSegment;
155 valuesPerProviderSegment[valueId.entityID.getProviderSegmentID()].push_back(&valueId);
158 for (
const auto& [providerSegmentID, values] : valuesPerProviderSegment)
163 reader = getReader(providerSegmentID);
167 log <<
"\n" << e.what();
175 log <<
"Query to provider segment " << providerSegmentID
183 if (entity ==
nullptr)
185 log <<
"\nDid not find entity " << valueId->entityID <<
" in provider segment "
186 << providerSegmentID <<
".";
198 if (instance ==
nullptr)
200 log <<
"\nEntity " << valueId->entityID
201 <<
" has no latest instance (yet) in provider segment " << providerSegmentID
207 instance->
data()->navigateAbsolute(valueId->aronPath);
208 if (not valueVariant)
210 log <<
"\nDid not find " << valueId->aronPath.toString()
211 <<
" in entity instance " << instance->
id() <<
".";
222 services.debugObserver.sendDebugObserverBatch();
224 if (not log.str().empty())
227 <<
"Encountered issues while sending memory values to the debug observer "
238 return simox::alg::replace_all(memoryID.
str(),
"/",
">");
251 std::vector<std::pair<std::string, double>>
258 auto mapAsMatrix = [&array, maxSize](
auto scalar) -> std::optional<Eigen::MatrixXd>
260 using ScalarT =
decltype(scalar);
261 const std::vector<int> shape = array.
getShape();
262 if (shape.size() != 3 or shape.back() !=
static_cast<int>(
sizeof(ScalarT)))
266 const int rows = shape.at(0);
267 const int cols = shape.at(1);
268 if (rows <= 0 or cols <= 0 or rows * cols > maxSize)
272 using MapT = Eigen::Map<
274 return MapT(
reinterpret_cast<const ScalarT*
>(array.
getData()), rows, cols)
275 .template cast<double>();
278 const std::string type = array.
getType();
279 std::optional<Eigen::MatrixXd> matrix;
282 matrix = mapAsMatrix(
float{});
284 else if (type ==
"double")
286 matrix = mapAsMatrix(
double{});
288 else if (type ==
"int")
290 matrix = mapAsMatrix(
int{});
292 else if (type ==
"long")
294 matrix = mapAsMatrix(std::int64_t{});
296 if (not matrix.has_value())
300 const Eigen::MatrixXd& m = matrix.value();
302 std::vector<std::pair<std::string, double>>
components;
305 constexpr double bottomRowPrecision = 1e-4;
306 if (m.rows() == 4 and m.cols() == 4 and
307 m.row(3).isApprox(Eigen::RowVector4d(0, 0, 0, 1), bottomRowPrecision))
309 const Eigen::Matrix4f pose = m.cast<
float>();
310 const Eigen::Vector3f rpy = simox::math::mat4f_to_rpy(pose);
327 if (m.rows() == 1 or m.cols() == 1)
329 static const std::array<std::string, 4> xyzw{
"_x",
"_y",
"_z",
"_w"};
330 for (
int i = 0; i < m.size(); ++i)
332 components.emplace_back(m.size() <= 4 ? xyzw.at(i) :
"_" + std::to_string(i), m(i));
338 for (
int r = 0; r < m.rows(); ++r)
340 for (
int c = 0;
c < m.cols(); ++
c)
342 components.emplace_back(
"_" + std::to_string(r) +
"_" + std::to_string(
c), m(r,
c));
349 MemoryToDebugObserver::getReader(
const MemoryID& memoryID)
351 auto it = memoryReaders.find(memoryID);
352 if (it != memoryReaders.end())
359 auto [it, _] = memoryReaders.emplace(memoryID, reader);
392 j[
"entityID"] =
id.entityID.getItems();
393 j[
"aronPath"] =
id.aronPath.getPath();
400 id.aronPath = {j.at(
"aronPath").get<std::vector<std::string>>()};
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Brief description of class DebugObserverHelper.
static MemoryID fromItems(const std::vector< std::string > &items)
Constructor memory ID from items as returned by getItems().
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
auto * findLatestInstance(int instanceIndex=0)
const DataT & data() const
Reader getReader(const MemoryID &memoryID)
Get a reader to the given memory name.
Reads data from a memory server.
QueryResult getLatestSnapshotsIn(const MemoryID &id, armem::query::DataMode dataMode=armem::query::DataMode::WithData) const
Get the latest snapshots under the given memory ID.
static std::vector< std::pair< std::string, double > > decomposeNDArray(const aron::data::NDArray &array, int maxSize=16)
Decompose a numeric NDArray (vector, matrix, pose) into scalar datafields.
void pollOnce()
Query values from the memory and send them to the debug observer.
static std::string makeChannelName(const armem::MemoryID &memoryID)
static std::string makeDatafieldName(const aron::Path &path)
MemoryToDebugObserver(const Properties &properties, const Services &services)
Constructor.
Visitor(armarx::DebugObserverHelper &debugObserver)
std::map< std::string, std::set< std::string > > pushed
armarx::DebugObserverHelper & debugObserver
void visitAronVariant(const aron::data::LongPtr &v) override
void visitAronVariant(const aron::data::IntPtr &v) override
void visitAronVariant(const aron::data::DoublePtr &v) override
std::string datafieldName
void visitAronVariant(const aron::data::NDArrayPtr &v) override
void setDatafield(const ValueT &value)
void visitAronVariant(const aron::data::StringPtr &v) override
void setDatafield(const std::string &datafield, const ValueT &value)
void visitAronVariant(const aron::data::FloatPtr &v) override
void visitAronVariant(const aron::data::BoolPtr &v) override
Indicates that a query to the Memory Name System failed.
std::string toString() const
std::vector< std::string > getPath() const
std::string getDelimeter() const
std::string getRootIdentifier() const
std::string getType() const
unsigned char * getData() const
std::vector< int > getShape() const
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
bool operator<(const MemoryValueID &lhs, const MemoryValueID &rhs)
void from_json(const simox::json::json &j, MemoryValueID &id)
bool operator==(const MemoryValueID &lhs, const MemoryValueID &rhs)
void to_json(simox::json::json &j, const MemoryValueID &id)
This file is part of ArmarX.
armem::wm::EntityInstance EntityInstance
std::shared_ptr< Bool > BoolPtr
std::shared_ptr< Float > FloatPtr
std::shared_ptr< Variant > VariantPtr
std::shared_ptr< NDArray > NDArrayPtr
std::shared_ptr< Long > LongPtr
std::shared_ptr< Int > IntPtr
void visit(VisitorImplementation &v, typename VisitorImplementation::Input &o)
std::shared_ptr< Double > DoublePtr
std::shared_ptr< String > StringPtr
auto * findEntity(const MemoryID &entityID)
Find an entity.
wm::Memory memory
The slice of the memory that matched the query.
std::vector< MemoryValueID > plottedValues
MemoryNameSystem & memoryNameSystem
ID of an ARON value in the memory.