30#include <Ice/ObjectAdapter.h>
32#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
41#include <MemoryX/interface/components/PriorKnowledgeInterface.h>
60 [](
const std::string& s) { return s ==
""; })));
93 RemoteObjectNodeInterfacePrx::uncheckedCast(
localNode->getProxy(-1)));
97 ARMARX_WARNING_S <<
"Starting motion planning server without any remote object "
98 "nodes! (some algorithms may still work)";
118 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
123 tasks.at(taskId).task->abortTask();
127 for (
auto& task :
tasks)
129 task.second.rh->forceDeletion();
162 std::unique_lock<std::recursive_mutex> lock{
queueMutex};
176 handle =
tasks.at(taskId);
184 << "\n\tname: " << handle.task->getTaskName() << "\n\tID: " << taskId \
185 << "\n\tice id = " << handle.task->ice_id() << "\n\tstatus " \
186 << TaskStatus::toString(handle.task->getTaskStatus())
193 auto start = IceUtil::Time::now();
198 t->addTaskStatusCallback(
199 [tp, start,
this](TaskStatus::Status s)
201 if (s == TaskStatus::eRefining)
203 auto duration = IceUtil::Time::now() - start;
204 tp->planningTime = duration.toMicroSeconds();
208 auto duration = IceUtil::Time::now() - start;
209 if (tp->planningTime > 0)
211 tp->refiningTime = duration.toMicroSeconds() - tp->planningTime;
215 tp->planningTime = duration.toMicroSeconds();
218 <<
": Planning time: " << tp->planningTime * 0.001f
219 <<
" ms, " << tp->refiningTime * 0.001f <<
" ms";
223 PostprocessingMotionPlanningTaskPtr::dynamicCast(t);
226 t = MotionPlanningTaskPtr::dynamicCast(tmp->previousStep);
233 handle.
task->run(ronCache);
235 catch (Ice::Exception& e)
238 << e.what() <<
"\n\tSTACK:\n"
239 << e.ice_stackTrace();
240 handle.
task->setTaskStatus(TaskStatus::eException);
242 catch (std::exception& e)
245 handle.
task->setTaskStatus(TaskStatus::eException);
250 <<
"\n\tsomething not derived from std::exception was thrown";
251 handle.
task->setTaskStatus(TaskStatus::eException);
258 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
269 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
270 auto it =
tasks.find(
id);
272 if (it ==
tasks.end())
279 it->second.task->abortTask();
289 armarx::ClientSideRemoteHandleControlBlockBasePtr
294 throw armarx::ServerShuttingDown{
"MotionPlanningServerComponent"};
306 planningTask->registerAtIceAdapter(adapter, ident);
312 MotionPlanningTaskControlInterfacePrx::uncheckedCast(planningTask->getProxy()),
313 [
id,
this, adapter, ident]
315 adapter->remove(ident);
321 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
325 planningTask->postEnqueueing();
330 return remoteHandleHandles.clientSideRemoteHandleControlBlock;
336 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
343 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
350 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
352 result.reserve(
tasks.size());
355 std::back_inserter(result),
356 [](
const decltype(
tasks)::value_type& v)
358 const TaskAndRemoteHandle& rhs = v.second;
360 return TaskInfo{v.first,
361 rhs.rh->getManagedObjectProxy()->ice_getIdentity(),
362 rhs.task->getTaskStatus(),
364 rhs.task->getTaskName()};
369 ClientSideRemoteHandleControlBlockBasePtr
372 ClientSideRemoteHandleControlBlockBasePtr remoteHandle;
375 remoteHandle =
currentTask.rh->getClientSideRemoteHandleControlBlock();
383 CSpaceAndPaths result;
384 std::lock_guard<std::recursive_mutex> lock{
queueMutex};
385 auto it =
tasks.find(
id);
386 if (it !=
tasks.end())
388 auto task = MotionPlanningTaskBasePtr::dynamicCast(it->second.task);
390 result.cspace = task ? task->getCSpace()->clone() :
nullptr;
391 auto multPathTask = MotionPlanningMultiPathTaskControlInterfacePtr::dynamicCast(task);
394 result.paths = multPathTask->getAllPaths();
398 result.paths.emplace_back(it->second.task->getPath());
409 MotionPlanningServer::loadLibFromAbsolutePath(
const std::string& path)
411 if (loadedLibs.count(path) > 0)
415 DynamicLibraryPtr lib(
new DynamicLibrary());
426 if (lib->isLibraryLoaded())
428 loadedLibs[path] = lib;
432 ARMARX_ERROR <<
"Could not load lib " + path +
": " + lib->getErrorMessage();
436 ArmarXManager::RegisterKnownObjectFactoriesWithIce(
437 this->getIceManager()->getCommunicator());
447 return loadLibFromAbsolutePath(absPath);
458 const std::string& name,
464 ARMARX_ERROR <<
"Could not find package '" <<
package << "'";
470 std::filesystem::path fullPath = libDirPath;
472 if (!std::filesystem::exists(fullPath))
474 fullPath = libDirPath;
476 if (!std::filesystem::exists(fullPath))
481 if (loadLibFromAbsolutePath(fullPath.string()))
486 ARMARX_ERROR <<
"Could not find library " << name <<
" in package " << package;
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
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