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
25namespace armarx
26{
27
30 {
33
34 def->topic<PlatformUnitListener>("Armar6PlatformUnit", "PlatformUnitName");
35 def->optional(frequency, "UpdateFrequency", "Frequency of updates in Hz");
36 return def;
37 }
38
39 std::string
41 {
42 return "SimpleEpisodicMemoryPlatformUnitConnector";
43 }
44
46 frequency(10),
47 updated_pose(false),
48 timestampLastUpdateInMs_pose(0),
49 updated_target(false),
50 timestampLastUpdateInMs_target(0)
51 {
52 }
53
54 void
59
60 void
62 {
65 this,
66 &SimpleEpisodicMemoryPlatformUnitConnector::checkAndSendToMemory,
67 (1.0f / frequency * 1000));
68 periodic_task->start();
69 }
70
71 void
76
77 void
81
82 void
83 SimpleEpisodicMemoryPlatformUnitConnector::checkAndSendToMemory()
84 {
85 std::lock_guard l(platformPose_mutex);
86 std::lock_guard ll(platformTarget_mutex);
87 std::lock_guard lll(platformAcceleration_mutex);
88
89 {
90 std::lock_guard u(updatedMutex_pose);
91 if (updated_pose && timestampLastUpdateInMs_pose != 0)
92 {
93 memoryx::PlatformUnitEvent event;
94 event.receivedInMs = timestampLastUpdateInMs_pose;
95
96 event.x = x;
97 event.y = y;
98 event.rot = rot;
99 event.acc_x = acc_x;
100 event.acc_y = acc_y;
101 event.acc_rot = acc_rot;
102
103 m_simple_episodic_memory->registerPlatformUnitEvent(event);
104
105 updated_pose = false;
106 timestampLastUpdateInMs_pose = 0;
107 }
108 }
109
110 {
111 std::lock_guard u(updatedMutex_target);
112 if (updated_target && timestampLastUpdateInMs_target != 0)
113 {
114 memoryx::PlatformUnitTargetEvent event;
115 event.receivedInMs = timestampLastUpdateInMs_target;
116
117 event.target_x = goal_x;
118 event.target_y = goal_y;
119 event.target_rot = goal_rot;
120
121 m_simple_episodic_memory->registerPlatformUnitTargetEvent(event);
122
123 updated_target = false;
124 timestampLastUpdateInMs_target = 0;
125 }
126 }
127 }
128
129 void
131 const Ice::Current&)
132 {
133 std::lock_guard l(platformPose_mutex);
134 std::lock_guard u(updatedMutex_pose);
135 double received = IceUtil::Time::now().toMilliSecondsDouble();
136 x = pose.x;
137 y = pose.y;
138 rot = pose.rotationAroundZ;
139 updated_pose = true;
140 timestampLastUpdateInMs_pose = received;
141 }
142
143 void
145 Ice::Float t2,
146 Ice::Float t3,
147 const Ice::Current&)
148 {
149 std::lock_guard l(platformTarget_mutex);
150 std::lock_guard u(updatedMutex_target);
151 double received = IceUtil::Time::now().toMilliSecondsDouble();
152 goal_x = t1;
153 goal_y = t2;
154 goal_rot = t3;
155 updated_target = true;
156 timestampLastUpdateInMs_target = received;
157 }
158
159 void
161 Ice::Float v2,
162 Ice::Float v3,
163 const Ice::Current&)
164 {
165 std::lock_guard l(platformAcceleration_mutex);
166 std::lock_guard u(updatedMutex_pose);
167 double received = IceUtil::Time::now().toMilliSecondsDouble();
168 acc_x = v1;
169 acc_y = v2;
170 acc_rot = v3;
171 updated_pose = true;
172 timestampLastUpdateInMs_pose = received;
173 }
174
175 void
177 Ice::Float,
178 Ice::Float,
179 const Ice::Current&)
180 {
181 }
182
183} // 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 reportPlatformVelocity(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &)
void reportPlatformOdometryPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &)
void reportNewTargetPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &)
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.