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
28
29namespace armarx
30{
36
39 {
43
44 defs->defineOptionalProperty<std::string>(
45 "PriorKnowledgeName", "PriorKnowledge", "Prior knowledge name.");
46 defs->defineOptionalProperty<std::string>(
47 "WorkingMemoryName", "WorkingMemory", "Working memory name.");
48 defs->defineOptionalProperty<std::string>(
49 "RobotStateComponentName", "RobotStateComponent", "Robot state component name.");
50
51
52 defs->defineOptionalProperty<std::string>(
53 "ObjectClassBlackWhitelistTopic",
54 "WorkingMemoryToArVizObjectClassBlackWhitelistUpdates",
55 "The topic where updates to the object class black-whitelist are published.");
56 defs->defineOptionalProperty<std::vector<std::string>>(
57 "ObjectClassWhitelist",
58 {},
59 "If not empty, only these object classes are shown (comma separated list).")
60 .map("[empty whitelist]", {});
61 defs->defineOptionalProperty<std::vector<std::string>>(
62 "ObjectClassBlacklist",
63 {},
64 "These object classes will never be shown (comma separated list).")
65 .map("[empty blacklist]", {});
66
67
68 defs->optional(
69 p.updateFrequency, "p.UpdateFrequency", "Target number of updates per second.");
70
71 defs->optional(p.floor.show, "p.floor.Show", "Whether to show the floor.");
72 defs->optional(
73 p.floor.height,
74 "p.floor.Height",
75 "Height (z) of the floor plane. \n"
76 "Set slightly below 0 to avoid z-fighting when drawing planes on the ground.");
77 defs->optional(p.loadObjectDatasetsStr,
78 "p.loadDatasets",
79 "Only load the files for the following datasets, separated by ;. Load all "
80 "if input is empty.");
81
82
83 return defs;
84 }
85
86 std::string
88 {
89 return "WorkingMemoryToArViz";
90 }
91
92 void
94 {
96 usingProxyFromProperty("PriorKnowledgeName");
97 usingProxyFromProperty("WorkingMemoryName");
98 usingProxyFromProperty("RobotStateComponentName");
99
100 usingTopicFromProperty("ObjectClassBlackWhitelistTopic");
101 }
102
103 void
105 {
107 getProxyFromProperty(priorKnowledge, "PriorKnowledgeName");
108 getProxyFromProperty(workingMemory, "WorkingMemoryName");
109 getProxyFromProperty(robotStateComponent, "RobotStateComponentName");
110
111 auto datasets = simox::alg::split(p.loadObjectDatasetsStr, ";");
112
113 drawer.setArViz(arviz);
114 drawer.initFromProxies(priorKnowledge, workingMemory, robotStateComponent, datasets);
115 {
117 armarx::BlackWhitelistUpdate update;
118 getProperty(update.whitelist.set, "ObjectClassWhitelist");
119 getProperty(update.blacklist.set, "ObjectClassBlacklist");
120 drawer.updateObjectClassBlackWhitelist(update);
121 }
122
123 if (p.floor.show > 0)
124 {
125 drawer.updateFloorObject(p.floor.height);
126 }
127
128 // A periodic task logs an important info when the cycle time is not met.
129 // To avoid this, we use a running task.
131 [this]()
132 {
134 CycleUtil cycle(int(1000 / p.updateFrequency));
135
136 while (task && !task->isStopped())
137 {
138 {
139 std::scoped_lock lock(drawerMutex);
140 drawer.updateObjects();
141 }
142 cycle.waitForCycleDuration();
143 }
144 });
145
146 task->start();
147 }
148
149 void
151 {
153 if (task)
154 {
155 task->stop();
156 task = nullptr;
157 }
158 }
159
160 void
165
166 void
167 WorkingMemoryToArViz::updateBlackWhitelist(const BlackWhitelistUpdate& update,
168 const Ice::Current&)
169 {
171 std::scoped_lock lock(drawerMutex);
172 drawer.updateObjectClassBlackWhitelist(update);
173 }
174
175 void
177 const memoryx::AttachObjectToRobotNodeInput& input,
178 const Ice::Current&)
179 {
181 std::scoped_lock lock(drawerMutex);
182 drawer.attachObjectToRobotNode(input);
183 }
184
185 void
187 const memoryx::DetachObjectFromRobotNodeInput& input,
188 const Ice::Current&)
189 {
191 std::scoped_lock lock(drawerMutex);
192 drawer.detachObjectFromRobotNode(input);
193 }
194
195} // namespace armarx
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.
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