28#include <Ice/ObjectAdapter.h>
30#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
39#include <MemoryX/interface/components/PriorKnowledgeInterface.h>
58 [](
const std::string& s) { return s ==
""; })));
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)";
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)
356 const TaskAndRemoteHandle& rhs = v.second;
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)
409 if (loadedLibs.count(path) > 0)
413 DynamicLibraryPtr lib(
new DynamicLibrary());
424 if (lib->isLibraryLoaded())
426 loadedLibs[path] = lib;
430 ARMARX_ERROR <<
"Could not load lib " + path +
": " + lib->getErrorMessage();
434 ArmarXManager::RegisterKnownObjectFactoriesWithIce(
435 this->getIceManager()->getCommunicator());
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;
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
std::string getLibraryPaths() const
Returns the library paths seperated by semi-colons.
bool packageFound() const
Returns whether or not this package was found with cmake.
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
Property< PropertyType > getProperty(const std::string &name)
static std::string GetSharedLibraryFileExtension()
void setTag(const LogTag &tag)
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.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
std::string getName() const
Retrieve name of object.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
TaskAndRemoteHandle currentTask
currentTask stores a handle to the currently dispatched planning task.
std::thread dispatcherThread
The dispatcher's thread.
ClientSideRemoteHandleControlBlockBasePtr getCurrentTaskHandle(const Ice::Current &) override
void onInitComponent() override
Initializes the server and starts the dispatcher thread.
std::vector< armarx::RemoteObjectNodeInterfacePrx > remoteObjectNodes
The used remote object nodes.
std::recursive_mutex queueMutex
mutex protecting the task queue
bool startLocalNode
Whether a local node should be started, if no rons were provided.
Ice::Long getNumberOfTasks(const Ice::Current &=Ice::emptyCurrent) const override
Returns the number of tasks.
float localNodePercent
Percentage of cores used by the local ron (if started).
bool loadLibFromPackage(const std::string &package, const std::string &lib, const Ice::Current &=Ice::emptyCurrent) override
armarx::ClientSideRemoteHandleControlBlockBasePtr enqueueTask(const MotionPlanningTaskBasePtr &task, const Ice::Current &=Ice::emptyCurrent) override
Enqueues a task.
std::vector< std::string > remoteObjectNodeNames
The used remote object nodes' names.
TaskMap tasks
The map of tasks.
TaskInfoSeq getAllTaskInfo(const Ice::Current &=Ice::emptyCurrent) const override
Returns information about all tasks.
std::condition_variable_any waitForTaskOrDispatcherKill
The dispatcher's cv.
std::set< Ice::Long > taskQueue
Contains the queue of task ids to execute.
std::atomic_bool dispatcherKillRequest
Whether the dispatcher should shut down.
void dispatcherTask()
the dispatcher task.
bool loadLibFromPath(const std::string &path, const Ice::Current &=Ice::emptyCurrent) override
void onConnectComponent() override
Connects to the used RemoteObjectNodes.
SimoxCSpacePtr cacheCSpace
void onExitComponent() override
cleans up and joins the dispatcher
Ice::Long getNewTaskId()
Returns a new task id.
CSpaceAndPaths getTaskCSpaceAndPathsById(Ice::Long id, const Ice::Current &=Ice::emptyCurrent) override
Returns a task's cspace and all found paths.
RemoteObjectNodePtr localNode
Ice::Long getNumberOfQueuedTasks(const Ice::Current &) const override
Returns the number of queued tasks.
bool deleteTaskById(Ice::Long id)
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
static ManagementData create(ArmarXManagerPtr manager, Ice::ObjectPrx managedObjectPrx, Deleter deleter)
Creates a new RemoteHandleControlBlock.
static SimoxCSpacePtr PrefetchWorkingMemoryObjects(memoryx::WorkingMemoryInterfacePrx workingMemoryPrx, memoryx::CommonStorageInterfacePrx commonStoragePrx, RobotStateComponentInterfacePrx rsc)
Load objects from WorkingMemory and puts them into the mesh cache.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_VERBOSE
The logging level for verbose information.
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
bool finishedRunning(Status status)
Returns whether the given task status describes a state where planning is done (may be failed).
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< PostprocessingMotionPlanningTask > PostprocessingMotionPlanningTaskPtr
IceInternal::Handle< MotionPlanningTask > MotionPlanningTaskPtr
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
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...
const std::string & to_string(const std::string &s)
MotionPlanningTaskPtr task
armarx::RemoteHandleControlBlockPtr rh