32 def->topic<KinematicUnitListener>(
"RealRobotState",
"KinematicUnitName");
33 def->optional(frequency,
"UpdateFrequency",
"Frequency of updates in Hz");
39 return "SimpleEpisodicMemoryKinematicUnitConnector";
45 timestampLastUpdateInMs(0)
61 &SimpleEpisodicMemoryKinematicUnitConnector::checkAndSendToMemory, (1.0f / frequency * 1000));
62 periodic_task->start();
68 periodic_task->stop();
77 void SimpleEpisodicMemoryKinematicUnitConnector::checkAndSendToMemory()
79 std::lock_guard l(jointAngle_mutex);
80 std::lock_guard ll(jointVelocity_mutex);
81 std::lock_guard lll(jointTorque_mutex);
82 std::lock_guard llll(jointAcceleration_mutex);
83 std::lock_guard lllll(jointCurrent_mutex);
84 std::lock_guard llllll(jointTemperature_mutex);
85 std::lock_guard lllllll(jointEnabled_mutex);
87 std::lock_guard u(updatedMutex);
88 if (!updated || timestampLastUpdateInMs == 0)
93 memoryx::KinematicUnitEvent event;
94 event.receivedInMs = timestampLastUpdateInMs;
96 for (
const auto& [key,
value] : jointAngleMap)
98 event.data[key].jointAngle =
value;
101 for (
const auto& [key,
value] : jointVelocityMap)
103 event.data[key].jointVelocity =
value;
106 for (
const auto& [key,
value] : jointTorqueMap)
108 event.data[key].jointTorque =
value;
111 for (
const auto& [key,
value] : jointAccelerationMap)
113 event.data[key].jointAcceleration =
value;
116 for (
const auto& [key,
value] : jointCurrentMap)
118 event.data[key].current =
value;
121 for (
const auto& [key,
value] : jointTemperatureMap)
123 event.data[key].temperature =
value;
126 for (
const auto& [key,
value] : jointEnabledMap)
128 event.data[key].enabled =
value;
134 timestampLastUpdateInMs = 0;
144 std::lock_guard l(jointAngle_mutex);
145 double received = IceUtil::Time::now().toMilliSecondsDouble();
148 jointAngleMap[key] =
value;
152 std::lock_guard u(updatedMutex);
153 this->updated =
true;
154 this->timestampLastUpdateInMs = received;
159 std::lock_guard l(jointVelocity_mutex);
160 double received = IceUtil::Time::now().toMilliSecondsDouble();
163 jointVelocityMap[key] =
value;
167 std::lock_guard u(updatedMutex);
168 this->updated =
true;
169 this->timestampLastUpdateInMs = received;
174 std::lock_guard l(jointTorque_mutex);
175 double received = IceUtil::Time::now().toMilliSecondsDouble();
178 jointTorqueMap[key] =
value;
182 std::lock_guard u(updatedMutex);
183 this->updated =
true;
184 this->timestampLastUpdateInMs = received;
189 std::lock_guard l(jointAcceleration_mutex);
190 double received = IceUtil::Time::now().toMilliSecondsDouble();
193 jointTorqueMap[key] =
value;
197 std::lock_guard u(updatedMutex);
198 this->updated =
true;
199 this->timestampLastUpdateInMs = received;
204 std::lock_guard l(jointCurrent_mutex);
205 double received = IceUtil::Time::now().toMilliSecondsDouble();
208 jointCurrentMap[key] =
value;
212 std::lock_guard u(updatedMutex);
213 this->updated =
true;
214 this->timestampLastUpdateInMs = received;
219 std::lock_guard l(jointTemperature_mutex);
220 double received = IceUtil::Time::now().toMilliSecondsDouble();
223 jointTemperatureMap[key] =
value;
227 std::lock_guard u(updatedMutex);
228 this->updated =
true;
229 this->timestampLastUpdateInMs = received;
234 std::lock_guard l(jointEnabled_mutex);
235 double received = IceUtil::Time::now().toMilliSecondsDouble();
238 jointEnabledMap[key] =
value.enabled;
242 std::lock_guard u(updatedMutex);
243 this->updated =
true;
244 this->timestampLastUpdateInMs = received;