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
24
25#include <fstream>
26#include <sstream>
27
31
33
34namespace 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
118 getProperty<std::string>("RobotStateComponentName").getValue());
119 }
120
121 void
125
126 void
130
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
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
memoryx::ObjectLocalizationResultList localizeObjectClasses(const memoryx::ObjectClassNameList &classes, const Ice::Current &) override
The FramedPose class.
Definition FramedPose.h:281
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition JSONObject.h:44
const Json::Value & getJsonValue() const
void fromString(const ::std::string &jsonString, const ::Ice::Current &=Ice::emptyCurrent) override
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
static TimestampVariantPtr nowPtr()
static MultivariateNormalDistributionPtr CreateDefaultDistribution(float variance=10000)
Create a distribution with uncertainty of variance in all directions (default: variance = 10000,...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
Definition FramedPose.h:59
IceInternal::Handle< TimestampVariant > TimestampVariantPtr
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272