Task.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package RobotComponents
19 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <atomic>
27#include <chrono>
28#include <mutex>
29
31#include <ArmarXCore/interface/core/RemoteObjectNode.h>
32
33#include <RobotComponents/interface/components/MotionPlanning/Tasks/PathCollection/Task.h>
34
35#include "../../util/Metrics.h"
37
38namespace armarx::pathcol
39{
40 class Task;
42
43 class Task :
44 public virtual MotionPlanningTask,
45 public virtual TaskBase,
47 {
48 public:
49 Task(const std::string& taskName = "PathCollection")
50 {
51 this->taskName = taskName;
52 }
53
54 ~Task() override = default;
55
56 PathWithCost
57 getPathWithCost(const Ice::Current& = Ice::emptyCurrent) const override
58 {
60 }
61
62 Path
63 getNthPath(Ice::Long n, const Ice::Current& = Ice::emptyCurrent) const override
64 {
66 }
67
68 Path
69 getPath(const Ice::Current& = Ice::emptyCurrent) const override
70 {
72 }
73
74 void
75 abortTask(const Ice::Current& = Ice::emptyCurrent) override
76 {
77 }
78
79 CSpaceBasePtr
80 getCSpace(const Ice::Current& = Ice::emptyCurrent) const override
81 {
82 return cspace;
83 }
84
85 /**
86 * @brief Runs the task.
87 * @param remoteNodes The list of \ref RemoteObjectNodeInterfacePrx used to distribute work to computers.
88 */
89 void run(const RemoteObjectNodePrxList&, const Ice::Current& = Ice::emptyCurrent) override;
90
91 Ice::Long
92 getMaximalPlanningTimeInSeconds(const Ice::Current& = Ice::emptyCurrent) const override
93 {
94 return maximalPlanningTimeInSeconds;
95 }
96
97 Ice::Long
98 getPathCount(const Ice::Current& = Ice::emptyCurrent) const override
99 {
100 return paths.size();
101 }
102
103 PathWithCost
104 getBestPath(const Ice::Current& = Ice::emptyCurrent) const override
105 {
106 return getNthPathWithCost(0);
107 }
108
109 PathWithCost
110 getNthPathWithCost(Ice::Long n, const Ice::Current& = Ice::emptyCurrent) const override
111 {
112 if (static_cast<std::size_t>(n) < paths.size())
113 {
114 return paths.at(n);
115 }
116 return {{}, std::numeric_limits<float>::infinity(), "Path_" + to_string(n)};
117 }
118
119 PathWithCostSeq
120 getAllPathsWithCost(const Ice::Current& = Ice::emptyCurrent) const override
121 {
122 return paths;
123 }
124
125 void
126 addPath(Path p)
127 {
128 float len = 0;
129 for (std::size_t i = 0; i + 1 < p.nodes.size(); ++i)
130 {
131 len += euclideanDistance(
132 p.nodes.at(i).begin(), p.nodes.at(i).end(), p.nodes.at(i + 1).begin());
133 }
134 addPath(PathWithCost{std::move(p.nodes), len, std::move(p.pathName)});
135 }
136
137 void
138 addPath(PathWithCost p)
139 {
140 paths.emplace_back(std::move(p));
141 }
142 };
143} // namespace armarx::pathcol
144
145namespace armarx
146{
151} // namespace armarx
Path getNthPath(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
PathWithCost getPathWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Path getPath(const Ice::Current &=Ice::emptyCurrent) const override
The RemoteHandle class wrapps a ClientSideRemoteHandleControlBlock and can be used just as a Ice prox...
PathWithCostSeq getAllPathsWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition Task.h:120
Ice::Long getPathCount(const Ice::Current &=Ice::emptyCurrent) const override
Definition Task.h:98
Task(const std::string &taskName="PathCollection")
Definition Task.h:49
void run(const RemoteObjectNodePrxList &, const Ice::Current &=Ice::emptyCurrent) override
Runs the task.
Definition Task.cpp:30
Path getPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition Task.h:69
void addPath(PathWithCost p)
Definition Task.h:138
PathWithCost getNthPathWithCost(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition Task.h:110
void abortTask(const Ice::Current &=Ice::emptyCurrent) override
Definition Task.h:75
Ice::Long getMaximalPlanningTimeInSeconds(const Ice::Current &=Ice::emptyCurrent) const override
Definition Task.h:92
PathWithCost getBestPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition Task.h:104
~Task() override=default
void addPath(Path p)
Definition Task.h:126
CSpaceBasePtr getCSpace(const Ice::Current &=Ice::emptyCurrent) const override
Definition Task.h:80
Path getNthPath(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition Task.h:63
PathWithCost getPathWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition Task.h:57
IceInternal::Handle< Task > TaskPtr
Definition Task.h:41
This file offers overloads of toIce() and fromIce() functions for STL container types.
float euclideanDistance(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
Returns the euclidean distance.
Definition Metrics.h:104
IceUtil::Handle< PathCollection > PathCollectionPtr
Definition Task.h:148
RemoteHandle< MotionPlanningMultiPathWithCostTaskControlInterfacePrx > PathCollectionHandle
Definition Task.h:149
pathcol::Task PathCollection
Definition Task.h:147
const std::string & to_string(const std::string &s)