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
34namespace 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 {
52 getProperty<std::string>("RobotStateComponentName").getValue());
54
56 getProperty<std::string>("WorkingMemoryName").getValue());
58
59 agentsMemoryPrx = memoryPrx->getAgentInstancesSegment();
61
62 Ice::CommunicatorPtr iceCommunicator = getIceManager()->getCommunicator();
63
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
73 Eigen::Matrix3f I = Eigen::Matrix3f::Identity();
75 robotPos = new armarx::FramedPosition(Eigen::Vector3f(0, 0, 0), armarx::GlobalFrame, "");
77
78 lastUpdateTime = IceUtil::Time::now();
79 }
80
81 void
85
86 void
90
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();
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 {
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
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)
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
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.