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
32
34
35namespace armarx
36{
37 std::string
39 {
40 return "DummyObjectLocalizer";
41 }
42
43 void
45 {
46 std::setlocale(LC_ALL, "En_US");
47
48 std::string objectPoseFile = getProperty<std::string>("ObjectPoseFile").getValue();
49 if (!armarx::ArmarXDataPath::getAbsolutePath(objectPoseFile, objectPoseFile))
50 {
51 ARMARX_ERROR << "Could not find object pose file file in ArmarXDataPath: "
52 << objectPoseFile;
53 return;
54 }
55
56 std::stringstream fileContent;
57 try
58 {
59 std::ifstream input;
60 input.exceptions(std::ifstream::failbit | std::ifstream::badbit);
61 input.open(objectPoseFile, std::ios::binary);
62 fileContent << input.rdbuf();
63 }
64 catch (std::exception const& ex)
65 {
66 ARMARX_WARNING << "Could not open or read from file: " << objectPoseFile;
67 }
68
69 ARMARX_INFO << "File content: " << fileContent.str();
70
72 o.fromString(fileContent.str());
73 const Json::Value& j = o.getJsonValue();
74
75 std::vector<std::string> objectNames = j.getMemberNames();
76
77 for (std::string const& objectName : objectNames)
78 {
79 ARMARX_INFO << "Object name: " << objectName;
80 DummyObject object;
81 object.name = objectName;
82
83 Json::Value map = j.get(objectName, Json::Value::null);
84 std::string encodedPose = map["pose"].asString();
85 std::string frame = map["frame"].asString();
86 std::string agent = map["agent"].asString();
87
88 std::istringstream poseInput(encodedPose);
89 Eigen::Matrix4f pose;
90 for (int row = 0; row < 4; ++row)
91 {
92 for (int column = 0; column < 4; ++column)
93 {
94 float value;
95 if (poseInput >> value)
96 {
97 pose.col(column)[row] = value;
98 }
99 else
100 {
101 ARMARX_WARNING << "Failed to read float: " << poseInput.str();
102 }
103 }
104 }
105
106 object.pose = new armarx::FramedPose(pose, frame, agent);
107
108 dummyObjects.push_back(object);
109 }
110
111
112 usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
113 }
114
115 void
117 {
118 for (DummyObject const& object : dummyObjects)
119 {
120 ARMARX_INFO << "Object '" << object.name << "': " << *object.pose;
121 }
122
123
125 getProperty<std::string>("RobotStateComponentName").getValue());
126 }
127
128 void
132
133 void
137
144
145 memoryx::ObjectLocalizationResultList
146 armarx::DummyObjectLocalizer::localizeObjectClasses(const memoryx::ObjectClassNameList& classes,
147 const Ice::Current&)
148 {
149 memoryx::ObjectLocalizationResultList result;
150 result.reserve(dummyObjects.size());
151
152
153 armarx::SharedRobotInterfacePrx robot = robotStateComponent->getSynchronizedRobot();
155 for (DummyObject const& object : dummyObjects)
156 {
157 if (std::find(classes.begin(), classes.end(), object.name) == classes.end())
158 {
159 continue;
160 }
161
162
163 armarx::FramedPosePtr poseInRootFrame = object.pose->toRootFrame(robot);
164 memoryx::ObjectLocalizationResult localizedObject;
165
166 localizedObject.objectClassName = object.name;
167 ARMARX_INFO << "Reporting: " << object.name << " at " << poseInRootFrame->output();
168 localizedObject.position = poseInRootFrame->getPosition();
169 localizedObject.orientation = poseInRootFrame->getOrientation();
170
171 localizedObject.recognitionCertainty = 1.0f;
172
173 localizedObject.positionNoise =
175
176 localizedObject.timeStamp = now;
177
178
179 result.push_back(localizedObject);
180 }
181
182 return result;
183 }
184} // namespace armarx
185
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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)
Brief description of class DummyObjectLocalizer.
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