RobotHandLocalizationDynamicSimulation.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2013-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package VisionX::Component
19 * @author David Schiebener (schiebener at kit dot edu)
20 * @date 2013
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27// Core
30
33
34// MemoryX
36
37using namespace armarx;
38using namespace memoryx;
39using namespace memoryx::EntityWrappers;
40
41
43
44void
46{
47 usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
48 tcpNameLeft = getProperty<std::string>("TCPNameLeft").getValue();
49 tcpNameRight = getProperty<std::string>("TCPNameRight").getValue();
50 referenceFrame = getProperty<std::string>("ReferenceFrameName").getValue();
51
52 std::string simPrxName = getProperty<std::string>("SimulatorName").getValue();
53
54 if (!simPrxName.empty())
55 {
56 usingProxy(simPrxName);
57 }
58}
59
60void
62{
63 ARMARX_VERBOSE << "onConnect";
64
65 try
66 {
67 RobotStateComponentInterfacePrx robotStateComponent =
69 getProperty<std::string>("RobotStateComponentName").getValue());
70 remoteRobot.reset(new RemoteRobot(robotStateComponent->getSynchronizedRobot()));
71
72 std::string simPrxName = getProperty<std::string>("SimulatorName").getValue();
73
74 if (!simPrxName.empty())
75 {
76 simulatorProxy = getProxy<SimulatorInterfacePrx>(simPrxName);
77 }
78
79
80 // check nodes
81 VirtualRobot::RobotNodePtr rn = remoteRobot->getRobotNode(referenceFrame);
82 ARMARX_CHECK_EXPRESSION(rn) << "Reference frame not present in remote robot!";
83 rn = remoteRobot->getRobotNode(tcpNameLeft);
84 ARMARX_CHECK_EXPRESSION(rn) << "tcpNameLeft frame not present in remote robot!";
85 rn = remoteRobot->getRobotNode(tcpNameRight);
86 ARMARX_CHECK_EXPRESSION(rn) << "tcpNameRight frame not present in remote robot!";
87 }
88 catch (...)
89 {
91 }
92}
93
94void
96{
97 ARMARX_VERBOSE << "onDisConnect";
98
99 try
100 {
101 remoteRobot.reset();
102 simulatorProxy = nullptr;
103 }
104 catch (...)
105 {
107 }
108}
109
110bool
112 const memoryx::EntityPtr& objectClassEntity,
113 const memoryx::GridFileManagerPtr& fileManager)
114{
115 ARMARX_VERBOSE << "Adding object class " << objectClassEntity->getName() << armarx::flush;
116
117 return true;
118}
119
120memoryx::ObjectLocalizationResultList
122 const ::memoryx::ObjectClassNameList& objectClassNames,
123 const ::Ice::Current&)
124{
125 ARMARX_DEBUG << "localizeObjectClasses() started";
127 bool firstEntryIsLeft = objectClassNames.at(0).find("left") != std::string::npos ||
128 objectClassNames.at(0).find("Left") != std::string::npos;
129
130 auto agentName = remoteRobot->getName();
131 PosePtr rnPoseLeft =
132 simulatorProxy
133 ? PosePtr::dynamicCast(simulatorProxy->getRobotNodePose(agentName, tcpNameLeft))
134 : new Pose(remoteRobot->getRobotNode(tcpNameLeft)->getGlobalPose());
135 PosePtr rnPoseRight =
136 simulatorProxy
137 ? PosePtr::dynamicCast(simulatorProxy->getRobotNodePose(agentName, tcpNameRight))
138 : new Pose(remoteRobot->getRobotNode(tcpNameRight)->getGlobalPose());
139 Eigen::Matrix4f tcpLeftGlobalPose = rnPoseLeft->toEigen();
140 Eigen::Matrix4f tcpRightGlobalPose = rnPoseRight->toEigen();
141 //Eigen::Matrix4f cameraPose = remoteRobot->getRobotNode(referenceFrame)->getPoseInRootFrame();
142 // convert all poses to reference frame/camera coordinates
143 Eigen::Matrix4f cameraPose =
144 simulatorProxy
145 ? PosePtr::dynamicCast(simulatorProxy->getRobotNodePose(agentName, referenceFrame))
146 ->toEigen()
147 : remoteRobot->getRobotNode(referenceFrame)->getGlobalPose();
148 tcpLeftGlobalPose = cameraPose.inverse() * tcpLeftGlobalPose;
149 tcpRightGlobalPose = cameraPose.inverse() * tcpRightGlobalPose;
150
151 armarx::FramedPositionPtr positionLeftHand =
152 new armarx::FramedPosition(tcpLeftGlobalPose, referenceFrame, agentName);
153 armarx::FramedPositionPtr positionRightHand =
154 new armarx::FramedPosition(tcpRightGlobalPose, referenceFrame, agentName);
155 armarx::FramedOrientationPtr orientationLeftHand =
156 new armarx::FramedOrientation(tcpLeftGlobalPose, referenceFrame, agentName);
157 armarx::FramedOrientationPtr orientationRightHand =
158 new armarx::FramedOrientation(tcpRightGlobalPose, referenceFrame, agentName);
159
160 // get poses of hands and markers
161 /*Eigen::Matrix4f leftHandPose = remoteRobot->getRobotNode(tcpNameLeft)->getPoseInRootFrame();
162 Eigen::Matrix4f rightHandPose = remoteRobot->getRobotNode(tcpNameRight)->getPoseInRootFrame();
163 Eigen::Matrix4f leftMarkerPose = remoteRobot->getRobotNode(markerNameLeft)->getPoseInRootFrame();
164 Eigen::Matrix4f rightMarkerPose = remoteRobot->getRobotNode(markerNameRight)->getPoseInRootFrame();*/
165
166 // return poses from simulator
167 memoryx::ObjectLocalizationResult result;
168 result.timeStamp = timestamp;
169
170 memoryx::ObjectLocalizationResultList resultList;
171 result.recognitionCertainty = 1;
172
173 if (objectClassNames.size() == 1)
174 {
175 ARMARX_DEBUG << "Returning hand pose from simulator for one hand: "
176 << objectClassNames.at(0);
177
178 result.objectClassName = objectClassNames.at(0);
179
180 if (firstEntryIsLeft)
181 {
182 result.position = positionLeftHand;
183 result.orientation = orientationLeftHand;
184
185 result.positionNoise = computePositionNoise(positionLeftHand->toEigen());
186 }
187 else
188 {
189 result.position = positionRightHand;
190 result.orientation = orientationRightHand;
191 result.positionNoise = computePositionNoise(positionRightHand->toEigen());
192 }
193 resultList.push_back(result);
194 }
195 else if (objectClassNames.size() == 2)
196 {
197 ARMARX_INFO << "Returning hand pose from simulator for two hands: "
198 << objectClassNames.at(0) << ", " << objectClassNames.at(1);
199
200 result.objectClassName = firstEntryIsLeft ? objectClassNames.at(0) : objectClassNames.at(1);
201 result.position = positionLeftHand;
202 result.orientation = orientationLeftHand;
203 result.positionNoise = computePositionNoise(positionLeftHand->toEigen());
204 resultList.push_back(result);
205
206 result.objectClassName = firstEntryIsLeft ? objectClassNames.at(1) : objectClassNames.at(0);
207 result.position = positionRightHand;
208 result.orientation = orientationRightHand;
209 result.positionNoise = computePositionNoise(positionRightHand->toEigen());
210 resultList.push_back(result);
211 }
212 else
213 {
214 ARMARX_WARNING << "More than 2 hands requested - this case is not handeled here";
215 }
216
217
218 ARMARX_DEBUG << "Finished localization, returning.";
219
220 return resultList;
221}
222
224RobotHandLocalizationDynamicSimulation::computePositionNoise(const Eigen::Vector3f& pos)
225{
227 mean.push_back(pos(0));
228 mean.push_back(pos(1));
229 mean.push_back(pos(2));
230
231 // assuming 2 mm noise
233 posDist->setMean(mean);
234 posDist->setCovariance(0, 0, 2.0f);
235 posDist->setCovariance(1, 1, 2.0f);
236 posDist->setCovariance(2, 2, 2.0f);
237 return posDist;
238}
std::string timestamp()
Property< PropertyType > getProperty(const std::string &name)
The FramedOrientation class.
Definition FramedPose.h:216
The FramedPosition class.
Definition FramedPose.h:158
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)
The Pose class.
Definition Pose.h:243
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
void onInitComponent() override
Pure virtual hook for the subclass.
virtual bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager)
Add a memory entity representing the hand marker in order to set its properties.
memoryx::ObjectLocalizationResultList localizeObjectClasses(const ::memoryx::ObjectClassNameList &, const ::Ice::Current &=Ice::emptyCurrent) override
localize one or both hand markers
void onConnectComponent() override
Pure virtual hook for the subclass.
static TimestampVariantPtr nowPtr()
The MultivariateNormalDistribution class.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::optional< float > mean(const boost::circular_buffer< NameValueMap > &buffer, const std::string &key)
::std::vector<::Ice::Float > FloatVector
void handleExceptions()
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
Definition FramedPose.h:207
const LogSender::manipulator flush
Definition LogSender.h:251
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
IceInternal::Handle< TimestampVariant > TimestampVariantPtr
VirtualRobot headers.
IceInternal::Handle< MultivariateNormalDistribution > MultivariateNormalDistributionPtr
IceInternal::Handle< Entity > EntityPtr
Typedef of EntityPtr as IceInternal::Handle<Entity> for convenience.
Definition Entity.h:45
std::shared_ptr< GridFileManager > GridFileManagerPtr