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
35namespace 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
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...";
103 Eigen::Isometry3f::Identity();
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
113
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
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
The periodic task executes one thread method repeatedly using the time period specified in the constr...
PeriodicTask< SelfLocalizationDynamicSimulation >::pointer_type execTask
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onDisconnectComponent() override
PropertyDefinitionsPtr createPropertyDefinitions() override
void publishSelfLocalization(const PoseStamped &map_T_robot)
static void SleepMS(float milliseconds)
Definition TimeUtil.h:203
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
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.
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)