RequestObjects.cpp
Go to the documentation of this file.
1#include "RequestObjects.h"
2
3//#include <ArmarXCore/core/time/TimeUtil.h>
4//#include <ArmarXCore/observers/variant/DatafieldRef.h>
5
9
10#include "ObjectMemoryGroupStatechartContext.generated.h"
11
13{
14 // DO NOT EDIT NEXT LINE
15 RequestObjects::SubClassRegistry RequestObjects::Registry(RequestObjects::GetName(),
17
20 RequestObjectsGeneratedBase<RequestObjects>(stateData)
21 {
22 }
23
24 void
26 {
27
28 // put your user code for the enter-point here
29 // execution time should be short (<100ms)
30 }
31
32 void
34 {
35 if (not in.getEnable())
36 {
37 emitSuccess();
38 return;
39 }
40
42
43 const std::string provider = in.isProviderSet() ? in.getProvider() : "";
44
45 const std::vector<std::string> objectIdsString = in.getObjectIds();
46 const armarx::Duration relativeTimeout =
47 armarx::Duration::MilliSeconds(in.getRelativeTimeoutMilliseconds());
48
49 std::stringstream info;
50 std::stringstream warn;
51
52 std::vector<armarx::ObjectID> objectIds;
53 for (const std::string& idString : objectIdsString)
54 {
55 try
56 {
58 objectIds.push_back(id);
59 info << "Requesting object " << id << "\n";
60 }
61 catch (const armarx::LocalException& e)
62 {
63 warn << "\nGiven object ID '" << idString
64 << "' could not parsed as ObjectID: " << e.what();
65 }
66 }
67
68 auto context = getContext<ObjectMemoryGroupStatechartContext>();
69 armarx::armem::client::MemoryNameSystem mns(getMemoryNameSystem(), context);
70
71 Reader reader;
72 reader.connect(mns);
73 objpose::ObjectPoseStorageInterfacePrx storage = reader.getObjectPoseStorage();
74
75 armarx::objpose::observer::RequestObjectsInput input;
76 input.provider = provider;
77 for (const armarx::ObjectID& id : objectIds)
78 {
79 armarx::toIce(input.request.objectIDs.emplace_back(), id);
80 }
81 input.request.relativeTimeoutMS = relativeTimeout.toMilliSeconds();
82
83
84 objpose::observer::RequestObjectsOutput output;
85 try
86 {
87 output = storage->requestObjects(input);
88 }
89 catch (const Ice::Exception& e)
90 {
91 ARMARX_WARNING << "Failed to request object localization: " << e.what();
92 emitFailure();
93 return;
94 }
95
96 for (const auto& [id, result] : output.results)
97 {
98 if (result.result.success)
99 {
100 info << "Requested object " << id << " via provider '" << result.providerName
101 << "'.\n";
102 }
103 else
104 {
105 warn << "\nFailed to request the object " << id << " for localization.";
106 }
107 }
108
109 if (not info.str().empty())
110 {
111 ARMARX_INFO << info.str();
112 }
113 if (not warn.str().empty())
114 {
116 << "The following issues occurred whhen requesting objects for localization:"
117 << warn.str();
118 }
119
120 emitSuccess();
121 }
122
123 //void RequestObjects::onBreak()
124 //{
125 // // put your user code for the breaking point here
126 // // execution time should be short (<100ms)
127 //}
128
129 void
131 {
132 // put your user code for the exit point here
133 // execution time should be short (<100ms)
134 }
135
136 // DO NOT EDIT NEXT FUNCTION
142} // namespace armarx::ObjectMemoryGroup
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
static ObjectID FromString(const std::string &idString)
Construct from a string produced by str(), e.g. ("mydataset/myobject", "mydataset/myclass/myinstance"...
Definition ObjectID.cpp:34
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
RequestObjects(const XMLStateConstructorParams &stateData)
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
The memory name system (MNS) client.
Represents a duration.
Definition Duration.h:17
std::int64_t toMilliSeconds() const
Returns the amount of milliseconds.
Definition Duration.cpp:60
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)