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 #include <random>
30 
33 #include <ArmarXCore/interface/core/RemoteObjectNode.h>
34 
35 #include <RobotComponents/interface/components/MotionPlanning/Tasks/RandomShortcutPostprocessor/Task.h>
36 
37 #include "../../util/Metrics.h"
38 #include "../MotionPlanningTask.h"
39 
40 namespace armarx::rngshortcut
41 {
42  class Task;
44 
45  class Task :
46  public virtual PostprocessingMotionPlanningTask,
47  public virtual TaskBase,
49  {
50  public:
51  Task(MotionPlanningTaskBasePtr previousStep,
52  const std::string& taskName = "RandomShortcutPostprocessorTask",
53  Ice::Long maxTimeForPostprocessingInSeconds = 6000,
54  Ice::Float dcdStep = 0.01,
55  Ice::Long maxTries = 10000,
56  Ice::Float minShortcutImprovementRatio = 0.1,
57  Ice::Float minPathImprovementRatio = 0.01);
58 
59  PathWithCost
60  getPathWithCost(const Ice::Current& = Ice::emptyCurrent) const override
61  {
63  }
64 
65  Path
66  getNthPath(Ice::Long n, const Ice::Current& = Ice::emptyCurrent) const override
67  {
69  }
70 
71  Path
72  getPath(const Ice::Current& = Ice::emptyCurrent) const override
73  {
75  }
76 
77  ~Task() override = default;
78 
79  //PlanningControlInterface
80  /**
81  * @brief Aborts planning.
82  */
83  void abortTask(const Ice::Current& = Ice::emptyCurrent) override;
84 
85  //PlanningTaskBase
86  /**
87  * @brief Runs the task.
88  * @param remoteNodes The list of \ref RemoteObjectNodeInterfacePrx used to distribute work to computers.
89  */
90  void run(const RemoteObjectNodePrxList& nodes,
91  const Ice::Current& = Ice::emptyCurrent) override;
92 
93  Ice::Long
94  getMaximalPlanningTimeInSeconds(const Ice::Current& = Ice::emptyCurrent) const override
95  {
96  return previousStep->getMaximalPlanningTimeInSeconds();
97  }
98 
99  Ice::Long getPathCount(const Ice::Current& = Ice::emptyCurrent) const override;
100  PathWithCost getBestPath(const Ice::Current& = Ice::emptyCurrent) const override;
101  PathWithCost getNthPathWithCost(Ice::Long n,
102  const Ice::Current& = Ice::emptyCurrent) const override;
103  PathWithCostSeq getAllPathsWithCost(const Ice::Current& = Ice::emptyCurrent) const override;
104 
105  bool isPathCollisionFree(const VectorXf& from, const VectorXf& to);
106 
107  std::pair<float, float> calcOffsets(float length, std::mt19937& gen);
108 
109  protected:
110  /**
111  * @brief Ctor used by object factories.
112  */
113  Task() = default;
114 
115  mutable std::mutex mtx;
117  PathWithCostSeq paths;
118  std::atomic_bool taskIsAborted{false};
119 
120  private:
121  template <class Base, class Derived>
122  friend class ::armarx::GenericFactory;
123  };
124 } // namespace armarx::rngshortcut
125 
126 namespace armarx
127 {
132 } // namespace armarx
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::rngshortcut::Task::paths
PathWithCostSeq paths
Definition: Task.h:117
armarx::rngshortcut::Task::mtx
std::mutex mtx
Definition: Task.h:115
armarx::rngshortcut::Task::getPath
Path getPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:72
armarx::rngshortcut::Task::getMaximalPlanningTimeInSeconds
Ice::Long getMaximalPlanningTimeInSeconds(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:94
armarx::rngshortcut::Task::getPathCount
Ice::Long getPathCount(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:334
RemoteHandle.h
FactoryCollectionBase.h
armarx::rngshortcut::Task::calcOffsets
std::pair< float, float > calcOffsets(float length, std::mt19937 &gen)
Definition: Task.cpp:416
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::rngshortcut::Task::getPathWithCost
PathWithCost getPathWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:60
armarx::rngshortcut::Task::run
void run(const RemoteObjectNodePrxList &nodes, const Ice::Current &=Ice::emptyCurrent) override
Runs the task.
Definition: Task.cpp:101
armarx::rngshortcut::Task::getNthPathWithCost
PathWithCost getNthPathWithCost(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:347
armarx::MotionPlanningMultiPathWithCostTaskCI::getPathWithCost
PathWithCost getPathWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: MotionPlanningTaskControlInterface.h:118
armarx::rngshortcut::Task::getNthPath
Path getNthPath(Ice::Long n, const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.h:66
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::rngshortcut::Task::Task
Task()=default
Ctor used by object factories.
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::rngshortcut::Task::taskIsAborted
std::atomic_bool taskIsAborted
Definition: Task.h:118
armarx::rngshortcut::Task::postprocessedSolution
Path postprocessedSolution
Definition: Task.h:116
armarx::rngshortcut::Task::isPathCollisionFree
bool isPathCollisionFree(const VectorXf &from, const VectorXf &to)
Definition: Task.cpp:361
armarx::rngshortcut::Task::getAllPathsWithCost
PathWithCostSeq getAllPathsWithCost(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:354
armarx::PostprocessingMotionPlanningTask
Definition: MotionPlanningTask.h:244
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::RemoteHandle< MotionPlanningMultiPathWithCostTaskControlInterfacePrx >
armarx::rngshortcut::Task::getBestPath
PathWithCost getBestPath(const Ice::Current &=Ice::emptyCurrent) const override
Definition: Task.cpp:341
armarx::rngshortcut::Task
Definition: Task.h:45
armarx::armem::server::ltm::detail::mixin::Path
std::filesystem::path Path
Definition: DiskStorageMixin.h:17
armarx::rngshortcut::Task::~Task
~Task() override=default
armarx::rngshortcut
Definition: Task.cpp:36
armarx::rngshortcut::Task::abortTask
void abortTask(const Ice::Current &=Ice::emptyCurrent) override
Aborts planning.
Definition: Task.cpp:91
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::MotionPlanningMultiPathWithCostTaskCI
Definition: MotionPlanningTaskControlInterface.h:99