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>
30 
32 
34 
35 namespace armarx
36 {
37 
40  {
42 
43  defs->component(simulatorProxy);
44 
45  defs->optional(p.cycleTime, "cycleTime");
46  defs->required(p.robotName, "RobotName");
47 
48  return defs;
49  }
50 
51  void
53  {
55 
56  ARMARX_CHECK(simulatorProxy->hasRobot(p.robotName))
57  << "Robot with given name not available in armarx simulator: " + p.robotName;
58 
59  ARMARX_INFO << "Using robot with name " << p.robotName;
60 
61  // periodic task setup
62  if (execTask)
63  {
64  execTask->stop();
65  }
66 
68  this,
69  &SelfLocalizationDynamicSimulation::reportRobotPose,
70  p.cycleTime,
71  false,
72  "SelfLocalizationDynamicSimulationCalculation");
73  execTask->start();
74  execTask->setDelayWarningTolerance(100);
75  }
76 
77  void
79  {
81 
82  ARMARX_INFO << "Disconnect...";
83  if (execTask)
84  {
85  execTask->stop();
86  }
87  }
88 
89  void
90  SelfLocalizationDynamicSimulation::reportRobotPose()
91  {
92  try
93  {
94  std::unique_lock lock(dataMutex);
95 
96  const Eigen::Isometry3f globalPose = [&]() -> Eigen::Isometry3f
97  {
98  const PoseBasePtr poseBase = simulatorProxy->getRobotPose(p.robotName);
99 
100  if (not poseBase)
101  {
102  ARMARX_WARNING << deactivateSpam(10) << "No robot pose from simulator...";
104  }
105 
106  return Eigen::Isometry3f(PosePtr::dynamicCast(poseBase)->toEigen());
107  }();
108 
109  // world and map are identical
110  const PoseStamped mapPose{.pose = globalPose, .timestamp = Clock::Now()};
111 
112  TimeUtil::SleepMS(50);
113 
114  publishSelfLocalization(mapPose);
115 
116  // ARMARX_INFO << deactivateSpam(0.1) << globalPose.translation();
117  }
118  catch (...)
119  {
121  << "Could not update robot pose in agents segment...\n"
123  }
124  }
125 
126 } // namespace armarx
armarx::SelfLocalization::onDisconnectComponent
void onDisconnectComponent() override
Definition: SelfLocalization.cpp:141
armarx::SelfLocalization::publishSelfLocalization
void publishSelfLocalization(const PoseStamped &map_T_robot)
Definition: SelfLocalization.cpp:95
armarx::SelfLocalizationDynamicSimulation::execTask
PeriodicTask< SelfLocalizationDynamicSimulation >::pointer_type execTask
Definition: SelfLocalizationDynamicSimulation.h:73
armarx::SelfLocalizationDynamicSimulation::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SelfLocalizationDynamicSimulation.cpp:39
Pose.h
SelfLocalizationDynamicSimulation.h
armarx::SelfLocalization::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SelfLocalization.cpp:38
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:165
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::toEigen
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)
Definition: PointToModelICP.h:67
armarx::SelfLocalizationDynamicSimulation::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: SelfLocalizationDynamicSimulation.cpp:78
armarx::TimeUtil::SleepMS
static void SleepMS(float milliseconds)
Definition: TimeUtil.h:203
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::SelfLocalizationDynamicSimulation::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: SelfLocalizationDynamicSimulation.cpp:52
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::core::time::Clock::Now
static DateTime Now()
Current time on the virtual clock.
Definition: Clock.cpp:93
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:99
armarx::PeriodicTask
Definition: ArmarXManager.h:70
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
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:27