KinematicSelfLocalization.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXSimulation::ArmarXObjects::KinematicSelfLocalization
17 * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
18 * @date 2016
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
26
27#include <Eigen/Geometry>
28
29#include <SimoxUtility/math/convert/rpy_to_mat3f.h>
30
32#include <RobotAPI/interface/core/GeometryBase.h>
33
36
37using namespace armarx;
38
39void
41{
42 usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
43
44 usingProxy(getProperty<std::string>("WorkingMemoryName").getValue());
45 usingTopic(getProperty<std::string>("PlatformTopicName").getValue());
46}
47
48void
50{
52 getProperty<std::string>("RobotStateComponentName").getValue());
54 ARMARX_INFO << "Retrieved robot state proxy...";
55
57 getProperty<std::string>("WorkingMemoryName").getValue());
59 ARMARX_INFO << "Retrieved WM proxy...";
60
61 agentsMemoryPrx = memoryPrx->getAgentInstancesSegment();
63 ARMARX_INFO << "Retrieved WM agent segment ...";
64
65 Ice::CommunicatorPtr iceCommunicator = getIceManager()->getCommunicator();
66
67 robotName = getProperty<std::string>("RobotName").getValue();
69 getProperty<float>("RobotPoseZ").isSet() ? getProperty<float>("RobotPoseZ").getValue() : 0;
70
71 std::string agentName = getProperty<std::string>("AgentName").isSet()
72 ? getProperty<std::string>("AgentName").getValue()
73 : robotName;
74
75
76 ARMARX_INFO << "Creating robot agent with name " << agentName;
77 robotAgent = new memoryx::AgentInstance(agentName);
78 auto robot = robotStateComponentPrx->getSynchronizedRobot();
79 robotAgent->setSharedRobot(robot);
80 robotAgent->setName(agentName);
81 robotAgent->setStringifiedSharedRobotInterfaceProxy(iceCommunicator->proxyToString(robot));
82 robotAgent->setAgentFilePath(robotStateComponentPrx->getRobotFilename());
83 ARMARX_INFO << "Creating robot agent...done";
84
85 // Simulating platform movement to initial pose
86 Eigen::Isometry3f global_T_robot_initial = Eigen::Isometry3f::Identity();
87 global_T_robot_initial.translation().x() =
88 getProperty<float>("InitialPlatformPoseX").getValue();
89 global_T_robot_initial.translation().y() =
90 getProperty<float>("InitialPlatformPoseY").getValue();
91 global_T_robot_initial.linear() =
92 simox::math::rpy_to_mat3f(0, 0, getProperty<float>("InitialPlatformPoseAngle").getValue());
93
94 TransformStamped transformStamped;
95 transformStamped.transform = global_T_robot_initial.matrix();
96 transformStamped.header.agent = agentName;
97 transformStamped.header.frame = GlobalFrame;
98 transformStamped.header.timestampInMicroSeconds = TimeUtil::GetTime().toMicroSeconds();
99
100 reportGlobalRobotPose(transformStamped);
101
102 // periodic task setup
103 cycleTime = 30;
104
105 if (execTask)
106 {
107 execTask->stop();
108 }
109
110 execTask =
113 cycleTime,
114 false,
115 "KinematicSelfLocalizationCalculation");
116 execTask->start();
117 execTask->setDelayWarningTolerance(100);
118}
119
120void
125
126void
130
137
138void
140{
141 try
142 {
143 std::unique_lock lock(dataMutex);
144 ARMARX_DEBUG << "Reporting robot agent:" << robotAgent->getName()
145 << ", robotAgentId:" << robotAgentId << ", self:" << this->getName();
146
147
148 if (!currentRobotPose)
149 {
150 return;
151 }
153
154 robotAgentId = agentsMemoryPrx->upsertEntityByName(robotAgent->getName(), robotAgent);
155 robotAgent->setId(robotAgentId);
156 }
157 catch (...)
158 {
159 ARMARX_WARNING << deactivateSpam(10) << "Could not update robot pose in agents segment...\n"
161 robotAgentId.clear();
162 }
163}
164
165void
166KinematicSelfLocalization::reportGlobalRobotPose(const ::armarx::TransformStamped& transformStamped,
167 const ::Ice::Current&)
168{
169 std::unique_lock lock(dataMutex);
170
171 Eigen::Isometry3f global_T_robot(transformStamped.transform);
172 global_T_robot.translation().z() = robotPoseZ; // TODO lecagy. Is this really necessary?
173
174 currentRobotPose = new FramedPose(global_T_robot.matrix(), armarx::GlobalFrame, "");
175}
176
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
The FramedPose class.
Definition FramedPose.h:281
Brief description of class KinematicSelfLocalization.
memoryx::WorkingMemoryInterfacePrx memoryPrx
void reportGlobalRobotPose(const ::armarx::TransformStamped &, const ::Ice::Current &=::Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
memoryx::AgentInstancesSegmentBasePrx agentsMemoryPrx
PeriodicTask< KinematicSelfLocalization >::pointer_type execTask
RobotStateComponentInterfacePrx robotStateComponentPrx
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition Logging.cpp:99
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
std::string getName() const
Retrieve name of object.
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)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition TimeUtil.cpp:42
#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
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.
std::string GetHandledExceptionString()
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.