SimpleEpisodicMemoryKinematicUnitConnector.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 * @package RobotComponents::ArmarXObjects::SimpleEpisodicMemoryKinematicUnitConnector
17 * @author Fabian PK ( fabian dot peller-konrad at kit dot edu )
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
26
27namespace armarx
28{
29
32 {
35
36 def->topic<KinematicUnitListener>("RealRobotState", "KinematicUnitName");
37 def->optional(frequency, "UpdateFrequency", "Frequency of updates in Hz");
38 return def;
39 }
40
41 std::string
43 {
44 return "SimpleEpisodicMemoryKinematicUnitConnector";
45 }
46
48 frequency(10), updated(false), timestampLastUpdateInMs(0)
49 {
50 }
51
52 void
57
58 void
60 {
63 this,
64 &SimpleEpisodicMemoryKinematicUnitConnector::checkAndSendToMemory,
65 (1.0f / frequency * 1000));
66 periodic_task->start();
67 }
68
69 void
74
75 void
79
80 void
81 SimpleEpisodicMemoryKinematicUnitConnector::checkAndSendToMemory()
82 {
83 std::lock_guard l(jointAngle_mutex);
84 std::lock_guard ll(jointVelocity_mutex);
85 std::lock_guard lll(jointTorque_mutex);
86 std::lock_guard llll(jointAcceleration_mutex);
87 std::lock_guard lllll(jointCurrent_mutex);
88 std::lock_guard llllll(jointTemperature_mutex);
89 std::lock_guard lllllll(jointEnabled_mutex);
90
91 std::lock_guard u(updatedMutex);
92 if (!updated || timestampLastUpdateInMs == 0)
93 {
94 return;
95 }
96
97 memoryx::KinematicUnitEvent event;
98 event.receivedInMs = timestampLastUpdateInMs;
99
100 for (const auto& [key, value] : jointAngleMap)
101 {
102 event.data[key].jointAngle = value;
103 }
104
105 for (const auto& [key, value] : jointVelocityMap)
106 {
107 event.data[key].jointVelocity = value;
108 }
109
110 for (const auto& [key, value] : jointTorqueMap)
111 {
112 event.data[key].jointTorque = value;
113 }
114
115 for (const auto& [key, value] : jointAccelerationMap)
116 {
117 event.data[key].jointAcceleration = value;
118 }
119
120 for (const auto& [key, value] : jointCurrentMap)
121 {
122 event.data[key].current = value;
123 }
124
125 for (const auto& [key, value] : jointTemperatureMap)
126 {
127 event.data[key].temperature = value;
128 }
129
130 for (const auto& [key, value] : jointEnabledMap)
131 {
132 event.data[key].enabled = value;
133 }
134
135 m_simple_episodic_memory->registerKinematicUnitEvent(event);
136
137 updated = false;
138 timestampLastUpdateInMs = 0;
139 }
140
141 void
143 Ice::Long,
144 bool updated,
145 const Ice::Current&)
146 {
147 //ARMARX_DEBUG << "Received reportControlModeChanged";
148 }
149
150 void
152 Ice::Long ts,
153 bool updated,
154 const Ice::Current&)
155 {
156 std::lock_guard l(jointAngle_mutex);
157 double received = IceUtil::Time::now().toMilliSecondsDouble();
158 for (const auto& [key, value] : data)
159 {
160 jointAngleMap[key] = value;
161 }
162 if (updated)
163 {
164 std::lock_guard u(updatedMutex);
165 this->updated = true;
166 this->timestampLastUpdateInMs = received;
167 }
168 }
169
170 void
172 Ice::Long,
173 bool updated,
174 const Ice::Current&)
175 {
176 std::lock_guard l(jointVelocity_mutex);
177 double received = IceUtil::Time::now().toMilliSecondsDouble();
178 for (const auto& [key, value] : data)
179 {
180 jointVelocityMap[key] = value;
181 }
182 if (updated)
183 {
184 std::lock_guard u(updatedMutex);
185 this->updated = true;
186 this->timestampLastUpdateInMs = received;
187 }
188 }
189
190 void
192 Ice::Long,
193 bool updated,
194 const Ice::Current&)
195 {
196 std::lock_guard l(jointTorque_mutex);
197 double received = IceUtil::Time::now().toMilliSecondsDouble();
198 for (const auto& [key, value] : data)
199 {
200 jointTorqueMap[key] = value;
201 }
202 if (updated)
203 {
204 std::lock_guard u(updatedMutex);
205 this->updated = true;
206 this->timestampLastUpdateInMs = received;
207 }
208 }
209
210 void
212 Ice::Long updated,
213 bool,
214 const Ice::Current&)
215 {
216 std::lock_guard l(jointAcceleration_mutex);
217 double received = IceUtil::Time::now().toMilliSecondsDouble();
218 for (const auto& [key, value] : data)
219 {
220 jointTorqueMap[key] = value;
221 }
222 if (updated)
223 {
224 std::lock_guard u(updatedMutex);
225 this->updated = true;
226 this->timestampLastUpdateInMs = received;
227 }
228 }
229
230 void
232 Ice::Long,
233 bool updated,
234 const Ice::Current&)
235 {
236 std::lock_guard l(jointCurrent_mutex);
237 double received = IceUtil::Time::now().toMilliSecondsDouble();
238 for (const auto& [key, value] : data)
239 {
240 jointCurrentMap[key] = value;
241 }
242 if (updated)
243 {
244 std::lock_guard u(updatedMutex);
245 this->updated = true;
246 this->timestampLastUpdateInMs = received;
247 }
248 }
249
250 void
252 const NameValueMap& data,
253 Ice::Long,
254 bool updated,
255 const Ice::Current&)
256 {
257 std::lock_guard l(jointTemperature_mutex);
258 double received = IceUtil::Time::now().toMilliSecondsDouble();
259 for (const auto& [key, value] : data)
260 {
261 jointTemperatureMap[key] = value;
262 }
263 if (updated)
264 {
265 std::lock_guard u(updatedMutex);
266 this->updated = true;
267 this->timestampLastUpdateInMs = received;
268 }
269 }
270
271 void
273 Ice::Long,
274 bool updated,
275 const Ice::Current&)
276 {
277 std::lock_guard l(jointEnabled_mutex);
278 double received = IceUtil::Time::now().toMilliSecondsDouble();
279 for (const auto& [key, value] : data)
280 {
281 jointEnabledMap[key] = value.enabled;
282 }
283 if (updated)
284 {
285 std::lock_guard u(updatedMutex);
286 this->updated = true;
287 this->timestampLastUpdateInMs = received;
288 }
289 }
290
292} // namespace armarx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
void reportJointStatuses(const NameStatusMap &, Ice::Long, bool, const Ice::Current &)
void reportControlModeChanged(const NameControlModeMap &, Ice::Long, bool, const Ice::Current &)
void reportJointAccelerations(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
void reportJointTorques(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
void reportJointVelocities(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
void reportJointAngles(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
void reportJointCurrents(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
std::string getDefaultName() const override
Retrieve default name of component.
memoryx::SimpleEpisodicMemoryInterface::ProxyType m_simple_episodic_memory
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::shared_ptr< Value > value()
Definition cxxopts.hpp:855