SelfLocalization.h
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 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2021
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <atomic>
25#include <optional>
26
27#include <Eigen/Core>
28#include <Eigen/Geometry>
29
34
38#include <RobotAPI/interface/core/RobotLocalization.h>
39#include <RobotAPI/interface/units/LocalizationUnitInterface.h>
40#include <RobotAPI/interface/units/PlatformUnitInterface.h>
43
44#include <RobotComponents/interface/components/LaserScannerSelfLocalisation.h>
45
46#include <MemoryX/interface/components/LongtermMemoryInterface.h>
47#include <MemoryX/interface/components/WorkingMemoryInterface.h>
49
51{
52 class TransformWriterInterface;
53 class TransformReaderInterface;
54} // namespace armarx::armem::client::robot_state::localization
55
56namespace armarx
57{
58
60 {
61 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
62
63 Eigen::Isometry3f pose = Eigen::Isometry3f::Identity(); // [mm]
65 };
66
67 /**
68 * @brief The SelfLocalization class.
69 *
70 * This class serves as a base class for all self-localization implementations.
71 * The global pose is sent to a multitude of topics, written to ArMem and to MemoryX short and longterm memory,
72 * which is all done by this class.
73 *
74 * All you have to do, is to
75 * - implement worldToMapTransform()
76 * - call publishSelfLocalization(...) whenever needed.
77 *
78 *
79 * Hint:
80 * If your component which is derived from SelfLocalization implements its own interface,
81 * make sure that it also extends the MemoryListenerInterface
82 * (RobotAPI/interface/armem/client/MemoryListenerInterface.ice).
83 */
84 class [[deprecated("This class was moved to armarx::localization_and_mapping. It is kept for "
85 "ArmarXSimulation but should not be removed after CMake modernization of "
86 "ArmarXSimulation.")]] SelfLocalization :
87 virtual public armarx::Component,
89 {
90
91 public:
94
96
97 void publishSelfLocalization(const PoseStamped& map_T_robot);
98
99 [[nodiscard]] std::optional<Eigen::Affine3f> globalPoseFromLongTermMemory() const;
100
101 /// @see armarx::ManagedIceObject::onInitComponent()
102 void onInitComponent() override;
103
104 /// @see armarx::ManagedIceObject::onConnectComponent()
105 void onConnectComponent() override;
106
108
109 /// @see armarx::ManagedIceObject::onDisconnectComponent()
110 void onDisconnectComponent() override;
111
112 /// @see armarx::ManagedIceObject::onExitComponent()
113 void
115 {
116 }
117
118
119 protected:
120 /// static transformation from world to map
121 virtual Eigen::Isometry3f worldToMapTransform() const = 0;
122
123 const std::string& getAgentName() const noexcept;
124 const std::string& getRobotRootFrame() const noexcept;
125 const std::shared_ptr<VirtualRobot::Robot>& getRobot() const noexcept;
126
127 armem::robot_state::client::localization::TransformWriterInterface&
128 getTransformWriter() const;
129 const armem::robot_state::client::localization::TransformReaderInterface&
130 getTransformReader() const;
131
132 private:
133 void publishSelfLocalizationOnTopic(const PoseStamped& map_T_robot);
134
135 void publishSelfLocalizationToWorkingMemory(const PoseStamped& map_T_robot);
136 void publishSelfLocalizationToLongtermMemory(const PoseStamped& map_T_robot);
137 void publishSelfLocalizationToArMem(const PoseStamped& map_T_robot);
138
139 // setup
140 void setupArMem();
141 void setupWorkingMemory();
142 void setupLongTermMemory();
143
144 // helpers
145 TransformStamped toTransformStamped(const PoseStamped& poseStamped);
146 armem::robot_state::localization::Transform toTransform(const PoseStamped& poseStamped);
147
148 // publisher
149 LaserScannerSelfLocalisationListenerPrx reportTopic;
150 GlobalRobotPoseLocalizationListenerPrx globalRobotPoseTopic;
151 GlobalRobotPoseLocalizationCorrectionListenerPrx gobalRobotPoseCorrectionTopic;
152
153 // long-term memory
154 memoryx::LongtermMemoryInterfacePrx longtermMemory;
155 memoryx::PersistentEntitySegmentBasePrx ltmSelfLocalisationSegment;
156 std::optional<std::string> ltmPoseEntityId;
157
158 // working memory
159 memoryx::WorkingMemoryInterfacePrx workingMemory;
160 memoryx::AgentInstancesSegmentBasePrx wmAgentsMemory;
161 memoryx::AgentInstancePtr wmAgentInstance;
162
163 // proxies
164 RobotStateComponentInterfacePrx robotStateComponent;
165 LocalizationUnitInterfacePrx localizationUnitPrx;
166
167 // utils
168 IceReportSkipper skipper{0.};
169
170 struct Properties
171 {
172 // old working memory
173 bool updateWorkingMemory = true;
174 float workingMemoryUpdateFrequency = 50.F;
175
176 // old long term memory
177 std::string longtermMemoryName = "LongtermMemory";
178 bool updateLongTermMemory = true;
179 float longtermMemoryUpdateFrequency = 1.F;
180 bool initialPoseFromLTM = true;
181
182 // armem
183 bool updateArMem = true;
184 float armMemUpdateFrequency = 1000.F;
185
186 // general
187 bool useLocalizationUnit = true;
188 std::string localizationUnitName = ""; // will be set in c'tor
189 } properties;
190
191 std::string agentName;
192 std::string robotRootFrame;
193
194 std::shared_ptr<VirtualRobot::Robot> robot;
195
198 nullptr;
201 nullptr;
202
203 Eigen::Isometry3f global_T_map;
204
205 std::atomic_bool connected{false};
206
207 bool onConnectCalled{false};
208 };
209
210} // namespace armarx
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
const armem::robot_state::client::localization::TransformReaderInterface & getTransformReader() const
void onDisconnectComponent() override
std::optional< Eigen::Affine3f > globalPoseFromLongTermMemory() const
const std::string & getAgentName() const noexcept
const std::string & getRobotRootFrame() const noexcept
armem::robot_state::client::localization::TransformWriterInterface & getTransformWriter() const
PropertyDefinitionsPtr createPropertyDefinitions() override
virtual Eigen::Isometry3f worldToMapTransform() const =0
static transformation from world to map
void onExitComponent() override
const std::shared_ptr< VirtualRobot::Robot > & getRobot() const noexcept
void publishSelfLocalization(const PoseStamped &map_T_robot)
A component plugin offering client-side access to a reader or writer and manages the lifecycle,...
Represents a point in time.
Definition DateTime.h:25
client::plugins::ListeningPluginUser ListeningClientPluginUser
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
VirtualRobot headers.
armarx::DateTime timestamp
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Isometry3f pose