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 
23 #include "WorkingMemoryToArViz.h"
24 
26 #include <SimoxUtility/algorithm/string.h>
27 
28 namespace armarx
29 {
32  {
33  }
34 
35 
37  {
40 
41  defs->defineOptionalProperty<std::string>("PriorKnowledgeName", "PriorKnowledge", "Prior knowledge name.");
42  defs->defineOptionalProperty<std::string>("WorkingMemoryName", "WorkingMemory", "Working memory name.");
43  defs->defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Robot state component name.");
44 
45 
46  defs->defineOptionalProperty<std::string>(
47  "ObjectClassBlackWhitelistTopic", "WorkingMemoryToArVizObjectClassBlackWhitelistUpdates",
48  "The topic where updates to the object class black-whitelist are published.");
49  defs->defineOptionalProperty<std::vector<std::string>>("ObjectClassWhitelist", {},
50  "If not empty, only these object classes are shown (comma separated list).")
51  .map("[empty whitelist]", {});
52  defs->defineOptionalProperty<std::vector<std::string>>("ObjectClassBlacklist", {},
53  "These object classes will never be shown (comma separated list).")
54  .map("[empty blacklist]", {});
55 
56 
57  defs->optional(p.updateFrequency, "p.UpdateFrequency", "Target number of updates per second.");
58 
59  defs->optional(p.floor.show, "p.floor.Show", "Whether to show the floor.");
60  defs->optional(p.floor.height, "p.floor.Height",
61  "Height (z) of the floor plane. \n"
62  "Set slightly below 0 to avoid z-fighting when drawing planes on the ground.");
63  defs->optional(p.loadObjectDatasetsStr, "p.loadDatasets", "Only load the files for the following datasets, separated by ;. Load all if input is empty.");
64 
65 
66  return defs;
67  }
68 
69 
71  {
72  return "WorkingMemoryToArViz";
73  }
74 
75 
77  {
79  usingProxyFromProperty("PriorKnowledgeName");
80  usingProxyFromProperty("WorkingMemoryName");
81  usingProxyFromProperty("RobotStateComponentName");
82 
83  usingTopicFromProperty("ObjectClassBlackWhitelistTopic");
84  }
85 
86 
88  {
90  getProxyFromProperty(priorKnowledge, "PriorKnowledgeName");
91  getProxyFromProperty(workingMemory, "WorkingMemoryName");
92  getProxyFromProperty(robotStateComponent, "RobotStateComponentName");
93 
94  auto datasets = simox::alg::split(p.loadObjectDatasetsStr, ";");
95 
96  drawer.setArViz(arviz);
97  drawer.initFromProxies(priorKnowledge, workingMemory, robotStateComponent, datasets);
98  {
100  armarx::BlackWhitelistUpdate update;
101  getProperty(update.whitelist.set, "ObjectClassWhitelist");
102  getProperty(update.blacklist.set, "ObjectClassBlacklist");
104  }
105 
106  if (p.floor.show > 0)
107  {
108  drawer.updateFloorObject(p.floor.height);
109  }
110 
111  // A periodic task logs an important info when the cycle time is not met.
112  // To avoid this, we use a running task.
113  task = new armarx::SimpleRunningTask<>([this]()
114  {
116  CycleUtil cycle(int(1000 / p.updateFrequency));
117 
118  while (task && !task->isStopped())
119  {
120  {
121  std::scoped_lock lock(drawerMutex);
122  drawer.updateObjects();
123  }
124  cycle.waitForCycleDuration();
125  }
126  });
127 
128  task->start();
129  }
130 
131 
133  {
134  ARMARX_TRACE;
135  if (task) {
136  task->stop();
137  task = nullptr;
138  }
139  }
140 
141 
143  {
144  ARMARX_TRACE;
145  }
146 
147 
148  void WorkingMemoryToArViz::updateBlackWhitelist(const BlackWhitelistUpdate& update, const Ice::Current&)
149  {
150  ARMARX_TRACE;
151  std::scoped_lock lock(drawerMutex);
153  }
154 
156  const memoryx::AttachObjectToRobotNodeInput& input, const Ice::Current&)
157  {
158  ARMARX_TRACE;
159  std::scoped_lock lock(drawerMutex);
161  }
162 
164  const memoryx::DetachObjectFromRobotNodeInput& input, const Ice::Current&)
165  {
166  ARMARX_TRACE;
167  std::scoped_lock lock(drawerMutex);
169  }
170 
171 }
memoryx::ObjectInstancesToArViz::setArViz
void setArViz(armarx::viz::Client arviz)
Set the ArViz client.
Definition: ObjectInstancesToArViz.cpp:19
armarx::WorkingMemoryToArViz::updateBlackWhitelist
void updateBlackWhitelist(const BlackWhitelistUpdate &update, const Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemoryToArViz.cpp:148
armarx::SimpleRunningTask
Usage:
Definition: TaskUtil.h:70
memoryx::ObjectInstancesToArViz::attachObjectToRobotNode
void attachObjectToRobotNode(const memoryx::AttachObjectToRobotNodeInput &attachment)
Definition: ObjectInstancesToArViz.cpp:177
armarx::WorkingMemoryToArVizPropertyDefinitions::WorkingMemoryToArVizPropertyDefinitions
WorkingMemoryToArVizPropertyDefinitions(std::string prefix)
Definition: WorkingMemoryToArViz.cpp:30
memoryx::ObjectInstancesToArViz::updateFloorObject
void updateFloorObject(float height=0)
Draw a the floor as a simox object.
Definition: ObjectInstancesToArViz.cpp:52
armarx::CycleUtil
This util class helps with keeping a cycle time during a control cycle.
Definition: CycleUtil.h:40
armarx::WorkingMemoryToArViz::getDefaultName
std::string getDefaultName() const override
Definition: WorkingMemoryToArViz.cpp:70
armarx::Component::usingProxyFromProperty
bool usingProxyFromProperty(const std::string &propertyName, const std::string &endpoints="")
Use a proxy whose name is specified by the given property.
Definition: Component.cpp:167
armarx::WorkingMemoryToArViz::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: WorkingMemoryToArViz.cpp:76
memoryx::ObjectInstancesToArViz::initFromProxies
void initFromProxies(const PriorKnowledgeInterfacePrx &priorKnowledge, const WorkingMemoryInterfacePrx &workingMemory, const armarx::RobotStateComponentInterfacePrx &robotStateComponent, const std::vector< std::string > &datasets)
Set the proxies.
Definition: ObjectInstancesToArViz.cpp:25
ARMARX_TRACE_LITE
#define ARMARX_TRACE_LITE
Definition: trace.h:85
armarx::Component::getProxyFromProperty
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:236
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::WorkingMemoryToArViz::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: WorkingMemoryToArViz.cpp:142
armarx::WorkingMemoryToArViz::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: WorkingMemoryToArViz.cpp:132
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::Component::usingTopicFromProperty
void usingTopicFromProperty(const std::string &propertyName, bool orderedPublishing=false)
Use a topic whose name is specified by the given property.
Definition: Component.cpp:160
memoryx::ObjectInstancesToArViz::detachObjectFromRobotNode
void detachObjectFromRobotNode(const memoryx::DetachObjectFromRobotNodeInput &detachment)
Definition: ObjectInstancesToArViz.cpp:183
armarx::WorkingMemoryToArVizPropertyDefinitions
Property definitions of WorkingMemoryToArViz.
Definition: WorkingMemoryToArViz.h:46
armarx::WorkingMemoryToArViz::detachObjectFromRobotNode
void detachObjectFromRobotNode(const memoryx::DetachObjectFromRobotNodeInput &input, const Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemoryToArViz.cpp:163
armarx::CycleUtil::waitForCycleDuration
IceUtil::Time waitForCycleDuration()
This function will wait (virtual or system time) until the cycle time is reached.
Definition: CycleUtil.cpp:53
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
CycleUtil.h
WorkingMemoryToArViz.h
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::ArVizComponentPluginUser::arviz
armarx::viz::Client arviz
Definition: ArVizComponentPlugin.h:43
armarx::PropertyUser::getProperty
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
Definition: PropertyUser.h:179
armarx::WorkingMemoryToArViz::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: WorkingMemoryToArViz.cpp:87
IceUtil::Handle< class PropertyDefinitionContainer >
memoryx::ObjectInstancesToArViz::updateObjectClassBlackWhitelist
void updateObjectClassBlackWhitelist(const armarx::BlackWhitelistUpdate &update)
Definition: ObjectInstancesToArViz.cpp:169
armarx::WorkingMemoryToArViz::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: WorkingMemoryToArViz.cpp:36
memoryx::ObjectInstancesToArViz::updateObjects
void updateObjects()
Query object instances and update their visualization.
Definition: ObjectInstancesToArViz.cpp:59
armarx::WorkingMemoryToArViz::attachObjectToRobotNode
void attachObjectToRobotNode(const memoryx::AttachObjectToRobotNodeInput &input, const Ice::Current &=Ice::emptyCurrent) override
Definition: WorkingMemoryToArViz.cpp:155
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36