Go to the documentation of this file.
28 #include <Ice/ObjectAdapter.h>
30 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
39 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
49 const std::string remNames = getProperty<std::string>(
"RemoteObjectNodes").getValue();
58 [](
const std::string&
s) { return s ==
""; })));
78 remoteObjectNodes.emplace_back(getProxy<armarx::RemoteObjectNodeInterfacePrx>(name));
85 localNode = Component::create<RemoteObjectNode>(
91 RemoteObjectNodeInterfacePrx::uncheckedCast(
localNode->getProxy(-1)));
95 ARMARX_WARNING_S <<
"Starting motion planning server without any remote object "
96 "nodes! (some algorithms may still work)";
99 auto wm = getProxy<memoryx::WorkingMemoryInterfacePrx>(
"WorkingMemory",
false,
"",
false);
100 auto cs = getProxy<memoryx::CommonStorageInterfacePrx>(
"CommonStorage",
false,
"",
false);
102 getProxy<RobotStateComponentInterfacePrx>(
"RobotStateComponent",
false,
"",
false);
116 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
121 tasks.at(taskId).task->abortTask();
125 for (
auto& task :
tasks)
127 task.second.rh->forceDeletion();
160 std::unique_lock<std::recursive_mutex> lock{
queueMutex};
174 handle =
tasks.at(taskId);
182 << "\n\tname: " << handle.task->getTaskName() << "\n\tID: " << taskId \
183 << "\n\tice id = " << handle.task->ice_id() << "\n\tstatus " \
184 << TaskStatus::toString(handle.task->getTaskStatus())
191 auto start = IceUtil::Time::now();
196 t->addTaskStatusCallback(
197 [tp, start,
this](TaskStatus::Status
s)
199 if (
s == TaskStatus::eRefining)
201 auto duration = IceUtil::Time::now() - start;
202 tp->planningTime = duration.toMicroSeconds();
206 auto duration = IceUtil::Time::now() - start;
207 if (tp->planningTime > 0)
209 tp->refiningTime = duration.toMicroSeconds() - tp->planningTime;
213 tp->planningTime = duration.toMicroSeconds();
216 <<
": Planning time: " << tp->planningTime * 0.001f
217 <<
" ms, " << tp->refiningTime * 0.001f <<
" ms";
221 PostprocessingMotionPlanningTaskPtr::dynamicCast(t);
224 t = MotionPlanningTaskPtr::dynamicCast(tmp->previousStep);
231 handle.
task->run(ronCache);
233 catch (Ice::Exception& e)
236 << e.what() <<
"\n\tSTACK:\n"
237 << e.ice_stackTrace();
238 handle.
task->setTaskStatus(TaskStatus::eException);
240 catch (std::exception& e)
243 handle.
task->setTaskStatus(TaskStatus::eException);
248 <<
"\n\tsomething not derived from std::exception was thrown";
249 handle.
task->setTaskStatus(TaskStatus::eException);
256 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
267 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
268 auto it =
tasks.find(
id);
270 if (it ==
tasks.end())
277 it->second.task->abortTask();
287 armarx::ClientSideRemoteHandleControlBlockBasePtr
292 throw armarx::ServerShuttingDown{
"MotionPlanningServerComponent"};
304 planningTask->registerAtIceAdapter(adapter, ident);
310 MotionPlanningTaskControlInterfacePrx::uncheckedCast(planningTask->getProxy()),
311 [
id,
this, adapter, ident]
313 adapter->remove(ident);
319 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
323 planningTask->postEnqueueing();
328 return remoteHandleHandles.clientSideRemoteHandleControlBlock;
334 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
341 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
348 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
350 result.reserve(
tasks.size());
353 std::back_inserter(result),
354 [](
const decltype(
tasks)::value_type&
v)
358 return TaskInfo{
v.first,
359 rhs.
rh->getManagedObjectProxy()->ice_getIdentity(),
360 rhs.
task->getTaskStatus(),
362 rhs.
task->getTaskName()};
367 ClientSideRemoteHandleControlBlockBasePtr
370 ClientSideRemoteHandleControlBlockBasePtr remoteHandle;
373 remoteHandle =
currentTask.
rh->getClientSideRemoteHandleControlBlock();
381 CSpaceAndPaths result;
382 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
383 auto it =
tasks.find(
id);
384 if (it !=
tasks.end())
386 auto task = MotionPlanningTaskBasePtr::dynamicCast(it->second.task);
388 result.cspace = task ? task->getCSpace()->clone() :
nullptr;
389 auto multPathTask = MotionPlanningMultiPathTaskControlInterfacePtr::dynamicCast(task);
392 result.paths = multPathTask->getAllPaths();
396 result.paths.emplace_back(it->second.task->getPath());
407 MotionPlanningServer::loadLibFromAbsolutePath(
const std::string& path)
424 if (lib->isLibraryLoaded())
430 ARMARX_ERROR <<
"Could not load lib " + path +
": " + lib->getErrorMessage();
445 return loadLibFromAbsolutePath(absPath);
456 const std::string& name,
462 ARMARX_ERROR <<
"Could not find package '" <<
package << "'";
468 std::filesystem::path fullPath = libDirPath;
470 if (!std::filesystem::exists(fullPath))
472 fullPath = libDirPath;
474 if (!std::filesystem::exists(fullPath))
479 if (loadLibFromAbsolutePath(fullPath.string()))
484 ARMARX_ERROR <<
"Could not find library " << name <<
" in package " << package;
std::atomic_bool dispatcherKillRequest
Whether the dispatcher should shut down.
IceManagerPtr getIceManager() const
Returns the IceManager.
std::thread dispatcherThread
The dispatcher's thread.
bool packageFound() const
Returns whether or not this package was found with cmake.
std::shared_ptr< DynamicLibrary > DynamicLibraryPtr
std::condition_variable_any waitForTaskOrDispatcherKill
The dispatcher's cv.
std::vector< std::string > remoteObjectNodeNames
The used remote object nodes' names.
armarx::RemoteHandleControlBlockPtr rh
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
TaskMap tasks
The map of tasks.
void onConnectComponent() override
Connects to the used RemoteObjectNodes.
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
TaskAndRemoteHandle currentTask
currentTask stores a handle to the currently dispatched planning task.
CSpaceAndPaths getTaskCSpaceAndPathsById(Ice::Long id, const Ice::Current &=Ice::emptyCurrent) override
Returns a task's cspace and all found paths.
std::vector< armarx::RemoteObjectNodeInterfacePrx > remoteObjectNodes
The used remote object nodes.
std::string getLibraryPaths() const
Returns the library paths seperated by semi-colons.
bool loadLibFromPackage(const std::string &package, const std::string &lib, const Ice::Current &=Ice::emptyCurrent) override
static std::string GetSharedLibraryFileExtension()
void onInitComponent() override
Initializes the server and starts the dispatcher thread.
float localNodePercent
Percentage of cores used by the local ron (if started).
void onExitComponent() override
cleans up and joins the dispatcher
void Identity(MatrixXX< N, N, T > *a)
Ice::Long getNumberOfQueuedTasks(const Ice::Current &) const override
Returns the number of queued tasks.
bool finishedRunning(Status status)
Returns whether the given task status describes a state where planning is done (may be failed).
TaskInfoSeq getAllTaskInfo(const Ice::Current &=Ice::emptyCurrent) const override
Returns information about all tasks.
RemoteObjectNodePtr localNode
static std::string generateSubObjectName(const std::string &superObjectName, const std::string &subObjectName)
Generates a unique name for a sub object from a general name and unique name.
static SimoxCSpacePtr PrefetchWorkingMemoryObjects(memoryx::WorkingMemoryInterfacePrx workingMemoryPrx, memoryx::CommonStorageInterfacePrx commonStoragePrx, RobotStateComponentInterfacePrx rsc)
Load objects from WorkingMemory and puts them into the mesh cache.
armarx::ClientSideRemoteHandleControlBlockBasePtr enqueueTask(const MotionPlanningTaskBasePtr &task, const Ice::Current &=Ice::emptyCurrent) override
Enqueues a task.
const std::string & to_string(const std::string &s)
ClientSideRemoteHandleControlBlockBasePtr getCurrentTaskHandle(const Ice::Current &) override
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT >>
Convenience function (with less typing) to transform a container of type InputT into the same contain...
bool startLocalNode
Whether a local node should be started, if no rons were provided.
std::set< Ice::Long > taskQueue
Contains the queue of task ids to execute.
std::map< std::string, DynamicLibraryPtr > loadedLibs
bool loadLibFromPath(const std::string &path, const Ice::Current &=Ice::emptyCurrent) override
MotionPlanningTaskPtr task
double v(double t, double v0, double a0, double j)
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Ice::Long getNumberOfTasks(const Ice::Current &=Ice::emptyCurrent) const override
Returns the number of tasks.
Ice::Long getNewTaskId()
Returns a new task id.
void dispatcherTask()
the dispatcher task.
double distance(const Point &a, const Point &b)
std::string getName() const
Retrieve name of object.
SimoxCSpacePtr cacheCSpace
std::recursive_mutex queueMutex
mutex protecting the task queue
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
void setTag(const LogTag &tag)
Ice::CommunicatorPtr getCommunicator() const
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
double s(double t, double s0, double v0, double a0, double j)
static ManagementData create(ArmarXManagerPtr manager, Ice::ObjectPrx managedObjectPrx, Deleter deleter)
Creates a new RemoteHandleControlBlock.
This file offers overloads of toIce() and fromIce() functions for STL container types.
static void RegisterKnownObjectFactoriesWithIce(const Ice::CommunicatorPtr &ic)
Registers all object factories that are known with Ice.
bool deleteTaskById(Ice::Long id)