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