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
29
31{
32
35 {
38
39 {
40 armem::MemoryID robotEntityId{"RobotState", "Proprioception", "Armar7", "Armar7"};
41
42 std::vector<std::string> jointNames{
43 "Neck_1_Yaw",
44 "Neck_2_Hemisphere_A",
45 "Neck_3_Hemisphere_B",
46 };
47
48 for (const std::string& jointName : jointNames)
49 {
50 std::vector<std::string> attributes{
51 "position",
52 "positionTarget",
53 "relativePosition",
54 "velocity",
55 "velocityTarget",
56 "torque",
57 "motorCurrent",
58 "currentTarget",
59 };
60 for (const std::string& attribute : attributes)
61 {
62 properties.memoryToDebugObserver.plottedValues.push_back({
63 .entityID = robotEntityId,
64 .aronPath = {{"joints", attribute, jointName}},
65 });
66 properties.memoryToDebugObserver.plottedValues.push_back({
67 .entityID = robotEntityId,
68 .aronPath = {{"extraLongs", jointName + ".absoluteEncoderTicks"}},
69 });
70 }
71 }
72
73 simox::json::json j = properties.memoryToDebugObserver;
74 properties.memoryToDebugObserverJson = j.dump();
75 }
76 defs->optional(properties.memoryToDebugObserverJson,
77 "p.memoryToDebugObserverJson",
78 "Configuration of MemoryToDebugObserver in JSON format.");
79
80 defs->optional(properties.pollFrequencyHz, "p.pollFrequencyHz");
81
82 return defs;
83 }
84
88
89 std::string
91 {
92 return "MemoryToDebugObserver";
93 }
94
95 void
97 {
99
100 {
101 simox::json::json j = simox::json::json::parse(properties.memoryToDebugObserverJson);
102 j.get_to(properties.memoryToDebugObserver);
103 }
104 }
105
106 void
108 {
111
113 task->start();
114 }
115
116 void
118 {
119 task->stop();
120 task = nullptr;
121 }
122
123 void
127
128 void
130 {
132 .memoryNameSystem = memoryNameSystem(),
133 .debugObserver = getDebugObserverComponentPlugin(),
134 };
135 armem::client::util::MemoryToDebugObserver memoryToDebugObserver{
136 properties.memoryToDebugObserver, services};
137
138 Frequency frequency = Frequency::Hertz(properties.pollFrequencyHz);
139 Metronome metronome(frequency);
140 while (task and not task->isStopped())
141 {
142 memoryToDebugObserver.pollOnce();
143 metronome.waitForNextTick();
144 }
145 }
146
147 void
149 {
150 using namespace armarx::RemoteGui::Client;
151
152 tab.group = GroupBox();
153 tab.group.setLabel("Todo ...");
154
155 VBoxLayout root = {tab.group, VSpacer()};
156 RemoteGui_createTab(getName(), root, &tab);
157 }
158
159 void
161 {
162 if (tab.rebuild.exchange(false))
163 {
165 }
166 }
167
168} // namespace armarx::memory_to_debug_observer
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
void onInitComponent() override
Pure virtual hook for the subclass.
Definition Component.cpp:96
void onDisconnectComponent() override
Hook for subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition Component.cpp:34
void onConnectComponent() override
Pure virtual hook for the subclass.
void onExitComponent() override
Hook for subclass.
std::string getDefaultName() const override
Definition Component.cpp:90
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)