MemoryToDebugObserver.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::ArmarXObjects::MemoryToDebugObserver
17 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18 * @date 2023
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <map>
26#include <set>
27#include <string>
28
29#include <SimoxUtility/json/json.h>
30
32
33#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h>
37
39{
40 class NDArray;
41}
42
44{
45 /**
46 * @brief ID of an ARON value in the memory.
47 */
53
54 bool operator==(const MemoryValueID& lhs, const MemoryValueID& rhs);
55 bool operator<(const MemoryValueID& lhs, const MemoryValueID& rhs);
56
57 /**
58 * @brief Transfers data from memory servers to the DebugObserver.
59 *
60 * Transfers data from the memory system to the \ref Component-DebugObserver "Debug Observer",
61 * allowing to visualize them in the \ref ArmarXGui-GuiPlugins-PlotterPlugin "Live Plotter".
62 */
64 {
65 public:
66 /**
67 * @brief Configuration.
68 *
69 * Can be converted to and from JSON.
70 */
72 {
73 std::vector<MemoryValueID> plottedValues;
74 };
75
76 /**
77 * @brief Required services.
78 */
84
85 /**
86 * @brief Constructor.
87 */
88 MemoryToDebugObserver(const Properties& properties, const Services& services);
89
90 /**
91 * @brief Query values from the memory and send them to the debug observer.
92 */
93 void pollOnce();
94
95 /**
96 * @brief Query the given values from the memory and send them to the debug observer.
97 *
98 * Allows polling a dynamically changing set of values without reconstructing this object
99 * (and thereby keeping the cache of memory readers).
100 *
101 * @return The datafields that were sent, grouped by channel name. Lets callers detect which
102 * datafields are no longer being sent (e.g. because a value was removed) and remove them.
103 */
104 std::map<std::string, std::set<std::string>>
105 pollOnce(const std::vector<MemoryValueID>& values);
106
107 static std::string makeChannelName(const armem::MemoryID& memoryID);
108 static std::string makeDatafieldName(const aron::Path& path);
109
110 /**
111 * @brief Decompose a numeric NDArray (vector, matrix, pose) into scalar datafields.
112 *
113 * Returns a list of (datafield name suffix, value) pairs to append to the base datafield
114 * name. Vectors use x/y/z/w (or indices), matrices use row/column indices, and 4x4
115 * homogeneous transforms are converted to x, y, z and roll, pitch, yaw. Returns an empty
116 * list if the array is not a plottable numeric vector/matrix (e.g. an image).
117 */
118 static std::vector<std::pair<std::string, double>>
119 decomposeNDArray(const aron::data::NDArray& array, int maxSize = 16);
120
121 private:
122 armem::client::Reader* getReader(const armem::MemoryID& memoryID);
123
124 Properties properties;
125 Services services;
126
127 std::map<armem::MemoryID, armem::client::Reader> memoryReaders;
128 };
129
130 void to_json(simox::json::json& j, const MemoryValueID& id);
131 void from_json(const simox::json::json& j, MemoryValueID& id);
132
133 void to_json(simox::json::json& j, const MemoryToDebugObserver::Properties& p);
134 void from_json(const simox::json::json& j, MemoryToDebugObserver::Properties& p);
135
136} // namespace armarx::armem::client::util
Brief description of class DebugObserverHelper.
The memory name system (MNS) client.
Reads data from a memory server.
Definition Reader.h:25
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.
The Path class.
Definition Path.h:36
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)
A convenience header to include all aron files (full include, not forward declared)