ProprioceptionStressTest.h
Go to the documentation of this file.
1#pragma once
2
7
10#include <RobotAPI/libraries/armem_robot_state/aron/Proprioception.aron.generated.h>
14
15#include <atomic>
16#include <chrono>
17#include <random>
18#include <vector>
19
21{
22 namespace arondto = ::armarx::armem::arondto;
23
24 /**
25 * @brief Debug component for stress-testing the Proprioception segment
26 * of RobotStateMemory with high-frequency read and write operations.
27 *
28 * This component generates mock joint data and performs configurable
29 * read/write operations to test memory performance and concurrency.
30 */
32 virtual public armarx::Component,
34 {
35 public:
38
39 std::string getDefaultName() const override;
40
41 protected:
43 void onInitComponent() override;
44 void onConnectComponent() override;
45 void onDisconnectComponent() override;
46 void onExitComponent() override;
47
48 private:
49 /// Main write loop - generates and writes mock proprioception data
50 void writeLoop();
51
52 /// Main read loop - reads proprioception data and tracks statistics
53 void readLoop();
54
55 /// Generate complete mock proprioception data (joints + extra fields)
56 arondto::Proprioception generateMockProprioceptionData();
57
58 /// Store proprioception data with extra fields directly to memory
59 bool storeProprioceptionWithExtras(const arondto::Proprioception& proprioception,
60 const std::string& robotTypeName,
61 const std::string& robotName,
62 const armem::Time& timestamp);
63
64 /// Print statistics about read/write operations
65 void printStatistics();
66
67 struct Properties
68 {
69 /// Name of the robot to test (e.g., "Armar6", "Armar7")
70 std::string robotName = "Armar6";
71
72 /// Number of mock joints to generate
73 int numJoints = 30;
74
75 /// Frequency of write operations in Hz (0 = disabled)
76 float writeFrequencyHz = 100.0f;
77
78 /// Frequency of read operations in Hz (0 = disabled)
79 float readFrequencyHz = 100.0f;
80
81 /// Number of parallel read threads (for testing shared mutexes)
82 int numParallelReads = 1;
83
84 /// Number of parallel write threads (for testing concurrent writes)
85 int numParallelWrites = 1;
86
87 /// Number of extra float values to write per snapshot
88 int numExtraFloats = 10;
89
90 /// Number of extra long values to write per snapshot
91 int numExtraLongs = 10;
92
93 /// How often to print statistics (in seconds)
94 float statisticsIntervalSec = 1.0f;
95
96 /// Enable verbose logging of each operation
97 bool verboseLogging = false;
98 };
99
100 Properties properties;
101
102 /// Robot state reader and writer
105
106 /// Direct memory writer for custom proprioception data
108
109 /// Running tasks for read and write loops
110 std::vector<armarx::SimpleRunningTask<>::pointer_type> writeTasks;
111 std::vector<armarx::SimpleRunningTask<>::pointer_type> readTasks;
113
114 /// Random number generator for mock data
115 std::mt19937 rng;
116 std::uniform_real_distribution<float> jointAngleDist;
117
118 /// Statistics tracking (atomic for thread safety)
119 std::atomic<uint64_t> writeCount{0};
120 std::atomic<uint64_t> readCount{0};
121 std::atomic<uint64_t> readSuccessCount{0};
122 std::atomic<uint64_t> readFailureCount{0};
123 std::atomic<uint64_t> writeErrorCount{0};
124
125 std::chrono::steady_clock::time_point startTime;
126 };
127
128} // namespace armarx::armem::client
std::string timestamp()
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
void onInitComponent() override
Pure virtual hook for the subclass.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Creates the property definition container.
void onConnectComponent() override
Pure virtual hook for the subclass.
std::string getDefaultName() const override
Retrieve default name of component.
Helps a memory client sending data to a memory.
Definition Writer.h:23
This file is part of ArmarX.
plugins::ListeningPluginUser ComponentPluginUser
Definition plugins.h:10
armarx::core::time::DateTime Time
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.