Go to the documentation of this file.
26 #include <Ice/ObjectAdapter.h>
28 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
34 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
47 const std::string remNames = getProperty<std::string>(
"RemoteObjectNodes").getValue();
79 remoteObjectNodes.emplace_back(getProxy<armarx::RemoteObjectNodeInterfacePrx>(name));
94 ARMARX_WARNING_S <<
"Starting motion planning server without any remote object nodes! (some algorithms may still work)";
97 auto wm = getProxy<memoryx::WorkingMemoryInterfacePrx>(
"WorkingMemory",
false,
"",
false);
98 auto cs = getProxy<memoryx::CommonStorageInterfacePrx>(
"CommonStorage",
false,
"",
false);
99 auto rsc = getProxy<RobotStateComponentInterfacePrx>(
"RobotStateComponent",
false,
"",
false);
112 std::lock_guard<std::recursive_mutex> lock {
queueMutex};
117 tasks.at(taskId).task->abortTask();
121 for (
auto& task :
tasks)
123 task.second.rh->forceDeletion();
155 std::unique_lock<std::recursive_mutex> lock {
queueMutex};
169 handle =
tasks.at(taskId);
175 #define task_info "TASK FAILED!"\
176 << "\n\tname: " << handle.task->getTaskName()\
177 << "\n\tID: " << taskId\
178 << "\n\tice id = " << handle.task->ice_id()\
179 << "\n\tstatus " << TaskStatus::toString(handle.task->getTaskStatus())
186 auto start = IceUtil::Time::now();
191 t->addTaskStatusCallback([tp, start,
this](TaskStatus::Status
s)
193 if (
s == TaskStatus::eRefining)
195 auto duration = IceUtil::Time::now() - start;
196 tp->planningTime = duration.toMicroSeconds();
200 auto duration = IceUtil::Time::now() - start;
201 if (tp->planningTime > 0)
203 tp->refiningTime = duration.toMicroSeconds() - tp->planningTime;
207 tp->planningTime = duration.toMicroSeconds();
209 ARMARX_VERBOSE << tp->getTaskName() <<
": Planning time: " << tp->planningTime * 0.001f <<
" ms, " << tp->refiningTime * 0.001f <<
" ms";
215 t = MotionPlanningTaskPtr::dynamicCast(tmp->previousStep);
222 handle.
task->run(ronCache);
224 catch (Ice::Exception& e)
227 <<
"\n\tWHAT:\n" << e.what()
228 <<
"\n\tSTACK:\n" << e.ice_stackTrace();
229 handle.
task->setTaskStatus(TaskStatus::eException);
231 catch (std::exception& e)
234 <<
"\n\tWHAT:\n" << e.what();
235 handle.
task->setTaskStatus(TaskStatus::eException);
240 <<
"\n\tsomething not derived from std::exception was thrown";
241 handle.
task->setTaskStatus(TaskStatus::eException);
248 std::lock_guard<std::recursive_mutex> lock {
queueMutex};
258 std::lock_guard<std::recursive_mutex> lock {
queueMutex};
259 auto it =
tasks.find(
id);
261 if (it ==
tasks.end())
268 it->second.task->abortTask();
282 throw armarx::ServerShuttingDown {
"MotionPlanningServerComponent"};
294 planningTask->registerAtIceAdapter(adapter, ident);
300 MotionPlanningTaskControlInterfacePrx::uncheckedCast(planningTask->getProxy()),
301 [
id,
this, adapter, ident]
303 adapter->remove(ident);
310 std::lock_guard<std::recursive_mutex> lock {
queueMutex};
314 remoteHandleHandles.directHandle,
318 planningTask->postEnqueueing();
323 return remoteHandleHandles.clientSideRemoteHandleControlBlock;
328 std::lock_guard<std::recursive_mutex> lock {
queueMutex};
334 std::lock_guard<std::recursive_mutex> lock {
queueMutex};
340 std::lock_guard<std::recursive_mutex> lock {
queueMutex};
342 result.reserve(
tasks.size());
344 tasks.begin(),
tasks.end(), std::back_inserter(result),
345 [](
const decltype(
tasks)::value_type &
v)
352 rhs.
rh->getManagedObjectProxy()->ice_getIdentity(),
353 rhs.
task->getTaskStatus(),
355 rhs.
task->getTaskName()
363 ClientSideRemoteHandleControlBlockBasePtr remoteHandle;
366 remoteHandle =
currentTask.
rh->getClientSideRemoteHandleControlBlock();
373 CSpaceAndPaths result;
374 std::lock_guard<std::recursive_mutex> lock {
queueMutex};
375 auto it =
tasks.find(
id);
376 if (it !=
tasks.end())
378 auto task = MotionPlanningTaskBasePtr::dynamicCast(it->second.task);
380 result.cspace = task ? task->getCSpace()->clone() :
nullptr;
381 auto multPathTask = MotionPlanningMultiPathTaskControlInterfacePtr::dynamicCast(task);
384 result.paths = multPathTask->getAllPaths();
388 result.paths.emplace_back(it->second.task->getPath());
399 bool MotionPlanningServer::loadLibFromAbsolutePath(
const std::string& path)
416 if (lib->isLibraryLoaded())
422 ARMARX_ERROR <<
"Could not load lib " + path +
": " + lib->getErrorMessage();
435 return loadLibFromAbsolutePath(absPath);
449 ARMARX_ERROR <<
"Could not find package '" <<
package << "'";
455 std::filesystem::path fullPath = libDirPath;
457 if (!std::filesystem::exists(fullPath))
459 fullPath = libDirPath;
461 if (!std::filesystem::exists(fullPath))
466 if (loadLibFromAbsolutePath(fullPath.string()))
471 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
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.
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...
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)