SimpleEpisodicMemoryPlatformUnitConnector.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::SimpleEpisodicMemoryPlatformUnitConnector
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 
26 namespace armarx
27 {
28 
30  {
32 
33  def->topic<PlatformUnitListener>("Armar6PlatformUnit", "PlatformUnitName");
34  def->optional(frequency, "UpdateFrequency", "Frequency of updates in Hz");
35  return def;
36  }
37 
39  {
40  return "SimpleEpisodicMemoryPlatformUnitConnector";
41  }
42 
44  frequency(10),
45  updated_pose(false),
46  timestampLastUpdateInMs_pose(0),
47  updated_target(false),
48  timestampLastUpdateInMs_target(0)
49  {
50 
51  }
52 
53 
55  {
57  }
58 
59 
61  {
64  &SimpleEpisodicMemoryPlatformUnitConnector::checkAndSendToMemory, (1.0f / frequency * 1000));
65  periodic_task->start();
66  }
67 
68 
70  {
71  periodic_task->stop();
72  }
73 
74 
76  {
77 
78  }
79 
80  void SimpleEpisodicMemoryPlatformUnitConnector::checkAndSendToMemory()
81  {
82  std::lock_guard l(platformPose_mutex);
83  std::lock_guard ll(platformTarget_mutex);
84  std::lock_guard lll(platformAcceleration_mutex);
85 
86  {
87  std::lock_guard u(updatedMutex_pose);
88  if (updated_pose && timestampLastUpdateInMs_pose != 0)
89  {
90  memoryx::PlatformUnitEvent event;
91  event.receivedInMs = timestampLastUpdateInMs_pose;
92 
93  event.x = x;
94  event.y = y;
95  event.rot = rot;
96  event.acc_x = acc_x;
97  event.acc_y = acc_y;
98  event.acc_rot = acc_rot;
99 
100  m_simple_episodic_memory->registerPlatformUnitEvent(event);
101 
102  updated_pose = false;
103  timestampLastUpdateInMs_pose = 0;
104  }
105  }
106 
107  {
108  std::lock_guard u(updatedMutex_target);
109  if (updated_target && timestampLastUpdateInMs_target != 0)
110  {
111  memoryx::PlatformUnitTargetEvent event;
112  event.receivedInMs = timestampLastUpdateInMs_target;
113 
114  event.target_x = goal_x;
115  event.target_y = goal_y;
116  event.target_rot = goal_rot;
117 
118  m_simple_episodic_memory->registerPlatformUnitTargetEvent(event);
119 
120  updated_target = false;
121  timestampLastUpdateInMs_target = 0;
122  }
123  }
124  }
125 
126 
127  void SimpleEpisodicMemoryPlatformUnitConnector::reportPlatformPose(const PlatformPose& pose, const Ice::Current&)
128  {
129  std::lock_guard l(platformPose_mutex);
130  std::lock_guard u(updatedMutex_pose);
131  double received = IceUtil::Time::now().toMilliSecondsDouble();
132  x = pose.x;
133  y = pose.y;
134  rot = pose.rotationAroundZ;
135  updated_pose = true;
136  timestampLastUpdateInMs_pose = received;
137  }
138 
140  {
141  std::lock_guard l(platformTarget_mutex);
142  std::lock_guard u(updatedMutex_target);
143  double received = IceUtil::Time::now().toMilliSecondsDouble();
144  goal_x = t1;
145  goal_y = t2;
146  goal_rot = t3;
147  updated_target = true;
148  timestampLastUpdateInMs_target = received;
149  }
150 
152  {
153  std::lock_guard l(platformAcceleration_mutex);
154  std::lock_guard u(updatedMutex_pose);
155  double received = IceUtil::Time::now().toMilliSecondsDouble();
156  acc_x = v1;
157  acc_y = v2;
158  acc_rot = v3;
159  updated_pose = true;
160  timestampLastUpdateInMs_pose = received;
161  }
162 
164  {
165  }
166 
167 }
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::SimpleEpisodicMemoryPlatformUnitConnector::onInitComponent
void onInitComponent() override
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:54
armarx::SimpleEpisodicMemoryPlatformUnitConnector::reportPlatformVelocity
void reportPlatformVelocity(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &)
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:151
armarx::SimpleEpisodicMemoryPlatformUnitConnector::onDisconnectComponent
void onDisconnectComponent() override
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:69
armarx::SimpleEpisodicMemoryPlatformUnitConnector::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:29
armarx::SimpleEpisodicMemoryPlatformUnitConnector::reportNewTargetPose
void reportNewTargetPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &)
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:139
armarx::SimpleEpisodicMemoryPlatformUnitConnector::SimpleEpisodicMemoryPlatformUnitConnector
SimpleEpisodicMemoryPlatformUnitConnector()
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:43
memoryx::SimpleEpisodicMemoryConnector::m_simple_episodic_memory
memoryx::SimpleEpisodicMemoryInterface::ProxyType m_simple_episodic_memory
Definition: SimpleEpisodicMemoryConnector.h:41
SimpleEpisodicMemoryPlatformUnitConnector.h
armarx::SimpleEpisodicMemoryPlatformUnitConnector::onConnectComponent
void onConnectComponent() override
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:60
armarx::SimpleEpisodicMemoryPlatformUnitConnector::reportPlatformOdometryPose
void reportPlatformOdometryPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &)
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:163
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::SimpleEpisodicMemoryPlatformUnitConnector::getDefaultName
std::string getDefaultName() const override
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:38
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::SimpleEpisodicMemoryPlatformUnitConnector::reportPlatformPose
void reportPlatformPose(const PlatformPose &, const Ice::Current &)
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:127
armarx::PeriodicTask
Definition: ArmarXManager.h:70
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
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::SimpleEpisodicMemoryPlatformUnitConnector::onExitComponent
void onExitComponent() override
Definition: SimpleEpisodicMemoryPlatformUnitConnector.cpp:75