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 <mutex>
27 #include <chrono>
28 #include<atomic>
29 
31 #include <ArmarXCore/interface/core/RemoteObjectNode.h>
32 
33 #include <RobotComponents/interface/components/MotionPlanning/Tasks/PathCollection/Task.h>
34 
35 #include "../MotionPlanningTask.h"
36 #include "../../util/Metrics.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 
57  PathWithCost getPathWithCost(const Ice::Current& = Ice::emptyCurrent) const override
58  {
60  }
61  Path getNthPath(Ice::Long n, const Ice::Current& = Ice::emptyCurrent) const override
62  {
64  }
65  Path getPath(const Ice::Current& = Ice::emptyCurrent) const override
66  {
68  }
69 
70  void abortTask(const Ice::Current& = Ice::emptyCurrent) override
71  {
72  }
73 
74  CSpaceBasePtr getCSpace(const Ice::Current& = Ice::emptyCurrent) const override
75  {
76  return cspace;
77  }
78 
79  /**
80  * @brief Runs the task.
81  * @param remoteNodes The list of \ref RemoteObjectNodeInterfacePrx used to distribute work to computers.
82  */
83  void run(const RemoteObjectNodePrxList&, const Ice::Current& = Ice::emptyCurrent) override;
84 
85  Ice::Long getMaximalPlanningTimeInSeconds(const Ice::Current& = Ice::emptyCurrent) const override
86  {
87  return maximalPlanningTimeInSeconds;
88  }
89 
90  Ice::Long getPathCount(const Ice::Current& = Ice::emptyCurrent) const override
91  {
92  return paths.size();
93  }
94  PathWithCost getBestPath(const Ice::Current& = Ice::emptyCurrent) const override
95  {
96  return getNthPathWithCost(0);
97  }
98  PathWithCost getNthPathWithCost(Ice::Long n, const Ice::Current& = Ice::emptyCurrent) const override
99  {
100  if (static_cast<std::size_t>(n) < paths.size())
101  {
102  return paths.at(n);
103  }
104  return {{}, std::numeric_limits<float>::infinity(), "Path_" + to_string(n)};
105  }
106  PathWithCostSeq getAllPathsWithCost(const Ice::Current& = Ice::emptyCurrent) const override
107  {
108  return paths;
109  }
110 
111  void addPath(Path p)
112  {
113  float len = 0;
114  for (std::size_t i = 0; i + 1 < p.nodes.size(); ++i)
115  {
116  len += euclideanDistance(p.nodes.at(i).begin(), p.nodes.at(i).end(), p.nodes.at(i + 1).begin());
117  }
118  addPath(PathWithCost {std::move(p.nodes), len, std::move(p.pathName)});
119  }
120  void addPath(PathWithCost p)
121  {
122  paths.emplace_back(std::move(p));
123  }
124  };
125 }
126 namespace armarx
127 {
131 }
armarx::pathcol::Task::getBestPath
PathWithCost getBestPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:94
armarx::pathcol::Task::addPath
void addPath(Path p)
Definition: Task.h:111
armarx::MotionPlanningTask
Definition: MotionPlanningTask.h:56
armarx::pathcol::Task::getPath
Path getPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:65
RemoteHandle.h
armarx::pathcol::Task::getPathCount
Ice::Long getPathCount(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:90
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:98
armarx::MotionPlanningMultiPathWithCostTaskCI::getPathWithCost
PathWithCost getPathWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:106
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:120
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:29
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::MotionPlanningMultiPathWithCostTaskCI::getNthPath
Path getNthPath(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:110
armarx::MotionPlanningWithCostTaskCI::getPath
Path getPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:82
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
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:61
armarx::pathcol::Task::getCSpace
CSpaceBasePtr getCSpace(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:74
armarx::euclideanDistance
float euclideanDistance(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
Returns the euclidean distance.
Definition: Metrics.h:94
IceUtil::Handle
Definition: forward_declarations.h:29
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:106
armarx::pathcol::Task::getMaximalPlanningTimeInSeconds
Ice::Long getMaximalPlanningTimeInSeconds(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:85
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::MotionPlanningMultiPathWithCostTaskCI
Definition: MotionPlanningTaskControlInterface.h:89
armarx::pathcol::Task::abortTask
void abortTask(const Ice::Current &=Ice::emptyCurrent) override
Definition: Task.h:70