OpossumLogger.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 * @package RobotAPI::ArmarXObjects::OpossumLogger
17 * @author Joana Plewnia ( joana dot plewnia at kit dot edu )
18 * @date 2026
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <atomic>
26#include <condition_variable>
27#include <cstddef>
28#include <deque>
29#include <map>
30#include <memory>
31#include <mutex>
32#include <set>
33#include <string>
34#include <thread>
35#include <vector>
36
38
43
44#include "ObjectSpokenNames.h"
45#include "SkillEventRenderer.h"
46
47namespace armarx
48{
49
50 /**
51 * @defgroup Component-OpossumLogger OpossumLogger
52 * @ingroup RobotAPI-Components
53 *
54 * Streams the robot's skill events to an OPOSSUM summary server.
55 *
56 * OPOSSUM (Observe, Process, Organize Scene-Level SUMmaries) is the shared
57 * multi-agent log of the euROBIN demo: every robot posts scene-level log
58 * lines over HTTP, the server sorts them by `robot_name` and summarises them.
59 *
60 * This component subscribes to the `SkillEvent` core segment of the Skill
61 * memory and, for every skill that starts, succeeds, fails or is aborted,
62 * renders one line such as
63 * @code
64 * skill:LookAtObject, object:dining table, called_by:ServeDrinks::ApproachAndAskForDrink, state:started, time_stamp:2026-07-08T16:45:40.341
65 * @endcode
66 * and POSTs it as `{"robot_name": ..., "message": ...}`.
67 *
68 * The line format matches `tools/gen_armar7_logs.py` in the `opossum_euROBIN`
69 * repository, which produces the same lines offline from an LTM export.
70 *
71 * @class OpossumLogger
72 * @ingroup Component-OpossumLogger
73 */
75 virtual public armarx::Component,
77 {
78 public:
79 ~OpossumLogger() override;
80
81 std::string getDefaultName() const override;
82 static std::string GetDefaultName();
83
84 protected:
86
87 void onInitComponent() override;
88 void onConnectComponent() override;
89 void onDisconnectComponent() override;
90 void onExitComponent() override;
91
92 private:
93 /// Called by the memory listener for every batch of new `SkillEvent` snapshots.
94 void onSkillEventUpdate(const armem::MemoryID& subscriptionID,
95 const std::vector<armem::MemoryID>& updatedSnapshotIDs);
96
97 /// Whether this snapshot has not been handled before.
98 bool isNew(const armem::MemoryID& snapshotID);
99
100 /// Fetch the given snapshots' first instance each, skipping those the
101 /// memory no longer holds.
102 std::map<armem::MemoryID, armem::wm::EntityInstance>
103 resolve(const std::vector<armem::MemoryID>& snapshotIDs);
104
105 void enqueue(std::string line);
106
107 /// Worker: posts queued lines and appends them to the output file.
108 void sendLoop();
109
110 void startSender();
111 void stopSender();
112
113 struct Properties
114 {
115 bool enabled = true;
116
117 std::string robotName = "ARMAR-7 (KIT)";
118 std::string host = "192.168.253.48";
119 int port = 8001;
120 std::string path = "message";
121 // A POST to the summary server crosses from the robot network to
122 // the venue network; 200 ms was enough only against localhost.
123 int timeoutMs = 1000;
124
125 int queueSize = 1000;
126 // On by default: a failed POST discards its line for good, and the
127 // summary server belongs to a project partner, so the local record
128 // is the only one we control. Written before the POST is attempted.
129 std::string outputFile = "/tmp/opossum_log.txt";
130
131 std::string skillFilter;
132 bool resolveObjectNames = true;
133
134 std::string memoryName = "Skill";
135 std::string coreSegmentName = "SkillEvent";
136 };
137
138 Properties p;
139
140 armem::MemoryID skillEventID;
141 armem::client::Reader skillMemoryReader;
142
143 opossum::ObjectSpokenNames spokenNames;
144 std::unique_ptr<opossum::SkillEventRenderer> renderer;
145
146 std::thread sender;
147 std::atomic_bool running{false};
148
149 std::mutex queueMutex;
150 std::condition_variable queueCondition;
151 std::deque<std::string> queue;
152 std::size_t droppedLines = 0;
153
154 /// Snapshot IDs already handled, oldest first, bounded in size.
155 std::mutex seenMutex;
156 std::deque<std::string> seenOrder;
157 std::set<std::string> seen;
158
159 /// Declared last on purpose: members are destroyed in reverse
160 /// declaration order, so this is released before everything
161 /// `onSkillEventUpdate` touches (`renderer`, the queue, `seen`).
162 /// Note that ~SubscriptionHandle does not release by itself.
164 };
165
166} // namespace armarx
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
void onInitComponent() override
Pure virtual hook for the subclass.
void onDisconnectComponent() override
Hook for subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
Pure virtual hook for the subclass.
static std::string GetDefaultName()
void onExitComponent() override
Hook for subclass.
std::string getDefaultName() const override
Retrieve default name of component.
Reads data from a memory server.
Definition Reader.h:25
Spoken object names from PriorKnowledgeData, for use as a SpokenNameLookup.
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.