WorkingMemoryToArViz.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 MemoryX::ArmarXObjects::WorkingMemoryToArViz
17 * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
25#include <SimoxUtility/algorithm/string.h>
26
29
30namespace armarx
31{
37
40 {
44
45 defs->defineOptionalProperty<std::string>(
46 "PriorKnowledgeName", "PriorKnowledge", "Prior knowledge name.");
47 defs->defineOptionalProperty<std::string>(
48 "WorkingMemoryName", "WorkingMemory", "Working memory name.");
49 defs->defineOptionalProperty<std::string>(
50 "RobotStateComponentName", "RobotStateComponent", "Robot state component name.");
51
52
53 defs->defineOptionalProperty<std::string>(
54 "ObjectClassBlackWhitelistTopic",
55 "WorkingMemoryToArVizObjectClassBlackWhitelistUpdates",
56 "The topic where updates to the object class black-whitelist are published.");
57 defs->defineOptionalProperty<std::vector<std::string>>(
58 "ObjectClassWhitelist",
59 {},
60 "If not empty, only these object classes are shown (comma separated list).")
61 .map("[empty whitelist]", {});
62 defs->defineOptionalProperty<std::vector<std::string>>(
63 "ObjectClassBlacklist",
64 {},
65 "These object classes will never be shown (comma separated list).")
66 .map("[empty blacklist]", {});
67
68
69 defs->optional(
70 p.updateFrequency, "p.UpdateFrequency", "Target number of updates per second.");
71
72 defs->optional(p.floor.show, "p.floor.Show", "Whether to show the floor.");
73 defs->optional(
74 p.floor.height,
75 "p.floor.Height",
76 "Height (z) of the floor plane. \n"
77 "Set slightly below 0 to avoid z-fighting when drawing planes on the ground.");
78 defs->optional(p.loadObjectDatasetsStr,
79 "p.loadDatasets",
80 "Only load the files for the following datasets, separated by ;. Load all "
81 "if input is empty.");
82
83
84 return defs;
85 }
86
87 std::string
89 {
90 return "WorkingMemoryToArViz";
91 }
92
93 std::string
95 {
96 return "WorkingMemoryToArViz";
97 }
98
99 void
101 {
103 usingProxyFromProperty("PriorKnowledgeName");
104 usingProxyFromProperty("WorkingMemoryName");
105 usingProxyFromProperty("RobotStateComponentName");
106
107 usingTopicFromProperty("ObjectClassBlackWhitelistTopic");
108 }
109
110 void
112 {
114 getProxyFromProperty(priorKnowledge, "PriorKnowledgeName");
115 getProxyFromProperty(workingMemory, "WorkingMemoryName");
116 getProxyFromProperty(robotStateComponent, "RobotStateComponentName");
117
118 auto datasets = simox::alg::split(p.loadObjectDatasetsStr, ";");
119
120 drawer.setArViz(arviz);
121 drawer.initFromProxies(priorKnowledge, workingMemory, robotStateComponent, datasets);
122 {
124 armarx::BlackWhitelistUpdate update;
125 getProperty(update.whitelist.set, "ObjectClassWhitelist");
126 getProperty(update.blacklist.set, "ObjectClassBlacklist");
127 drawer.updateObjectClassBlackWhitelist(update);
128 }
129
130 if (p.floor.show > 0)
131 {
132 drawer.updateFloorObject(p.floor.height);
133 }
134
135 // A periodic task logs an important info when the cycle time is not met.
136 // To avoid this, we use a running task.
138 [this]()
139 {
141 CycleUtil cycle(int(1000 / p.updateFrequency));
142
143 while (task && !task->isStopped())
144 {
145 {
146 std::scoped_lock lock(drawerMutex);
147 drawer.updateObjects();
148 }
149 cycle.waitForCycleDuration();
150 }
151 });
152
153 task->start();
154 }
155
156 void
158 {
160 if (task)
161 {
162 task->stop();
163 task = nullptr;
164 }
165 }
166
167 void
172
173 void
174 WorkingMemoryToArViz::updateBlackWhitelist(const BlackWhitelistUpdate& update,
175 const Ice::Current&)
176 {
178 std::scoped_lock lock(drawerMutex);
179 drawer.updateObjectClassBlackWhitelist(update);
180 }
181
182 void
184 const memoryx::AttachObjectToRobotNodeInput& input,
185 const Ice::Current&)
186 {
188 std::scoped_lock lock(drawerMutex);
189 drawer.attachObjectToRobotNode(input);
190 }
191
192 void
194 const memoryx::DetachObjectFromRobotNodeInput& input,
195 const Ice::Current&)
196 {
198 std::scoped_lock lock(drawerMutex);
199 drawer.detachObjectFromRobotNode(input);
200 }
201
202} // namespace armarx
203
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
bool usingProxyFromProperty(const std::string &propertyName, const std::string &endpoints="")
Use a proxy whose name is specified by the given property.
void usingTopicFromProperty(const std::string &propertyName, bool orderedPublishing=false)
Use a topic whose name is specified by the given property.
ProxyType getProxyFromProperty(const std::string &propertyName, bool addToDependencies=false, const std::string &endpoints="", bool throwOnProxyError=true)
Get a proxy whose name is specified by the given property.
Definition Component.h:242
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
This util class helps with keeping a cycle time during a control cycle.
Definition CycleUtil.h:41
IceUtil::Time waitForCycleDuration()
This function will wait (virtual or system time) until the cycle time is reached.
Definition CycleUtil.cpp:53
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Property definitions of WorkingMemoryToArViz.
Brief description of class WorkingMemoryToArViz.
void onInitComponent() override
Pure virtual hook for the subclass.
void attachObjectToRobotNode(const memoryx::AttachObjectToRobotNodeInput &input, const Ice::Current &=Ice::emptyCurrent) override
void onDisconnectComponent() override
Hook for subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
Pure virtual hook for the subclass.
void detachObjectFromRobotNode(const memoryx::DetachObjectFromRobotNodeInput &input, const Ice::Current &=Ice::emptyCurrent) override
void onExitComponent() override
Hook for subclass.
void updateBlackWhitelist(const BlackWhitelistUpdate &update, const Ice::Current &=Ice::emptyCurrent) override
std::string getDefaultName() const override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
SimpleRunningTask(Ts...) -> SimpleRunningTask< std::function< void(void)> >
#define ARMARX_TRACE
Definition trace.h:77
#define ARMARX_TRACE_LITE
Definition trace.h:98