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 
27 #include <Eigen/LU>
28 
31 
33 
34 namespace armarx
35 {
36  void
38  {
39  currentVelocity.setZero();
40  poseBuffer.reserve(300);
41 
42  usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
43  usingProxy(getProperty<std::string>("WorkingMemoryName").getValue());
44 
45  offeringTopic(getProperty<std::string>("PlatformStateTopicName").getValue());
46  }
47 
48  void
50  {
51  robotStateComponentPrx = getProxy<armarx::RobotStateComponentInterfacePrx>(
52  getProperty<std::string>("RobotStateComponentName").getValue());
54 
55  memoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>(
56  getProperty<std::string>("WorkingMemoryName").getValue());
58 
59  agentsMemoryPrx = memoryPrx->getAgentInstancesSegment();
61 
62  Ice::CommunicatorPtr iceCommunicator = getIceManager()->getCommunicator();
63 
64  platformTopic = getTopic<PlatformUnitListenerPrx>(
65  getProperty<std::string>("PlatformStateTopicName").getValue());
66 
68  auto robot = robotStateComponentPrx->getSynchronizedRobot();
69  robotAgent->setSharedRobot(robot);
70  robotAgent->setStringifiedSharedRobotInterfaceProxy(iceCommunicator->proxyToString(robot));
71  robotAgent->setAgentFilePath(robotStateComponentPrx->getRobotFilename());
72 
75  robotPos = new armarx::FramedPosition(Eigen::Vector3f(0, 0, 0), armarx::GlobalFrame, "");
77 
78  lastUpdateTime = IceUtil::Time::now();
79  }
80 
81  void
83  {
84  }
85 
86  void
88  {
89  }
90 
93  {
96  }
97 
98  // void armarx::DummyAgentReporter::reportPlatformPose(PlatformPose const& currentPose, const Ice::Current&)
99  // {
100  // float x = currentPose.x;
101  // float y = currentPose.y;
102  // float alpha = currentPose.rotationAroundZ;
103  // // needed for Mean_of_circular_quantities
104  // if (alpha > M_PI)
105  // {
106  // alpha = - 2 * M_PI + alpha;
107  // }
108 
109  // ARMARX_DEBUG << deactivateSpam(1) << "received new platform pose: " << VAROUT(x) << VAROUT(y) << VAROUT(alpha);
110 
111  // {
112  // std::scoped_lock lock(dataMutex);
113 
114  // // rotation stored for Mean_of_circular_quantities
115  // // http://en.wikipedia.org/wiki/Mean_of_circular_quantities
116  // Eigen::Vector4d pose2d;
117  // pose2d << x, y, sin(alpha), cos(alpha);
118 
119  // Eigen::Matrix3f ori;
120  // ori.setIdentity();
121  // ori = Eigen::AngleAxisf(alpha, Eigen::Vector3f::UnitZ());
122 
123  // Eigen::Vector3f pos;
124  // pos[0] = x;
125  // pos[1] = y;
126  // pos[2] = 0;
127  // if (alpha < 0)
128  // {
129  // alpha += 2 * M_PI;
130  // }
131 
132  // PlatformPose newPose;
133  // newPose.timestampInMicroSeconds = armarx::TimeUtil::GetTime().toMicroSeconds();
134  // newPose.x = x;
135  // newPose.y = y;
136  // newPose.rotationAroundZ = alpha;
137  // // platformTopic->reportPlatformPose(newPose);
138 
139  // robotOri = new armarx::FramedOrientation(ori, armarx::GlobalFrame, "");
140  // robotPos = new armarx::FramedPosition(pos, armarx::GlobalFrame, "");
141  // }
142 
143  // reportRobotPose();
144  // }
145 
146 
147  void
149  Ice::Float y,
150  Ice::Float alpha,
151  const Ice::Current&)
152  {
153  std::scoped_lock lock(dataMutex);
154 
155  currentVelocity << x, y, sin(alpha), cos(alpha) - 1;
156  auto delay = IceUtil::Time::now() - lastUpdateTime;
157 
158  ARMARX_DEBUG << deactivateSpam(1) << "New platform speed received: " << VAROUT(x)
159  << VAROUT(y) << VAROUT(alpha) << " with delay of " << delay.toSecondsDouble();
160 
161  lastUpdateTime = IceUtil::Time::now();
162  velocityDeltaUpdateCount++;
163  velocityDeltaSum += delay.toSecondsDouble();
164 
165  platformTopic->reportPlatformVelocity(x, y, alpha);
166  }
167 
168  void
170  {
171  std::scoped_lock lock(dataMutex);
172 
173  if (!robotOri && !robotPos)
174  {
175  return;
176  }
177  if (!robotAgent)
178  {
179  return;
180  }
181 
182  try
183  {
184  robotAgent->setOrientation(robotOri);
185  robotAgent->setPosition(robotPos);
186 
187  if (robotAgentId.empty() || !agentsMemoryPrx->hasEntityById(robotAgentId))
188  {
190  ARMARX_INFO << "Agent created";
191  }
192  else
193  {
194  agentsMemoryPrx->updateEntity(robotAgentId, robotAgent);
195  ARMARX_INFO << "Agent updated";
196  }
197  }
198  catch (std::exception& e)
199  {
201  }
202  }
203 
204  void
206  Ice::Float y,
207  Ice::Float alpha,
208  const Ice::Current&)
209  {
210  platformTopic->reportPlatformOdometryPose(x, y, alpha);
211  }
212 } // namespace armarx
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:366
armarx::DummyAgentReporter::reportRobotPose
void reportRobotPose()
Definition: DummyAgentReporter.cpp:169
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::DummyAgentReporter::robotAgent
memoryx::AgentInstancePtr robotAgent
Definition: DummyAgentReporter.h:117
armarx::DummyAgentReporter::onDisconnectComponent
void onDisconnectComponent() override
Definition: DummyAgentReporter.cpp:82
Pose.h
armarx::GlobalFrame
const std::string GlobalFrame
Definition: FramedPose.h:65
armarx::DummyAgentReporterPropertyDefinitions
Definition: DummyAgentReporter.h:43
armarx::DummyAgentReporter::dataMutex
std::mutex dataMutex
Definition: DummyAgentReporter.h:124
armarx::DummyAgentReporter::robotPos
armarx::FramedPositionPtr robotPos
Definition: DummyAgentReporter.h:121
armarx::DummyAgentReporter::onExitComponent
void onExitComponent() override
Definition: DummyAgentReporter.cpp:87
IceInternal::Handle<::Ice::Communicator >
armarx::DummyAgentReporter::onInitComponent
void onInitComponent() override
Definition: DummyAgentReporter.cpp:37
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:75
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
armarx::DummyAgentReporter::currentVelocity
Eigen::Vector4d currentVelocity
Definition: DummyAgentReporter.h:126
armarx::DummyAgentReporter::reportPlatformVelocity
void reportPlatformVelocity(Ice::Float x, Ice::Float y, Ice::Float alpha, const Ice::Current &) override
Definition: DummyAgentReporter.cpp:148
armarx::DummyAgentReporter::poseBuffer
std::vector< Eigen::Vector4d > poseBuffer
Definition: DummyAgentReporter.h:125
armarx::DummyAgentReporter::onConnectComponent
void onConnectComponent() override
Definition: DummyAgentReporter.cpp:49
armarx::DummyAgentReporter::robotStateComponentPrx
armarx::RobotStateComponentInterfacePrx robotStateComponentPrx
Definition: DummyAgentReporter.h:113
armarx::DummyAgentReporter::robotAgentId
std::string robotAgentId
Definition: DummyAgentReporter.h:119
ExpressionException.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::DummyAgentReporter::agentsMemoryPrx
memoryx::AgentInstancesSegmentBasePrx agentsMemoryPrx
Definition: DummyAgentReporter.h:116
armarx::VariantType::FramedOrientation
const VariantTypeId FramedOrientation
Definition: FramedPose.h:39
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::DummyAgentReporter::memoryPrx
memoryx::WorkingMemoryInterfacePrx memoryPrx
Definition: DummyAgentReporter.h:115
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:198
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
IceUtil::Handle< class PropertyDefinitionContainer >
DummyAgentReporter.h
memoryx::AgentInstance
Definition: AgentInstance.h:45
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:38
armarx::handleExceptions
void handleExceptions()
Definition: Exception.cpp:157
armarx::DummyAgentReporter::lastUpdateTime
IceUtil::Time lastUpdateTime
Definition: DummyAgentReporter.h:127
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::DummyAgentReporter::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: DummyAgentReporter.cpp:92
armarx::DummyAgentReporter::robotOri
armarx::FramedOrientationPtr robotOri
Definition: DummyAgentReporter.h:122
armarx::DummyAgentReporter::reportPlatformOdometryPose
void reportPlatformOdometryPose(Ice::Float x, Ice::Float y, Ice::Float alpha, const Ice::Current &) override
Definition: DummyAgentReporter.cpp:205
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:154
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::DummyAgentReporter::platformTopic
PlatformUnitListenerPrx platformTopic
Definition: DummyAgentReporter.h:129