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 
29 #include <fstream>
30 #include <sstream>
31 
32 namespace armarx
33 {
35  {
36  std::setlocale(LC_ALL, "En_US");
37 
38  std::string objectPoseFile = getProperty<std::string>("ObjectPoseFile").getValue();
39  if (!armarx::ArmarXDataPath::getAbsolutePath(objectPoseFile, objectPoseFile))
40  {
41  ARMARX_ERROR << "Could not find object pose file file in ArmarXDataPath: " << objectPoseFile;
42  return;
43  }
44 
45  std::stringstream fileContent;
46  try
47  {
48  std::ifstream input;
49  input.exceptions(std::ifstream::failbit | std::ifstream::badbit);
50  input.open(objectPoseFile, std::ios::binary);
51  fileContent << input.rdbuf();
52  }
53  catch (std::exception const& ex)
54  {
55  ARMARX_WARNING << "Could not open or read from file: " << objectPoseFile;
56  }
57 
58  ARMARX_INFO << "File content: " << fileContent.str();
59 
61  o.fromString(fileContent.str());
62  const Json::Value& j = o.getJsonValue();
63 
64  std::vector<std::string> objectNames = j.getMemberNames();
65 
66  for (std::string const& objectName : objectNames)
67  {
68  ARMARX_INFO << "Object name: " << objectName;
69  DummyObject object;
70  object.name = objectName;
71 
72  Json::Value map = j.get(objectName, Json::Value::null);
73  std::string encodedPose = map["pose"].asString();
74  std::string frame = map["frame"].asString();
75  std::string agent = map["agent"].asString();
76 
77  std::istringstream poseInput(encodedPose);
78  Eigen::Matrix4f pose;
79  for (int row = 0; row < 4; ++row)
80  {
81  for (int column = 0; column < 4; ++column)
82  {
83  float value;
84  if (poseInput >> value)
85  {
86  pose.col(column)[row] = value;
87  }
88  else
89  {
90  ARMARX_WARNING << "Failed to read float: " << poseInput.str();
91  }
92  }
93  }
94 
95  object.pose = new armarx::FramedPose(pose, frame, agent);
96 
97  dummyObjects.push_back(object);
98  }
99 
100 
101  usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
102  }
103 
104 
106  {
107  for (DummyObject const& object : dummyObjects)
108  {
109  ARMARX_INFO << "Object '" << object.name << "': " << *object.pose;
110  }
111 
112 
113  robotStateComponent = getProxy<armarx::RobotStateComponentInterfacePrx>(getProperty<std::string>("RobotStateComponentName").getValue());
114  }
115 
116 
118  {
119 
120  }
121 
122 
124  {
125 
126  }
127 
129  {
132  }
133 
134 
135 
136  memoryx::ObjectLocalizationResultList armarx::DummyObjectLocalizer::localizeObjectClasses(const memoryx::ObjectClassNameList& classes, const Ice::Current&)
137  {
138  memoryx::ObjectLocalizationResultList result;
139  result.reserve(dummyObjects.size());
140 
141 
142  armarx::SharedRobotInterfacePrx robot = robotStateComponent->getSynchronizedRobot();
144  for (DummyObject const& object : dummyObjects)
145  {
146  if (std::find(classes.begin(), classes.end(), object.name) == classes.end())
147  {
148  continue;
149  }
150 
151 
152  armarx::FramedPosePtr poseInRootFrame = object.pose->toRootFrame(robot);
153  memoryx::ObjectLocalizationResult localizedObject;
154 
155  localizedObject.objectClassName = object.name;
156  ARMARX_INFO << "Reporting: " << object.name << " at " << poseInRootFrame->output();
157  localizedObject.position = poseInRootFrame->getPosition();
158  localizedObject.orientation = poseInRootFrame->getOrientation();
159 
160  localizedObject.recognitionCertainty = 1.0f;
161 
163 
164  localizedObject.timeStamp = now;
165 
166 
167  result.push_back(localizedObject);
168  }
169 
170  return result;
171  }
172 }
armarx::DummyObjectLocalizer::onExitComponent
void onExitComponent() override
Definition: DummyObjectLocalizer.cpp:123
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:37
armarx::DummyObjectLocalizer::onConnectComponent
void onConnectComponent() override
Definition: DummyObjectLocalizer.cpp:105
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:136
armarx::DummyObjectLocalizer::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: DummyObjectLocalizer.cpp:128
armarx::DummyObjectLocalizer::onDisconnectComponent
void onDisconnectComponent() override
Definition: DummyObjectLocalizer.cpp:117
armarx::TimestampVariant::nowPtr
static TimestampVariantPtr nowPtr()
Definition: TimestampVariant.h:111
armarx::DummyObjectLocalizerPropertyDefinitions
Definition: DummyObjectLocalizer.h:47
IceInternal::Handle< TimestampVariant >
armarx::JSONObject::getJsonValue
const Json::Value & getJsonValue() const
Definition: JSONObject.cpp:93
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:251
DummyObjectLocalizer.h
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::JSONObject::fromString
void fromString(const ::std::string &jsonString, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: JSONObject.cpp:86
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
TimestampVariant.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::DummyObjectLocalizer::onInitComponent
void onInitComponent() override
Definition: DummyObjectLocalizer.cpp:34
ProbabilityMeasures.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle< ::IceProxy::armarx::SharedRobotInterface >
armarx::DummyObject
Definition: DummyObjectLocalizer.h:37
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:111
armarx::DummyObject::name
std::string name
Definition: DummyObjectLocalizer.h:39
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
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:151
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28