DummyAgentReporter.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-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 MemoryX::ArmarXObjects::DummyAgentReporter
19 * @author Peter Kaiser ( peter dot kaiser at kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#include "DummyAgentReporter.h"
26
28
29#include <Eigen/LU>
30
33
35
36namespace armarx
37{
38 void
40 {
41 currentVelocity.setZero();
42 poseBuffer.reserve(300);
43
44 usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
45 usingProxy(getProperty<std::string>("WorkingMemoryName").getValue());
46
47 offeringTopic(getProperty<std::string>("PlatformStateTopicName").getValue());
48 }
49
50 void
52 {
54 getProperty<std::string>("RobotStateComponentName").getValue());
56
58 getProperty<std::string>("WorkingMemoryName").getValue());
60
61 agentsMemoryPrx = memoryPrx->getAgentInstancesSegment();
63
64 Ice::CommunicatorPtr iceCommunicator = getIceManager()->getCommunicator();
65
67 getProperty<std::string>("PlatformStateTopicName").getValue());
68
70 auto robot = robotStateComponentPrx->getSynchronizedRobot();
71 robotAgent->setSharedRobot(robot);
72 robotAgent->setStringifiedSharedRobotInterfaceProxy(iceCommunicator->proxyToString(robot));
73 robotAgent->setAgentFilePath(robotStateComponentPrx->getRobotFilename());
74
75 Eigen::Matrix3f I = Eigen::Matrix3f::Identity();
77 robotPos = new armarx::FramedPosition(Eigen::Vector3f(0, 0, 0), armarx::GlobalFrame, "");
79
80 lastUpdateTime = IceUtil::Time::now();
81 }
82
83 void
87
88 void
92
99
100 // void armarx::DummyAgentReporter::reportPlatformPose(PlatformPose const& currentPose, const Ice::Current&)
101 // {
102 // float x = currentPose.x;
103 // float y = currentPose.y;
104 // float alpha = currentPose.rotationAroundZ;
105 // // needed for Mean_of_circular_quantities
106 // if (alpha > M_PI)
107 // {
108 // alpha = - 2 * M_PI + alpha;
109 // }
110
111 // ARMARX_DEBUG << deactivateSpam(1) << "received new platform pose: " << VAROUT(x) << VAROUT(y) << VAROUT(alpha);
112
113 // {
114 // std::scoped_lock lock(dataMutex);
115
116 // // rotation stored for Mean_of_circular_quantities
117 // // http://en.wikipedia.org/wiki/Mean_of_circular_quantities
118 // Eigen::Vector4d pose2d;
119 // pose2d << x, y, sin(alpha), cos(alpha);
120
121 // Eigen::Matrix3f ori;
122 // ori.setIdentity();
123 // ori = Eigen::AngleAxisf(alpha, Eigen::Vector3f::UnitZ());
124
125 // Eigen::Vector3f pos;
126 // pos[0] = x;
127 // pos[1] = y;
128 // pos[2] = 0;
129 // if (alpha < 0)
130 // {
131 // alpha += 2 * M_PI;
132 // }
133
134 // PlatformPose newPose;
135 // newPose.timestampInMicroSeconds = armarx::TimeUtil::GetTime().toMicroSeconds();
136 // newPose.x = x;
137 // newPose.y = y;
138 // newPose.rotationAroundZ = alpha;
139 // // platformTopic->reportPlatformPose(newPose);
140
141 // robotOri = new armarx::FramedOrientation(ori, armarx::GlobalFrame, "");
142 // robotPos = new armarx::FramedPosition(pos, armarx::GlobalFrame, "");
143 // }
144
145 // reportRobotPose();
146 // }
147
148
149 void
151 Ice::Float y,
152 Ice::Float alpha,
153 const Ice::Current&)
154 {
155 std::scoped_lock lock(dataMutex);
156
157 currentVelocity << x, y, sin(alpha), cos(alpha) - 1;
158 auto delay = IceUtil::Time::now() - lastUpdateTime;
159
160 ARMARX_DEBUG << deactivateSpam(1) << "New platform speed received: " << VAROUT(x)
161 << VAROUT(y) << VAROUT(alpha) << " with delay of " << delay.toSecondsDouble();
162
163 lastUpdateTime = IceUtil::Time::now();
165 velocityDeltaSum += delay.toSecondsDouble();
166
167 platformTopic->reportPlatformVelocity(x, y, alpha);
168 }
169
170 void
172 {
173 std::scoped_lock lock(dataMutex);
174
175 if (!robotOri && !robotPos)
176 {
177 return;
178 }
179 if (!robotAgent)
180 {
181 return;
182 }
183
184 try
185 {
186 robotAgent->setOrientation(robotOri);
187 robotAgent->setPosition(robotPos);
188
189 if (robotAgentId.empty() || !agentsMemoryPrx->hasEntityById(robotAgentId))
190 {
192 ARMARX_INFO << "Agent created";
193 }
194 else
195 {
197 ARMARX_INFO << "Agent updated";
198 }
199 }
200 catch (std::exception& e)
201 {
203 }
204 }
205
206 void
208 Ice::Float y,
209 Ice::Float alpha,
210 const Ice::Current&)
211 {
212 platformTopic->reportPlatformOdometryPose(x, y, alpha);
213 }
214
215 std::string
217 {
218 return "DummyAgentReporter";
219 }
220} // namespace armarx
221
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
#define VAROUT(x)
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 DummyAgentReporter.
memoryx::WorkingMemoryInterfacePrx memoryPrx
armarx::FramedOrientationPtr robotOri
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportPlatformOdometryPose(Ice::Float x, Ice::Float y, Ice::Float alpha, const Ice::Current &) override
memoryx::AgentInstancesSegmentBasePrx agentsMemoryPrx
std::vector< Eigen::Vector4d > poseBuffer
static std::string GetDefaultName()
memoryx::AgentInstancePtr robotAgent
armarx::FramedPositionPtr robotPos
armarx::RobotStateComponentInterfacePrx robotStateComponentPrx
void reportPlatformVelocity(Ice::Float x, Ice::Float y, Ice::Float alpha, const Ice::Current &) override
PlatformUnitListenerPrx platformTopic
The FramedOrientation class.
Definition FramedPose.h:216
The FramedPosition class.
Definition FramedPose.h:158
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
#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
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
Definition IceManager.h:49
This file offers overloads of toIce() and fromIce() functions for STL container types.
void handleExceptions()
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.