HumanRobotInteractionWriter.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 Joana Plewnia ( joana dot plewnia at kit dot edu )
17 * @date 2025
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
23
25
29
32
34{
35
39
41
42 void
47
48 void
50 {
51 ARMARX_VERBOSE << "Connecting ...";
53 ARMARX_VERBOSE << "Connected.";
54
55 reader.connect(memoryNameSystem);
56 }
57
58 bool
60 const std::string& provider,
61 const armem::Time& referencedTime)
62 {
63 return this->commitHumanRobotInteractions({interaction}, provider, referencedTime);
64 }
65
66 bool
68 const std::vector<HumanRobotInteraction>& interactions,
69 const std::string& provider,
70 const armem::Time& referencedTime)
71 {
72 if (interactions.empty())
73 {
74 ARMARX_WARNING << "No interactions to commit";
75 return false;
76 }
77
78 try
79 {
80 // Group interactions by person (entity)
81 std::map<std::string, std::vector<HumanRobotInteraction>> interactionsByPerson;
82
83 for (const HumanRobotInteraction& interaction : interactions)
84 {
85 std::string entityName;
86 if (interaction.personID.has_value())
87 {
88 entityName = interaction.personID.value().toMemoryEntityID();
89 }
90 else
91 {
92 // If no person ID, use a default entity name
93 entityName = "unknown-person";
94 }
95
96 interactionsByPerson[entityName].push_back(interaction);
97 }
98
99 // Commit each entity separately
100 for (const auto& [entityName, entityInteractions] : interactionsByPerson)
101 {
102 // Convert interactions to DTO
103 std::vector<armarx::aron::data::DictPtr> interactionDtos;
104 for (const HumanRobotInteraction& interaction : entityInteractions)
105 {
106 armarx::human::arondto::HumanRobotInteraction interactionAron;
107 toAron(interactionAron, interaction);
108 interactionDtos.push_back(interactionAron.toAron());
109 }
110
111 // Create entity ID
112 armarx::armem::MemoryID entityId =
114 .withProviderSegmentName(provider)
115 .withEntityName(entityName);
116
117 ARMARX_INFO << "Entity ID created: " << entityId.str();
118 ARMARX_INFO << " Memory: " << entityId.memoryName;
119 ARMARX_INFO << " CoreSegment: " << entityId.coreSegmentName;
120 ARMARX_INFO << " Provider: " << entityId.providerSegmentName;
121 ARMARX_INFO << " Entity: " << entityId.entityName;
122
123 // Create entity update
125 .entityID = entityId,
126 .instancesData = interactionDtos,
127 .referencedTime = referencedTime,
128 .confidence = 1.0F,
129 .sentTime = armarx::armem::Time::Now(),
130 .arrivedTime = armarx::armem::Time::Now(),
131 };
132
133 // Commit the update
134 armem::Commit commit;
135 commit.add(update);
136
137 ARMARX_INFO << "Committing " << entityInteractions.size()
138 << " interactions for entity " << entityName;
139 ARMARX_INFO << "Commit contains " << commit.updates.size() << " updates";
140
141 memoryWriter().commit(commit);
142
143 ARMARX_INFO << "Commit completed successfully";
144 }
145
146 return true;
147 }
148 catch (...)
149 {
150 ARMARX_WARNING << "Failed to commit human-robot interactions: "
152 return false;
153 }
154 }
155
156
157} // namespace armarx::armem::human::client
std::string coreSegmentName
Definition MemoryID.h:51
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
Definition MemoryID.cpp:102
std::string entityName
Definition MemoryID.h:53
std::string memoryName
Definition MemoryID.h:50
std::string providerSegmentName
Definition MemoryID.h:52
The memory name system (MNS) client.
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition Writer.cpp:68
void connect(armarx::armem::client::MemoryNameSystem &mns)
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
void connect(armem::client::MemoryNameSystem &memoryNameSystem)
bool commitHumanRobotInteractions(const std::vector< HumanRobotInteraction > &interactions, const std::string &provider, const armem::Time &referencedTime)
bool commitHumanRobotInteraction(const HumanRobotInteraction &interaction, const std::string &provider, const armem::Time &referencedTime)
void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr &def)
static DateTime Now()
Definition DateTime.cpp:51
#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
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
void toAron(armarx::human::arondto::HumanPose &dto, const HumanPose &bo)
armarx::core::time::DateTime Time
const armem::MemoryID HumanRobotInteractionCoreSegmentID
std::string GetHandledExceptionString()
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
A bundle of updates to be sent to the memory.
Definition Commit.h:90
EntityUpdate & add()
Definition Commit.cpp:80
std::vector< EntityUpdate > updates
The entity updates.
Definition Commit.h:97
An update of an entity for a specific point in time.
Definition Commit.h:26