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 
86  {
87  }
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 
112  task = new RunningTask<Component>(this, &Component::runLoop);
113  task->start();
114  }
115 
116  void
118  {
119  task->stop();
120  task = nullptr;
121  }
122 
123  void
125  {
126  }
127 
128  void
130  {
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
armarx::memory_to_debug_observer::Component::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: Component.cpp:107
armarx::memory_to_debug_observer
Definition: Component.cpp:30
armarx::armem::client::util::MemoryToDebugObserver::Services::memoryNameSystem
MemoryNameSystem & memoryNameSystem
Definition: MemoryToDebugObserver.h:69
armarx::RemoteGui::Client::VBoxLayout
Definition: Widgets.h:167
armarx::DebugObserverComponentPluginUser::getDebugObserverComponentPlugin
plugins::DebugObserverComponentPlugin & getDebugObserverComponentPlugin()
Definition: DebugObserverComponentPlugin.cpp:85
armarx::DebugObserverComponentPluginUser::setDebugObserverBatchModeEnabled
void setDebugObserverBatchModeEnabled(bool enable)
Definition: DebugObserverComponentPlugin.cpp:118
armarx::memory_to_debug_observer::Component::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: Component.cpp:124
armarx::armem::client::plugins::PluginUser::memoryNameSystem
MemoryNameSystem & memoryNameSystem()
Definition: PluginUser.cpp:22
Frequency.h
armarx::core::time::Frequency
Represents a frequency.
Definition: Frequency.h:17
armarx::memory_to_debug_observer::Component::RemoteGui_update
void RemoteGui_update() override
Definition: Component.cpp:160
armarx::RemoteGui::Client::VSpacer
Definition: Widgets.h:204
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::memory_to_debug_observer::Component::Component
Component()
Definition: Component.cpp:85
armarx::memory_to_debug_observer::Component::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: Component.cpp:34
armarx::memory_to_debug_observer::Component::runLoop
void runLoop()
Definition: Component.cpp:129
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::RemoteGui::Client::GroupBox
Definition: Widgets.h:193
armarx::memory_to_debug_observer::Component::getDefaultName
std::string getDefaultName() const override
Definition: Component.cpp:90
Metronome.h
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_startRunningTask
void RemoteGui_startRunningTask()
Definition: LightweightRemoteGuiComponentPlugin.cpp:110
armarx::core::time::Metronome::waitForNextTick
Duration waitForNextTick()
Wait and block until the target period is met.
Definition: Metronome.cpp:31
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::armem::client::util::MemoryToDebugObserver
Transfers data from memory servers to the DebugObserver.
Definition: MemoryToDebugObserver.h:51
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_createTab
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
Definition: LightweightRemoteGuiComponentPlugin.cpp:95
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::core::time::Metronome
Simple rate limiter for use in loops to maintain a certain frequency given a clock.
Definition: Metronome.h:35
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::core::time::Frequency::Hertz
static Frequency Hertz(std::int64_t hertz)
Definition: Frequency.cpp:23
armarx::armem::client::util::MemoryToDebugObserver::Services
Required services.
Definition: MemoryToDebugObserver.h:67
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
Component.h
armarx::memory_to_debug_observer::Component::createRemoteGuiTab
void createRemoteGuiTab()
Definition: Component.cpp:148
armarx::memory_to_debug_observer::Component::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: Component.cpp:117
armarx::memory_to_debug_observer::Component::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: Component.cpp:96