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 
25 namespace armarx
26 {
27 
29  {
31 
32  def->topic<KinematicUnitListener>("RealRobotState", "KinematicUnitName");
33  def->optional(frequency, "UpdateFrequency", "Frequency of updates in Hz");
34  return def;
35  }
36 
38  {
39  return "SimpleEpisodicMemoryKinematicUnitConnector";
40  }
41 
43  frequency(10),
44  updated(false),
45  timestampLastUpdateInMs(0)
46  {
47 
48  }
49 
50 
52  {
54  }
55 
56 
58  {
61  &SimpleEpisodicMemoryKinematicUnitConnector::checkAndSendToMemory, (1.0f / frequency * 1000));
62  periodic_task->start();
63  }
64 
65 
67  {
68  periodic_task->stop();
69  }
70 
71 
73  {
74 
75  }
76 
77  void SimpleEpisodicMemoryKinematicUnitConnector::checkAndSendToMemory()
78  {
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);
86 
87  std::lock_guard u(updatedMutex);
88  if (!updated || timestampLastUpdateInMs == 0)
89  {
90  return;
91  }
92 
93  memoryx::KinematicUnitEvent event;
94  event.receivedInMs = timestampLastUpdateInMs;
95 
96  for (const auto& [key, value] : jointAngleMap)
97  {
98  event.data[key].jointAngle = value;
99  }
100 
101  for (const auto& [key, value] : jointVelocityMap)
102  {
103  event.data[key].jointVelocity = value;
104  }
105 
106  for (const auto& [key, value] : jointTorqueMap)
107  {
108  event.data[key].jointTorque = value;
109  }
110 
111  for (const auto& [key, value] : jointAccelerationMap)
112  {
113  event.data[key].jointAcceleration = value;
114  }
115 
116  for (const auto& [key, value] : jointCurrentMap)
117  {
118  event.data[key].current = value;
119  }
120 
121  for (const auto& [key, value] : jointTemperatureMap)
122  {
123  event.data[key].temperature = value;
124  }
125 
126  for (const auto& [key, value] : jointEnabledMap)
127  {
128  event.data[key].enabled = value;
129  }
130 
131  m_simple_episodic_memory->registerKinematicUnitEvent(event);
132 
133  updated = false;
134  timestampLastUpdateInMs = 0;
135 
136  }
137 
138  void SimpleEpisodicMemoryKinematicUnitConnector::reportControlModeChanged(const NameControlModeMap&, Ice::Long, bool updated, const Ice::Current&)
139  {
140  //ARMARX_DEBUG << "Received reportControlModeChanged";
141  }
143  {
144  std::lock_guard l(jointAngle_mutex);
145  double received = IceUtil::Time::now().toMilliSecondsDouble();
146  for (const auto& [key, value] : data)
147  {
148  jointAngleMap[key] = value;
149  }
150  if (updated)
151  {
152  std::lock_guard u(updatedMutex);
153  this->updated = true;
154  this->timestampLastUpdateInMs = received;
155  }
156  }
158  {
159  std::lock_guard l(jointVelocity_mutex);
160  double received = IceUtil::Time::now().toMilliSecondsDouble();
161  for (const auto& [key, value] : data)
162  {
163  jointVelocityMap[key] = value;
164  }
165  if (updated)
166  {
167  std::lock_guard u(updatedMutex);
168  this->updated = true;
169  this->timestampLastUpdateInMs = received;
170  }
171  }
173  {
174  std::lock_guard l(jointTorque_mutex);
175  double received = IceUtil::Time::now().toMilliSecondsDouble();
176  for (const auto& [key, value] : data)
177  {
178  jointTorqueMap[key] = value;
179  }
180  if (updated)
181  {
182  std::lock_guard u(updatedMutex);
183  this->updated = true;
184  this->timestampLastUpdateInMs = received;
185  }
186  }
188  {
189  std::lock_guard l(jointAcceleration_mutex);
190  double received = IceUtil::Time::now().toMilliSecondsDouble();
191  for (const auto& [key, value] : data)
192  {
193  jointTorqueMap[key] = value;
194  }
195  if (updated)
196  {
197  std::lock_guard u(updatedMutex);
198  this->updated = true;
199  this->timestampLastUpdateInMs = received;
200  }
201  }
203  {
204  std::lock_guard l(jointCurrent_mutex);
205  double received = IceUtil::Time::now().toMilliSecondsDouble();
206  for (const auto& [key, value] : data)
207  {
208  jointCurrentMap[key] = value;
209  }
210  if (updated)
211  {
212  std::lock_guard u(updatedMutex);
213  this->updated = true;
214  this->timestampLastUpdateInMs = received;
215  }
216  }
218  {
219  std::lock_guard l(jointTemperature_mutex);
220  double received = IceUtil::Time::now().toMilliSecondsDouble();
221  for (const auto& [key, value] : data)
222  {
223  jointTemperatureMap[key] = value;
224  }
225  if (updated)
226  {
227  std::lock_guard u(updatedMutex);
228  this->updated = true;
229  this->timestampLastUpdateInMs = received;
230  }
231  }
232  void SimpleEpisodicMemoryKinematicUnitConnector::reportJointStatuses(const NameStatusMap& data, Ice::Long, bool updated, const Ice::Current&)
233  {
234  std::lock_guard l(jointEnabled_mutex);
235  double received = IceUtil::Time::now().toMilliSecondsDouble();
236  for (const auto& [key, value] : data)
237  {
238  jointEnabledMap[key] = value.enabled;
239  }
240  if (updated)
241  {
242  std::lock_guard u(updatedMutex);
243  this->updated = true;
244  this->timestampLastUpdateInMs = received;
245  }
246  }
247 }
armarx::SimpleEpisodicMemoryKinematicUnitConnector::reportJointVelocities
void reportJointVelocities(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:157
armarx::SimpleEpisodicMemoryKinematicUnitConnector::onDisconnectComponent
void onDisconnectComponent() override
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:66
armarx::SimpleEpisodicMemoryKinematicUnitConnector::onInitComponent
void onInitComponent() override
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:51
armarx::SimpleEpisodicMemoryKinematicUnitConnector::SimpleEpisodicMemoryKinematicUnitConnector
SimpleEpisodicMemoryKinematicUnitConnector()
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:42
armarx::SimpleEpisodicMemoryKinematicUnitConnector::reportJointStatuses
void reportJointStatuses(const NameStatusMap &, Ice::Long, bool, const Ice::Current &)
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:232
armarx::SimpleEpisodicMemoryKinematicUnitConnector::reportJointAngles
void reportJointAngles(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:142
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::SimpleEpisodicMemoryKinematicUnitConnector::reportControlModeChanged
void reportControlModeChanged(const NameControlModeMap &, Ice::Long, bool, const Ice::Current &)
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:138
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::SimpleEpisodicMemoryKinematicUnitConnector::reportJointTorques
void reportJointTorques(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:172
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::SimpleEpisodicMemoryKinematicUnitConnector::reportJointAccelerations
void reportJointAccelerations(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:187
memoryx::SimpleEpisodicMemoryConnector::m_simple_episodic_memory
memoryx::SimpleEpisodicMemoryInterface::ProxyType m_simple_episodic_memory
Definition: SimpleEpisodicMemoryConnector.h:41
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:91
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::SimpleEpisodicMemoryKinematicUnitConnector::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:28
armarx::SimpleEpisodicMemoryKinematicUnitConnector::reportJointCurrents
void reportJointCurrents(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:202
IceUtil::Handle< class PropertyDefinitionContainer >
SimpleEpisodicMemoryKinematicUnitConnector.h
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::SimpleEpisodicMemoryKinematicUnitConnector::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:37
armarx::SimpleEpisodicMemoryKinematicUnitConnector::onConnectComponent
void onConnectComponent() override
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:57
memoryx::SimpleEpisodicMemoryConnector::m_simple_episodic_memory_proxy_name
std::string m_simple_episodic_memory_proxy_name
Definition: SimpleEpisodicMemoryConnector.h:40
armarx::ManagedIceObject::getProxy
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Definition: ManagedIceObject.cpp:393
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
armarx::SimpleEpisodicMemoryKinematicUnitConnector::reportJointMotorTemperatures
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long, bool, const Ice::Current &)
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:217
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::SimpleEpisodicMemoryKinematicUnitConnector::onExitComponent
void onExitComponent() override
Definition: SimpleEpisodicMemoryKinematicUnitConnector.cpp:72