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