SelfLocalizationDynamicSimulation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2013-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 ArmarXSimulation
19  * @author Nikolaus Vahrenkamp
20  * @author Fabian Reister
21  * @date 2014
22  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
23  * GNU General Public License
24  */
25 
27 
28 // Robot API
29 #include <IceUtil/Time.h>
32 
33 namespace armarx
34 {
35 
37  {
39 
40  defs->component(simulatorProxy);
41 
42  defs->optional(p.cycleTime, "cycleTime");
43  defs->required(p.robotName, "RobotName");
44 
45  return defs;
46  }
47 
49  {
51 
52  ARMARX_CHECK(simulatorProxy->hasRobot(p.robotName))
53  << "Robot with given name not available in armarx simulator: " + p.robotName;
54 
55  ARMARX_INFO << "Using robot with name " << p.robotName;
56 
57  // periodic task setup
58  if (execTask)
59  {
60  execTask->stop();
61  }
62 
64  this,
65  &SelfLocalizationDynamicSimulation::reportRobotPose,
66  p.cycleTime,
67  false,
68  "SelfLocalizationDynamicSimulationCalculation");
69  execTask->start();
70  execTask->setDelayWarningTolerance(100);
71  }
72 
74  {
76 
77  ARMARX_INFO << "Disconnect...";
78  if (execTask)
79  {
80  execTask->stop();
81  }
82  }
83 
84  void SelfLocalizationDynamicSimulation::reportRobotPose()
85  {
86  try
87  {
88  std::unique_lock lock(dataMutex);
89 
90  const Eigen::Affine3f globalPose = [&]() -> Eigen::Affine3f
91  {
92  const PoseBasePtr poseBase = simulatorProxy->getRobotPose(p.robotName);
93 
94  if (not poseBase)
95  {
96  ARMARX_WARNING << deactivateSpam(10) << "No robot pose from simulator...";
98  }
99 
100  return Eigen::Affine3f(PosePtr::dynamicCast(poseBase)->toEigen());
101  }();
102 
103  // world and map are identical
104  const PoseStamped mapPose{.pose = globalPose, .timestamp = Clock::Now()};
105 
106  TimeUtil::SleepMS(50);
107 
108  publishSelfLocalization(mapPose);
109 
110  // ARMARX_INFO << deactivateSpam(0.1) << globalPose.translation();
111  }
112  catch (...)
113  {
115  << "Could not update robot pose in agents segment...\n"
117  }
118  }
119 
120 } // namespace armarx
armarx::SelfLocalization::onDisconnectComponent
void onDisconnectComponent() override
Definition: SelfLocalization.cpp:142
armarx::SelfLocalization::publishSelfLocalization
void publishSelfLocalization(const PoseStamped &map_T_robot)
Definition: SelfLocalization.cpp:96
armarx::viz::toEigen
Eigen::Matrix4f toEigen(data::GlobalPose const &pose)
Definition: Interaction.h:46
armarx::SelfLocalizationDynamicSimulation::execTask
PeriodicTask< SelfLocalizationDynamicSimulation >::pointer_type execTask
Definition: SelfLocalizationDynamicSimulation.h:74
armarx::SelfLocalizationDynamicSimulation::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SelfLocalizationDynamicSimulation.cpp:36
Pose.h
SelfLocalizationDynamicSimulation.h
armarx::SelfLocalization::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SelfLocalization.cpp:39
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
Clock.h
armarx::GetHandledExceptionString
std::string GetHandledExceptionString()
Definition: Exception.cpp:147
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::SelfLocalizationDynamicSimulation::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: SelfLocalizationDynamicSimulation.cpp:73
armarx::TimeUtil::SleepMS
static void SleepMS(float milliseconds)
Definition: TimeUtil.h:195
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::SelfLocalizationDynamicSimulation::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: SelfLocalizationDynamicSimulation.cpp:48
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::core::time::Clock::Now
static DateTime Now()
Current time on the virtual clock.
Definition: Clock.cpp:97
armarx::Logging::deactivateSpam
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:92
armarx::PeriodicTask
Definition: ArmarXManager.h:70
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::SelfLocalization::onConnectComponent
void onConnectComponent() override
Definition: SelfLocalization.cpp:491
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28