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
25namespace armarx
26{
27
30 {
33
34 def->topic<KinematicUnitListener>("RealRobotState", "KinematicUnitName");
35 def->optional(frequency, "UpdateFrequency", "Frequency of updates in Hz");
36 return def;
37 }
38
39 std::string
41 {
42 return "SimpleEpisodicMemoryKinematicUnitConnector";
43 }
44
46 frequency(10), updated(false), timestampLastUpdateInMs(0)
47 {
48 }
49
50 void
55
56 void
58 {
61 this,
62 &SimpleEpisodicMemoryKinematicUnitConnector::checkAndSendToMemory,
63 (1.0f / frequency * 1000));
64 periodic_task->start();
65 }
66
67 void
72
73 void
77
78 void
79 SimpleEpisodicMemoryKinematicUnitConnector::checkAndSendToMemory()
80 {
81 std::lock_guard l(jointAngle_mutex);
82 std::lock_guard ll(jointVelocity_mutex);
83 std::lock_guard lll(jointTorque_mutex);
84 std::lock_guard llll(jointAcceleration_mutex);
85 std::lock_guard lllll(jointCurrent_mutex);
86 std::lock_guard llllll(jointTemperature_mutex);
87 std::lock_guard lllllll(jointEnabled_mutex);
88
89 std::lock_guard u(updatedMutex);
90 if (!updated || timestampLastUpdateInMs == 0)
91 {
92 return;
93 }
94
95 memoryx::KinematicUnitEvent event;
96 event.receivedInMs = timestampLastUpdateInMs;
97
98 for (const auto& [key, value] : jointAngleMap)
99 {
100 event.data[key].jointAngle = value;
101 }
102
103 for (const auto& [key, value] : jointVelocityMap)
104 {
105 event.data[key].jointVelocity = value;
106 }
107
108 for (const auto& [key, value] : jointTorqueMap)
109 {
110 event.data[key].jointTorque = value;
111 }
112
113 for (const auto& [key, value] : jointAccelerationMap)
114 {
115 event.data[key].jointAcceleration = value;
116 }
117
118 for (const auto& [key, value] : jointCurrentMap)
119 {
120 event.data[key].current = value;
121 }
122
123 for (const auto& [key, value] : jointTemperatureMap)
124 {
125 event.data[key].temperature = value;
126 }
127
128 for (const auto& [key, value] : jointEnabledMap)
129 {
130 event.data[key].enabled = value;
131 }
132
133 m_simple_episodic_memory->registerKinematicUnitEvent(event);
134
135 updated = false;
136 timestampLastUpdateInMs = 0;
137 }
138
139 void
141 Ice::Long,
142 bool updated,
143 const Ice::Current&)
144 {
145 //ARMARX_DEBUG << "Received reportControlModeChanged";
146 }
147
148 void
150 Ice::Long ts,
151 bool updated,
152 const Ice::Current&)
153 {
154 std::lock_guard l(jointAngle_mutex);
155 double received = IceUtil::Time::now().toMilliSecondsDouble();
156 for (const auto& [key, value] : data)
157 {
158 jointAngleMap[key] = value;
159 }
160 if (updated)
161 {
162 std::lock_guard u(updatedMutex);
163 this->updated = true;
164 this->timestampLastUpdateInMs = received;
165 }
166 }
167
168 void
170 Ice::Long,
171 bool updated,
172 const Ice::Current&)
173 {
174 std::lock_guard l(jointVelocity_mutex);
175 double received = IceUtil::Time::now().toMilliSecondsDouble();
176 for (const auto& [key, value] : data)
177 {
178 jointVelocityMap[key] = value;
179 }
180 if (updated)
181 {
182 std::lock_guard u(updatedMutex);
183 this->updated = true;
184 this->timestampLastUpdateInMs = received;
185 }
186 }
187
188 void
190 Ice::Long,
191 bool updated,
192 const Ice::Current&)
193 {
194 std::lock_guard l(jointTorque_mutex);
195 double received = IceUtil::Time::now().toMilliSecondsDouble();
196 for (const auto& [key, value] : data)
197 {
198 jointTorqueMap[key] = value;
199 }
200 if (updated)
201 {
202 std::lock_guard u(updatedMutex);
203 this->updated = true;
204 this->timestampLastUpdateInMs = received;
205 }
206 }
207
208 void
210 Ice::Long updated,
211 bool,
212 const Ice::Current&)
213 {
214 std::lock_guard l(jointAcceleration_mutex);
215 double received = IceUtil::Time::now().toMilliSecondsDouble();
216 for (const auto& [key, value] : data)
217 {
218 jointTorqueMap[key] = value;
219 }
220 if (updated)
221 {
222 std::lock_guard u(updatedMutex);
223 this->updated = true;
224 this->timestampLastUpdateInMs = received;
225 }
226 }
227
228 void
230 Ice::Long,
231 bool updated,
232 const Ice::Current&)
233 {
234 std::lock_guard l(jointCurrent_mutex);
235 double received = IceUtil::Time::now().toMilliSecondsDouble();
236 for (const auto& [key, value] : data)
237 {
238 jointCurrentMap[key] = value;
239 }
240 if (updated)
241 {
242 std::lock_guard u(updatedMutex);
243 this->updated = true;
244 this->timestampLastUpdateInMs = received;
245 }
246 }
247
248 void
250 const NameValueMap& data,
251 Ice::Long,
252 bool updated,
253 const Ice::Current&)
254 {
255 std::lock_guard l(jointTemperature_mutex);
256 double received = IceUtil::Time::now().toMilliSecondsDouble();
257 for (const auto& [key, value] : data)
258 {
259 jointTemperatureMap[key] = value;
260 }
261 if (updated)
262 {
263 std::lock_guard u(updatedMutex);
264 this->updated = true;
265 this->timestampLastUpdateInMs = received;
266 }
267 }
268
269 void
271 Ice::Long,
272 bool updated,
273 const Ice::Current&)
274 {
275 std::lock_guard l(jointEnabled_mutex);
276 double received = IceUtil::Time::now().toMilliSecondsDouble();
277 for (const auto& [key, value] : data)
278 {
279 jointEnabledMap[key] = value.enabled;
280 }
281 if (updated)
282 {
283 std::lock_guard u(updatedMutex);
284 this->updated = true;
285 this->timestampLastUpdateInMs = received;
286 }
287 }
288} // namespace armarx
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