FakeWorkingMemoryObjectLocalizer.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 ArmarXSimulation::ArmarXObjects::FakeWorkingMemoryObjectLocalizer
17  * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
18  * @date 2016
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
26 
29 
30 using namespace armarx;
31 
32 std::string
34 {
35  return "FakeWorkingMemoryObjectLocalizer";
36 }
37 
38 void
40 {
41  usingProxy(getProperty<std::string>("WorkingMemoryName").getValue());
42 }
43 
44 void
46 {
47  getProxyFromProperty(wm, "WorkingMemoryName");
48 }
49 
50 void
52 {
53 }
54 
55 void
57 {
58 }
59 
62 {
65 }
66 
68 computePositionNoise(const Eigen::Vector3f& pos)
69 {
71  mean.push_back(pos(0));
72  mean.push_back(pos(1));
73  mean.push_back(pos(2));
74 
75  // assuming 2 mm noise
78  posDist->setMean(mean);
79  posDist->setCovariance(0, 0, 2.0f);
80  posDist->setCovariance(1, 1, 2.0f);
81  posDist->setCovariance(2, 2, 2.0f);
82  return posDist;
83 }
84 
85 memoryx::ObjectLocalizationResultList
87  const memoryx::ObjectClassNameList& objectClassNames,
88  const Ice::Current&)
89 {
90  memoryx::ObjectLocalizationResultList results;
91  auto objInstSeg = wm->getObjectInstancesSegment();
92  for (auto& className : objectClassNames)
93  {
94  ARMARX_DEBUG << deactivateSpam(5, className);
95 
96  auto objInstances = objInstSeg->getObjectInstancesByClass(className);
97  for (memoryx::ObjectInstanceBasePtr obj : objInstances)
98  {
99  if (obj)
100  {
101  memoryx::ObjectLocalizationResult result;
102  result.objectClassName = className;
103  result.orientation = obj->getOrientationBase();
104  result.position = obj->getPositionBase();
105  result.positionNoise = computePositionNoise(
106  armarx::FramedPositionPtr::dynamicCast(result.position)->toEigen());
107  result.recognitionCertainty = 0.95;
108  result.timeStamp = TimestampVariant::nowPtr();
109  ARMARX_INFO << "Returning instance at pose " << obj->getPositionBase()->output();
110  results.push_back(result);
111  }
112  }
113  }
114  return results;
115 }
armarx::FakeWorkingMemoryObjectLocalizer::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: FakeWorkingMemoryObjectLocalizer.cpp:61
armarx::FakeWorkingMemoryObjectLocalizer::wm
memoryx::WorkingMemoryInterfacePrx wm
Definition: FakeWorkingMemoryObjectLocalizer.h:104
armarx::FakeWorkingMemoryObjectLocalizer::getDefaultName
std::string getDefaultName() const override
Definition: FakeWorkingMemoryObjectLocalizer.cpp:33
armarx::FakeWorkingMemoryObjectLocalizerPropertyDefinitions
Definition: FakeWorkingMemoryObjectLocalizer.h:37
armarx::FakeWorkingMemoryObjectLocalizer::onConnectComponent
void onConnectComponent() override
Definition: FakeWorkingMemoryObjectLocalizer.cpp:45
armarx::TimestampVariant::nowPtr
static TimestampVariantPtr nowPtr()
Definition: TimestampVariant.h:126
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::FloatVector
::std::vector<::Ice::Float > FloatVector
Definition: KinematicUnitGuiPlugin.h:325
FakeWorkingMemoryObjectLocalizer.h
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:242
armarx::mean
std::optional< float > mean(const boost::circular_buffer< NameValueMap > &buffer, const std::string &key)
Definition: KinematicUnitGuiPlugin.cpp:1620
armarx::FakeWorkingMemoryObjectLocalizer::onExitComponent
void onExitComponent() override
Definition: FakeWorkingMemoryObjectLocalizer.cpp:56
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
TimestampVariant.h
armarx::FakeWorkingMemoryObjectLocalizer::onInitComponent
void onInitComponent() override
Definition: FakeWorkingMemoryObjectLocalizer.cpp:39
MemoryXCoreObjectFactories.h
computePositionNoise
::memoryx::MultivariateNormalDistributionPtr computePositionNoise(const Eigen::Vector3f &pos)
Definition: FakeWorkingMemoryObjectLocalizer.cpp:68
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle< class PropertyDefinitionContainer >
MemoryXTypesObjectFactories.h
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:99
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::FakeWorkingMemoryObjectLocalizer::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const memoryx::ObjectClassNameList &objectClassNames, const Ice::Current &) override
Definition: FakeWorkingMemoryObjectLocalizer.cpp:86
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:154
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::FakeWorkingMemoryObjectLocalizer::onDisconnectComponent
void onDisconnectComponent() override
Definition: FakeWorkingMemoryObjectLocalizer.cpp:51
armarx::VariantType::MultivariateNormalDistribution
const armarx::VariantTypeId MultivariateNormalDistribution
Definition: ProbabilityMeasures.h:40