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"
36 #include "../MotionPlanningTask.h"
37 
38 namespace 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
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 
145 namespace armarx
146 {
149  using PathCollectionHandle =
151 } // namespace armarx
armarx::pathcol::Task::getBestPath
PathWithCost getBestPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:104
armarx::pathcol::Task::addPath
void addPath(Path p)
Definition: Task.h:126
armarx::MotionPlanningTask
Definition: MotionPlanningTask.h:60
armarx::pathcol::Task::getPath
Path getPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:69
RemoteHandle.h
armarx::pathcol::Task::getPathCount
Ice::Long getPathCount(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:98
armarx::pathcol::Task::getPathWithCost
PathWithCost getPathWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:57
armarx::pathcol::Task
Definition: Task.h:43
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::pathcol::Task::getNthPathWithCost
PathWithCost getNthPathWithCost(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:110
armarx::MotionPlanningMultiPathWithCostTaskCI::getPathWithCost
PathWithCost getPathWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:118
armarx::pathcol::Task::Task
Task(const std::string &taskName="PathCollection")
Definition: Task.h:49
armarx::pathcol::Task::addPath
void addPath(PathWithCost p)
Definition: Task.h:138
armarx::pathcol::Task::~Task
~Task() override=default
armarx::pathcol::Task::run
void run(const RemoteObjectNodePrxList &, const Ice::Current &=Ice::emptyCurrent) override
Runs the task.
Definition: Task.cpp:30
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::MotionPlanningMultiPathWithCostTaskCI::getNthPath
Path getNthPath(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:124
armarx::MotionPlanningWithCostTaskCI::getPath
Path getPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:92
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
armarx::pathcol
Definition: Task.cpp:27
armarx::pathcol::Task::getNthPath
Path getNthPath(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:63
armarx::pathcol::Task::getCSpace
CSpaceBasePtr getCSpace(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:80
armarx::euclideanDistance
float euclideanDistance(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
Returns the euclidean distance.
Definition: Metrics.h:104
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::RemoteHandle< MotionPlanningMultiPathWithCostTaskControlInterfacePrx >
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::pathcol::Task::getAllPathsWithCost
PathWithCostSeq getAllPathsWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:120
armarx::pathcol::Task::getMaximalPlanningTimeInSeconds
Ice::Long getMaximalPlanningTimeInSeconds(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:92
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::MotionPlanningMultiPathWithCostTaskCI
Definition: MotionPlanningTaskControlInterface.h:99
armarx::pathcol::Task::abortTask
void abortTask(const Ice::Current &=Ice::emptyCurrent) override
Definition: Task.h:75