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
36
37namespace armarx
38{
39
40 std::string
42 {
43 return "SelfLocalizationDynamicSimulation";
44 }
45
48 {
50
51 defs->component(simulatorProxy);
52
53 defs->optional(p.cycleTime, "cycleTime");
54 defs->required(p.robotName, "RobotName");
55
56 return defs;
57 }
58
59 void
61 {
63
64 ARMARX_CHECK(simulatorProxy->hasRobot(p.robotName))
65 << "Robot with given name not available in armarx simulator: " + p.robotName;
66
67 ARMARX_INFO << "Using robot with name " << p.robotName;
68
69 // periodic task setup
70 if (execTask)
71 {
72 execTask->stop();
73 }
74
76 this,
77 &SelfLocalizationDynamicSimulation::reportRobotPose,
78 p.cycleTime,
79 false,
80 "SelfLocalizationDynamicSimulationCalculation");
81 execTask->start();
82 execTask->setDelayWarningTolerance(100);
83 }
84
85 void
96
97 void
98 SelfLocalizationDynamicSimulation::reportRobotPose()
99 {
100 try
101 {
102 std::unique_lock lock(dataMutex);
103
104 const Eigen::Isometry3f globalPose = [&]() -> Eigen::Isometry3f
105 {
106 const PoseBasePtr poseBase = simulatorProxy->getRobotPose(p.robotName);
107
108 if (not poseBase)
109 {
110 ARMARX_WARNING << deactivateSpam(10) << "No robot pose from simulator...";
111 Eigen::Isometry3f::Identity();
112 }
113
114 return Eigen::Isometry3f(PosePtr::dynamicCast(poseBase)->toEigen());
115 }();
116
117 // world and map are identical
118 const PoseStamped mapPose{.pose = globalPose, .timestamp = Clock::Now()};
119
121
123
124 // ARMARX_INFO << deactivateSpam(0.1) << globalPose.translation();
125 }
126 catch (...)
127 {
129 << "Could not update robot pose in agents segment...\n"
131 }
132 }
133
135
136} // namespace armarx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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...
SelfLocalizationDynamicSimulation uses the armarx simulator to retrieve thre current psoe of the robo...
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)