TransformWriter.cpp
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#include "TransformWriter.h"
23
24#include <algorithm>
25#include <iterator>
26#include <numeric>
27#include <optional>
28
29#include <Eigen/Geometry>
30
31#include <IceUtil/Time.h>
32
37
45#include <RobotAPI/libraries/armem_robot_state/aron/Transform.aron.generated.h>
49
51{
53
54 void
56 {
57 ARMARX_DEBUG << "TransformWriter: registerPropertyDefinitions";
58
59 def->optional(properties.coreSegmentID.memoryName, propertyPrefix + "MemoryName");
60 def->optional(properties.coreSegmentID.coreSegmentName,
61 propertyPrefix + "LocalizationSegmentName",
62 "Name of the localization memory core segment to use.");
63 }
64
65 void
67 {
68 // Wait for the memory to become available and add it as dependency.
69 ARMARX_IMPORTANT << "TransformWriter: Waiting for memory '"
70 << properties.coreSegmentID.memoryName << "' ...";
71 try
72 {
73 memoryWriter = memoryNameSystem.useWriter(properties.coreSegmentID);
74 ARMARX_IMPORTANT << "TransformWriter: Connected to memory for '"
75 << properties.coreSegmentID << "'";
76 }
78 {
79 ARMARX_ERROR << e.what();
80 return;
81 }
82 }
83
84 bool
86 const ::armarx::armem::robot_state::localization::Transform& transform)
87 {
88 std::lock_guard g{memoryWriterMutex};
89
90 const MemoryID providerId =
91 properties.coreSegmentID.withProviderSegmentName(transform.header.agent);
92 // const auto& timestamp = transform.header.timestamp;
93 const MemoryID entityID =
94 providerId.withEntityName(transform.header.parentFrame + "," + transform.header.frame);
95 const Time timestamp = Time::Now(); // FIXME remove
96
98 update.entityID = entityID;
99 update.referencedTime = timestamp;
100
101 arondto::Transform aronTransform;
102 toAron(aronTransform, transform);
103 update.instancesData = {aronTransform.toAron()};
104
105 ARMARX_DEBUG << "Committing " << update << " at time " << transform.header.timestamp;
106 armem::EntityUpdateResult updateResult = memoryWriter.commit(update);
107
108 ARMARX_DEBUG << updateResult;
109
110 if (not updateResult.success)
111 {
112 ARMARX_ERROR << updateResult.errorMessage;
113 }
114
115 return updateResult.success;
116 }
117
118} // namespace armarx::armem::robot_state::client::localization
std::string timestamp()
MemoryID withProviderSegmentName(const std::string &name) const
Definition MemoryID.cpp:417
MemoryID withEntityName(const std::string &name) const
Definition MemoryID.cpp:425
The memory name system (MNS) client.
Writer useWriter(const MemoryID &memoryID)
Use a memory server and get a writer for it.
Indicates that a query to the Memory Name System failed.
Definition mns.h:25
bool commitTransform(const ::armarx::armem::robot_state::localization::Transform &transform) override
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def) override
to be called in Component::addPropertyDefinitions
void connect(armem::client::MemoryNameSystem &memoryNameSystem) override
to be called in Component::onConnectComponent
static DateTime Now()
Definition DateTime.cpp:51
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
void toAron(arondto::ObjectInstance &dto, const RobotState &bo)
armarx::core::time::DateTime Time
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition algorithm.h:351
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Result of an EntityUpdate.
Definition Commit.h:75
An update of an entity for a specific point in time.
Definition Commit.h:26