Component.cpp
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#include "Component.h"
24
25#include <SimoxUtility/json.h>
26
30
32 "MemoryToDebugObserver");
33
35{
36
39 {
42
43 {
44 armem::MemoryID robotEntityId{"RobotState", "Proprioception", "Armar7", "Armar7"};
45
46 std::vector<std::string> jointNames{
47 "Neck_1_Yaw",
48 "Neck_2_Hemisphere_A",
49 "Neck_3_Hemisphere_B",
50 };
51
52 for (const std::string& jointName : jointNames)
53 {
54 std::vector<std::string> attributes{
55 "position",
56 "positionTarget",
57 "relativePosition",
58 "velocity",
59 "velocityTarget",
60 "torque",
61 "motorCurrent",
62 "currentTarget",
63 };
64 for (const std::string& attribute : attributes)
65 {
66 properties.memoryToDebugObserver.plottedValues.push_back({
67 .entityID = robotEntityId,
68 .aronPath = {{"joints", attribute, jointName}},
69 });
70 properties.memoryToDebugObserver.plottedValues.push_back({
71 .entityID = robotEntityId,
72 .aronPath = {{"extraLongs", jointName + ".absoluteEncoderTicks"}},
73 });
74 }
75 }
76
77 simox::json::json j = properties.memoryToDebugObserver;
78 properties.memoryToDebugObserverJson = j.dump();
79 }
80 defs->optional(properties.memoryToDebugObserverJson,
81 "p.memoryToDebugObserverJson",
82 "Configuration of MemoryToDebugObserver in JSON format.");
83
84 defs->optional(properties.pollFrequencyHz, "p.pollFrequencyHz");
85
86 return defs;
87 }
88
92
93 std::string
95 {
96 return "MemoryToDebugObserver";
97 }
98
99 void
101 {
103
104 {
105 simox::json::json j = simox::json::json::parse(properties.memoryToDebugObserverJson);
106 j.get_to(properties.memoryToDebugObserver);
107 }
108 }
109
110 void
112 {
115
117 task->start();
118 }
119
120 void
122 {
123 task->stop();
124 task = nullptr;
125 }
126
127 void
131
132 void
134 {
136 .memoryNameSystem = memoryNameSystem(),
137 .debugObserver = getDebugObserverComponentPlugin(),
138 };
139 armem::client::util::MemoryToDebugObserver memoryToDebugObserver{
140 properties.memoryToDebugObserver, services};
141
142 Frequency frequency = Frequency::Hertz(properties.pollFrequencyHz);
143 Metronome metronome(frequency);
144 while (task and not task->isStopped())
145 {
146 memoryToDebugObserver.pollOnce();
147 metronome.waitForNextTick();
148 }
149 }
150
151 void
153 {
154 using namespace armarx::RemoteGui::Client;
155
156 tab.group = GroupBox();
157 tab.group.setLabel("Todo ...");
158
159 VBoxLayout root = {tab.group, VSpacer()};
160 RemoteGui_createTab(getName(), root, &tab);
161 }
162
163 void
165 {
166 if (tab.rebuild.exchange(false))
167 {
169 }
170 }
171
172} // namespace armarx::memory_to_debug_observer
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
plugins::DebugObserverComponentPlugin & getDebugObserverComponentPlugin()
static Frequency Hertz(std::int64_t hertz)
Definition Frequency.cpp:20
std::string getName() const
Retrieve name of object.
Transfers data from memory servers to the DebugObserver.
Represents a frequency.
Definition Frequency.h:17
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition Metronome.h:57
Duration waitForNextTick() const
Wait and block until the target period is met.
Definition Metronome.cpp:27
Implementation of MemoryToDebugObserver.
Definition Component.h:59
void onInitComponent() override
Pure virtual hook for the subclass.
void onDisconnectComponent() override
Hook for subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition Component.cpp:38
void onConnectComponent() override
Pure virtual hook for the subclass.
void onExitComponent() override
Hook for subclass.
std::string getDefaultName() const override
Definition Component.cpp:94
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)