SkillsMemory.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 RobotAPI::ArmarXObjects::SkillsMemory
17  * @author Rainer Kartmann ( rainer dot kartmann 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 
23 #include "SkillsMemory.h"
24 #include <vector>
25 
26 #include <SimoxUtility/algorithm/string.h>
27 
34 
37 #include <RobotAPI/interface/skills/SkillManagerInterface.h>
43 #include <RobotAPI/libraries/skills/core/aron/FluxioSkill.aron.generated.h>
44 
45 namespace armarx
46 {
47 
49  ReadWritePluginUser(),
52  statechartListenerProviderSegment(iceAdapter()),
53  executableSkillCoreSegment(iceAdapter()),
54  composedSkillCoreSegment(iceAdapter()),
55  profileCoreSegment(iceAdapter()),
56  skillEventCoreSegment(iceAdapter()),
57  skillExecutionRequestCoreSegment(iceAdapter())
58  {
59  }
60 
63  {
66 
67  const std::string prefix = "mem.";
68  statechartListenerProviderSegment.defineProperties(defs, prefix + "statechartlistener.");
69  executableSkillCoreSegment.defineProperties(defs, prefix + "executableskill.");
70  composedSkillCoreSegment.defineProperties(defs, prefix + "composedskill.");
71  profileCoreSegment.defineProperties(defs, prefix + "profile.");
72  skillExecutionRequestCoreSegment.defineProperties(defs, prefix + "executionrequest.");
73  skillEventCoreSegment.defineProperties(defs, prefix + "event.");
74 
75  setMemoryName(MemoryName);
76  return defs;
77  }
78 
79  std::string
81  {
82  return "SkillMemory";
83  }
84 
85  void
87  {
88  statechartListenerProviderSegment.init();
89  executableSkillCoreSegment.init();
90  composedSkillCoreSegment.init();
91  profileCoreSegment.init();
92  skillExecutionRequestCoreSegment.init();
93  skillEventCoreSegment.init();
94  }
95 
96  void
98  {
99  }
100 
101  void
103  {
104  }
105 
106  void
108  {
109  }
110 
111  armem::data::CommitResult
112  SkillsMemory::commit(const armem::data::Commit& commit, const Ice::Current& current)
113  {
114  // This function is overloaded to check for skill executions
115  // First pass arg to parent func to ensure that data is written into memory and that clients are notified
116  armem::data::CommitResult result = ReadWritePluginUser::commit(commit);
117 
118  skills::callback::dti::SkillProviderCallbackInterfacePrx myPrx;
119  getProxy(myPrx, -1);
120 
121  for (const auto& up : commit.updates)
122  {
123  if (up.entityID.coreSegmentName ==
125  {
126  for (const auto& instance : up.instancesData)
127  {
128  ARMARX_CHECK_NOT_NULL(instance);
129 
131  skillExecutionRequestCoreSegment.convertCommit(instance);
133  }
134  }
135  }
136 
137  return result;
138  }
139 
140  void
141  SkillsMemory::addProvider(const skills::manager::dto::ProviderInfo& info,
142  const Ice::Current& current)
143  {
144  ARMARX_INFO << "Adding provider to skill memory: " << info.providerId.providerName;
146 
147  // log skills to memory
148  auto p = skills::ProviderInfo::FromIce(info);
149  executableSkillCoreSegment.addSkillProvider(p);
150  }
151 
152  void
153  SkillsMemory::removeProvider(const skills::manager::dto::ProviderID& provider,
154  const Ice::Current& current)
155  {
156  executableSkillCoreSegment.removeSkillProvider(provider.providerName);
157 
158  // remove skills from memory
160  }
161 
162  skills::manager::dto::SkillStatusUpdate
163  SkillsMemory::executeSkill(const skills::manager::dto::SkillExecutionRequest& info,
164  const Ice::Current& current)
165  {
167  skillExecutionRequestCoreSegment.addSkillExecutionRequest(e);
168 
169  return SkillManagerComponentPluginUser::executeSkill(info, current);
170  }
171 
172  skills::manager::dto::SkillExecutionID
173  SkillsMemory::executeSkillAsync(const skills::manager::dto::SkillExecutionRequest& info,
174  const Ice::Current& current)
175  {
177  skillExecutionRequestCoreSegment.addSkillExecutionRequest(e);
178 
180  }
181 
182  void
183  SkillsMemory::updateStatusForSkill(const skills::provider::dto::SkillStatusUpdate& update,
184  const skills::callback::dto::ProviderID& providerId,
185  const Ice::Current& current)
186  {
187  auto p = skills::ProviderID::FromIce(providerId);
189  skillEventCoreSegment.addSkillUpdateEvent(u);
190  }
191 
192  IceUtil::Optional<skills::manager::dto::SkillStatusUpdate>
193  SkillsMemory::getSkillExecutionStatus(const skills::manager::dto::SkillExecutionID& executionId,
194  const Ice::Current& current)
195  {
196  auto eid = skills::SkillExecutionID::FromIce(executionId);
197  auto op = this->skillEventCoreSegment.getSkillStatusUpdate(eid);
198  if (op.has_value())
199  {
200  return op->toManagerIce();
201  }
202  return {};
203  }
204 
205  skills::manager::dto::SkillStatusUpdateMap
206  SkillsMemory::getSkillExecutionStatuses(const Ice::Current& current)
207  {
208  skills::manager::dto::SkillStatusUpdateMap ret;
209  auto updates = this->skillEventCoreSegment.getSkillStatusUpdates();
210  for (const auto& [k, v] : updates)
211  {
212  ret.insert({k.toManagerIce(), v.toManagerIce()});
213  }
214  return ret;
215  }
216 
217  /*
218  * Statechart stuff
219  */
220  void
222  const ProfilerStatechartTransitionWithParameters& x,
223  const Ice::Current&)
224  {
225  statechartListenerProviderSegment.reportStatechartTransitionWithParameters(x);
226  }
227 
228  void
230  const ProfilerStatechartTransitionWithParametersList& x,
231  const Ice::Current&)
232  {
233  statechartListenerProviderSegment.reportStatechartTransitionWithParametersList(x);
234  }
235 
236  //****************************//
237  //** Fluxio related methods **//
238  //****************************//
239 
240  void SkillsMemory::saveSkill(const skills::manager::arondto::FluxioSkill& skill)
241  {
242  composedSkillCoreSegment.addSkill(skill);
243  }
244 
245  std::optional<std::vector<skills::manager::arondto::FluxioSkill>> SkillsMemory::loadCompositeSkills()
246  {
247  return composedSkillCoreSegment.getSkills();
248  }
249 
250  std::optional<std::vector<skills::manager::arondto::FluxioSkill>> SkillsMemory::loadCompositeSkillsOfProvider(const std::string& providerId)
251  {
252  return composedSkillCoreSegment.getSkillsOfProvider(providerId);
253  }
254 
255  void SkillsMemory::addProfile(const skills::manager::arondto::FluxioProfile& profile)
256  {
257  profileCoreSegment.addProfile(profile);
258  }
259 
260  std::optional<std::vector<skills::manager::arondto::FluxioProfile>> SkillsMemory::loadProfiles()
261  {
262  return profileCoreSegment.getProfiles();
263  }
264 } // namespace armarx
armarx::skills::segment::StatechartListenerProviderSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: StatechartListenerSegment.cpp:18
armarx::SkillsMemory::saveSkill
void saveSkill(const skills::manager::arondto::FluxioSkill &skillt) override
Definition: SkillsMemory.cpp:240
armarx::SkillsMemory::removeProvider
void removeProvider(const skills::manager::dto::ProviderID &provider, const Ice::Current &current) override
Definition: SkillsMemory.cpp:153
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
armarx::SkillsMemory::onExitComponent
void onExitComponent() override
Definition: SkillsMemory.cpp:107
armarx::skills::segment::ComposedSkillLibraryCoreSegment::addSkill
void addSkill(const skills::manager::arondto::FluxioSkill &skill)
Definition: ComposedSkillLibrarySegment.cpp:43
armarx::SkillsMemory::addProvider
void addProvider(const skills::manager::dto::ProviderInfo &info, const Ice::Current &current) override
Definition: SkillsMemory.cpp:141
armarx::skills::segment::ComposedSkillLibraryCoreSegment::getSkills
std::optional< std::vector< skills::manager::arondto::FluxioSkill > > getSkills() const
Definition: ComposedSkillLibrarySegment.cpp:62
armarx::skills::SkillStatusUpdate::FromIce
static SkillStatusUpdate FromIce(const provider::dto::SkillStatusUpdate &update, const std::optional< skills::ProviderID > &providerId=std::nullopt)
Definition: SkillStatusUpdate.cpp:369
armarx::SkillsMemory::getSkillExecutionStatus
IceUtil::Optional< skills::manager::dto::SkillStatusUpdate > getSkillExecutionStatus(const skills::manager::dto::SkillExecutionID &executionId, const Ice::Current &current) override
Definition: SkillsMemory.cpp:193
armarx::SkillManagerComponentPluginUser::executeSkill
skills::manager::dto::SkillStatusUpdate executeSkill(const skills::manager::dto::SkillExecutionRequest &info, const Ice::Current &current) override
Definition: SkillManagerComponentPluginUser.cpp:74
armarx::skills::segment::ExecutableSkillLibraryCoreSegment::init
void init()
Definition: ExecutableSkillLibrarySegment.cpp:30
armarx::skills::segment::ComposedSkillLibraryCoreSegment::init
void init()
Definition: ComposedSkillLibrarySegment.cpp:37
ArmarXManager.h
armarx::SkillsMemory::onDisconnectComponent
void onDisconnectComponent() override
Definition: SkillsMemory.cpp:102
armarx::SkillsMemory::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SkillsMemory.cpp:62
SkillManagerComponentPluginUser.h
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::skills::segment::ExecutableSkillLibraryCoreSegment::removeSkillProvider
void removeSkillProvider(const std::string &providerName)
Definition: ExecutableSkillLibrarySegment.cpp:62
armarx::skills::segment::SkillExecutionRequestCoreSegment::convertCommit
skills::SkillExecutionRequest convertCommit(const aron::data::dto::DictPtr &commitData)
Definition: SkillExecutionRequestSegment.cpp:34
armarx::skills::SkillExecutionRequest::FromIce
static SkillExecutionRequest FromIce(const manager::dto::SkillExecutionRequest &)
Definition: SkillExecutionRequest.cpp:29
armarx::SkillsMemory::getDefaultName
std::string getDefaultName() const override
Definition: SkillsMemory.cpp:80
armarx::SkillsMemory::onConnectComponent
void onConnectComponent() override
Definition: SkillsMemory.cpp:97
armarx::armem::server::plugins::ReadWritePluginUser::setMemoryName
void setMemoryName(const std::string &memoryName)
Definition: ReadWritePluginUser.cpp:25
armarx::skills::segment::SkillEventCoreSegment::init
void init()
Definition: SkillEventSegment.cpp:28
armarx::skills::ProviderInfo::FromIce
static ProviderInfo FromIce(const manager::dto::ProviderInfo &)
Definition: ProviderInfo.cpp:22
armarx::skills::segment::StatechartListenerProviderSegment::init
void init()
Definition: StatechartListenerSegment.cpp:38
armarx::skills::segment::ProfileLibraryCoreSegment::addProfile
void addProfile(const skills::manager::arondto::FluxioProfile &profile)
Definition: ProfileLibrarySegment.cpp:40
armarx::SkillsMemory::loadProfiles
std::optional< std::vector< skills::manager::arondto::FluxioProfile > > loadProfiles() override
Definition: SkillsMemory.cpp:260
armarx::SkillsMemory::reportStatechartTransitionWithParametersList
void reportStatechartTransitionWithParametersList(const ProfilerStatechartTransitionWithParametersList &, const Ice::Current &) override
Definition: SkillsMemory.cpp:229
armarx::SkillsMemory::commit
armem::data::CommitResult commit(const armem::data::Commit &commit, const Ice::Current &) override
Definition: SkillsMemory.cpp:112
armarx::skills::segment::ProfileLibraryCoreSegment::init
void init()
Definition: ProfileLibrarySegment.cpp:34
armarx::SkillManagerComponentPluginUser::executeSkillAsync
skills::manager::dto::SkillExecutionID executeSkillAsync(const skills::manager::dto::SkillExecutionRequest &skillExecutionRequest, const Ice::Current &current) override
Definition: SkillManagerComponentPluginUser.cpp:83
armarx::skills::segment::SkillExecutionRequestCoreSegment::init
void init()
Definition: SkillExecutionRequestSegment.cpp:28
ComposedSkillLibrarySegment.h
armarx::skills::segment::SkillExecutionRequestCoreSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: SkillExecutionRequestSegment.cpp:20
armarx::skills::SkillExecutionRequest
Definition: SkillExecutionRequest.h:13
armarx::skills::segment::StatechartListenerProviderSegment::reportStatechartTransitionWithParametersList
void reportStatechartTransitionWithParametersList(const ProfilerStatechartTransitionWithParametersList &)
Definition: StatechartListenerSegment.cpp:69
armarx::skills::segment::ComposedSkillLibraryCoreSegment::getSkillsOfProvider
std::optional< std::vector< skills::manager::arondto::FluxioSkill > > getSkillsOfProvider(const std::string &providerId) const
Definition: ComposedSkillLibrarySegment.cpp:91
memory_definitions.h
armarx::SkillsMemory::reportStatechartTransitionWithParameters
void reportStatechartTransitionWithParameters(const ProfilerStatechartTransitionWithParameters &, const Ice::Current &) override
Definition: SkillsMemory.cpp:221
LocalTimeServer.h
armarx::SkillsMemory::updateStatusForSkill
void updateStatusForSkill(const skills::provider::dto::SkillStatusUpdate &update, const skills::callback::dto::ProviderID &id, const Ice::Current &current) override
Definition: SkillsMemory.cpp:183
SkillsMemory.h
aron_conversions.h
armarx::skills::segment::SkillExecutionRequestCoreSegment::CoreSegmentName
static constexpr const char * CoreSegmentName
Definition: SkillExecutionRequestSegment.h:22
error.h
armarx::SkillsMemory::loadCompositeSkillsOfProvider
std::optional< std::vector< skills::manager::arondto::FluxioSkill > > loadCompositeSkillsOfProvider(const std::string &providerId) override
Definition: SkillsMemory.cpp:250
armarx::SkillsMemory::addProfile
void addProfile(const skills::manager::arondto::FluxioProfile &profile) override
Definition: SkillsMemory.cpp:255
armarx::SkillsMemory::executeSkillAsync
skills::manager::dto::SkillExecutionID executeSkillAsync(const skills::manager::dto::SkillExecutionRequest &info, const Ice::Current &current) override
Definition: SkillsMemory.cpp:173
armarx::SkillsMemory::SkillsMemory
SkillsMemory()
Definition: SkillsMemory.cpp:48
ArmarXObjectScheduler.h
armarx::SkillManagerComponentPluginUser
Definition: SkillManagerComponentPluginUser.h:21
armarx::SkillManagerComponentPluginUser::removeProvider
void removeProvider(const skills::manager::dto::ProviderID &provider, const Ice::Current &current) override
Definition: SkillManagerComponentPluginUser.cpp:65
armarx::SkillsMemory::onInitComponent
void onInitComponent() override
Definition: SkillsMemory.cpp:86
armarx::skills::segment::StatechartListenerProviderSegment::reportStatechartTransitionWithParameters
void reportStatechartTransitionWithParameters(const ProfilerStatechartTransitionWithParameters &)
Definition: StatechartListenerSegment.cpp:44
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:68
armarx::skills::SkillExecutionRequest::toManagerIce
manager::dto::SkillExecutionRequest toManagerIce() const
Definition: SkillExecutionRequest.cpp:8
MemoryToIceAdapter.h
memory_definitions.h
ExpressionException.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
armarx::SkillsMemory::loadCompositeSkills
std::optional< std::vector< skills::manager::arondto::FluxioSkill > > loadCompositeSkills() override
Definition: SkillsMemory.cpp:245
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::skills::segment::SkillEventCoreSegment::getSkillStatusUpdates
std::map< skills::SkillExecutionID, skills::SkillStatusUpdate > getSkillStatusUpdates()
Definition: SkillEventSegment.cpp:57
armarx::SkillManagerComponentPluginUser::addProvider
void addProvider(const skills::manager::dto::ProviderInfo &providerInfo, const Ice::Current &current) override
Definition: SkillManagerComponentPluginUser.cpp:40
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::skills::segment::SkillEventCoreSegment::addSkillUpdateEvent
void addSkillUpdateEvent(const skills::SkillStatusUpdate &update)
Definition: SkillEventSegment.cpp:34
armarx::skills::SkillExecutionID::FromIce
static SkillExecutionID FromIce(const skills::manager::dto::SkillExecutionID &)
Definition: SkillExecutionID.cpp:31
armarx::StatechartListenerComponentPluginUser
Definition: StatechartListenerComponentPlugin.h:25
armarx::SkillsMemory::getSkillExecutionStatuses
skills::manager::dto::SkillStatusUpdateMap getSkillExecutionStatuses(const Ice::Current &current) override
Definition: SkillsMemory.cpp:206
armarx::skills::segment::ProfileLibraryCoreSegment::getProfiles
std::optional< std::vector< skills::manager::arondto::FluxioProfile > > getProfiles() const
Definition: ProfileLibrarySegment.cpp:58
Logging.h
armarx::skills::segment::ProfileLibraryCoreSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: ProfileLibrarySegment.cpp:26
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:407
armarx::skills::segment::ExecutableSkillLibraryCoreSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: ExecutableSkillLibrarySegment.cpp:22
armarx::SkillsMemory::executeSkill
skills::manager::dto::SkillStatusUpdate executeSkill(const skills::manager::dto::SkillExecutionRequest &info, const Ice::Current &current) override
Definition: SkillsMemory.cpp:163
armarx::skills::segment::SkillEventCoreSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: SkillEventSegment.cpp:21
armarx::skills::segment::SkillEventCoreSegment::getSkillStatusUpdate
std::optional< skills::SkillStatusUpdate > getSkillStatusUpdate(const skills::SkillExecutionID &id)
Definition: SkillEventSegment.cpp:92
armarx::skills::segment::SkillExecutionRequestCoreSegment::addSkillExecutionRequest
void addSkillExecutionRequest(const skills::SkillExecutionRequest &info)
Definition: SkillExecutionRequestSegment.cpp:51
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::skills::ProviderID::FromIce
static ProviderID FromIce(const manager::dto::ProviderID &)
Definition: ProviderID.cpp:32
armarx::skills::segment::ExecutableSkillLibraryCoreSegment::addSkillProvider
void addSkillProvider(const skills::ProviderInfo &info)
Definition: ExecutableSkillLibrarySegment.cpp:36
armarx::skills::segment::ComposedSkillLibraryCoreSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: ComposedSkillLibrarySegment.cpp:29