DummyObjectLocalizer.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::DummyObjectLocalizer
17  * @author Fabian Paus ( fabian dot paus at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "DummyObjectLocalizer.h"
24 
25 #include <fstream>
26 #include <sstream>
27 
31 
33 
34 namespace armarx
35 {
36  void
38  {
39  std::setlocale(LC_ALL, "En_US");
40 
41  std::string objectPoseFile = getProperty<std::string>("ObjectPoseFile").getValue();
42  if (!armarx::ArmarXDataPath::getAbsolutePath(objectPoseFile, objectPoseFile))
43  {
44  ARMARX_ERROR << "Could not find object pose file file in ArmarXDataPath: "
45  << objectPoseFile;
46  return;
47  }
48 
49  std::stringstream fileContent;
50  try
51  {
52  std::ifstream input;
53  input.exceptions(std::ifstream::failbit | std::ifstream::badbit);
54  input.open(objectPoseFile, std::ios::binary);
55  fileContent << input.rdbuf();
56  }
57  catch (std::exception const& ex)
58  {
59  ARMARX_WARNING << "Could not open or read from file: " << objectPoseFile;
60  }
61 
62  ARMARX_INFO << "File content: " << fileContent.str();
63 
65  o.fromString(fileContent.str());
66  const Json::Value& j = o.getJsonValue();
67 
68  std::vector<std::string> objectNames = j.getMemberNames();
69 
70  for (std::string const& objectName : objectNames)
71  {
72  ARMARX_INFO << "Object name: " << objectName;
73  DummyObject object;
74  object.name = objectName;
75 
76  Json::Value map = j.get(objectName, Json::Value::null);
77  std::string encodedPose = map["pose"].asString();
78  std::string frame = map["frame"].asString();
79  std::string agent = map["agent"].asString();
80 
81  std::istringstream poseInput(encodedPose);
82  Eigen::Matrix4f pose;
83  for (int row = 0; row < 4; ++row)
84  {
85  for (int column = 0; column < 4; ++column)
86  {
87  float value;
88  if (poseInput >> value)
89  {
90  pose.col(column)[row] = value;
91  }
92  else
93  {
94  ARMARX_WARNING << "Failed to read float: " << poseInput.str();
95  }
96  }
97  }
98 
99  object.pose = new armarx::FramedPose(pose, frame, agent);
100 
101  dummyObjects.push_back(object);
102  }
103 
104 
105  usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
106  }
107 
108  void
110  {
111  for (DummyObject const& object : dummyObjects)
112  {
113  ARMARX_INFO << "Object '" << object.name << "': " << *object.pose;
114  }
115 
116 
117  robotStateComponent = getProxy<armarx::RobotStateComponentInterfacePrx>(
118  getProperty<std::string>("RobotStateComponentName").getValue());
119  }
120 
121  void
123  {
124  }
125 
126  void
128  {
129  }
130 
133  {
136  }
137 
138  memoryx::ObjectLocalizationResultList
139  armarx::DummyObjectLocalizer::localizeObjectClasses(const memoryx::ObjectClassNameList& classes,
140  const Ice::Current&)
141  {
142  memoryx::ObjectLocalizationResultList result;
143  result.reserve(dummyObjects.size());
144 
145 
146  armarx::SharedRobotInterfacePrx robot = robotStateComponent->getSynchronizedRobot();
148  for (DummyObject const& object : dummyObjects)
149  {
150  if (std::find(classes.begin(), classes.end(), object.name) == classes.end())
151  {
152  continue;
153  }
154 
155 
156  armarx::FramedPosePtr poseInRootFrame = object.pose->toRootFrame(robot);
157  memoryx::ObjectLocalizationResult localizedObject;
158 
159  localizedObject.objectClassName = object.name;
160  ARMARX_INFO << "Reporting: " << object.name << " at " << poseInRootFrame->output();
161  localizedObject.position = poseInRootFrame->getPosition();
162  localizedObject.orientation = poseInRootFrame->getOrientation();
163 
164  localizedObject.recognitionCertainty = 1.0f;
165 
166  localizedObject.positionNoise =
168 
169  localizedObject.timeStamp = now;
170 
171 
172  result.push_back(localizedObject);
173  }
174 
175  return result;
176  }
177 } // namespace armarx
armarx::DummyObjectLocalizer::onExitComponent
void onExitComponent() override
Definition: DummyObjectLocalizer.cpp:127
ColorMap::Value
Value
Color maps that associate a color to every float from [0..1].
Definition: color.h:16
JSONObject.h
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:36
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::DummyObjectLocalizer::onConnectComponent
void onConnectComponent() override
Definition: DummyObjectLocalizer.cpp:109
armarx::JSONObject
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition: JSONObject.h:43
armarx::DummyObjectLocalizer::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const memoryx::ObjectClassNameList &classes, const Ice::Current &) override
Definition: DummyObjectLocalizer.cpp:139
armarx::DummyObjectLocalizer::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: DummyObjectLocalizer.cpp:132
armarx::DummyObjectLocalizer::onDisconnectComponent
void onDisconnectComponent() override
Definition: DummyObjectLocalizer.cpp:122
armarx::TimestampVariant::nowPtr
static TimestampVariantPtr nowPtr()
Definition: TimestampVariant.h:126
armarx::DummyObjectLocalizerPropertyDefinitions
Definition: DummyObjectLocalizer.h:46
IceInternal::Handle< TimestampVariant >
armarx::JSONObject::getJsonValue
const Json::Value & getJsonValue() const
Definition: JSONObject.cpp:96
memoryx::MultivariateNormalDistribution::CreateDefaultDistribution
static MultivariateNormalDistributionPtr CreateDefaultDistribution(float variance=10000)
Create a distribution with uncertainty of variance in all directions (default: variance = 10000,...
Definition: ProbabilityMeasures.h:301
DummyObjectLocalizer.h
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::JSONObject::fromString
void fromString(const ::std::string &jsonString, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: JSONObject.cpp:88
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:12
TimestampVariant.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
armarx::DummyObjectLocalizer::onInitComponent
void onInitComponent() override
Definition: DummyObjectLocalizer.cpp:37
ProbabilityMeasures.h
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 >
IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface >
armarx::DummyObject
Definition: DummyObjectLocalizer.h:36
armarx::ArmarXDataPath::getAbsolutePath
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
Definition: ArmarXDataPath.cpp:109
armarx::DummyObject::name
std::string name
Definition: DummyObjectLocalizer.h:38
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
ArmarXDataPath.h
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