util.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 2015
21  * @copyright http://www.gnu.org/licenses/gpl.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
27 
28 #include <RobotComponents/interface/components/MotionPlanning/Tasks/AdaptiveDynamicDomainInformedRRTStar/DataStructures.h>
29 
30 #include "../../util/HashingUtil.h"
31 
32 ARMARX_OVERLOAD_STD_HASH((armarx::addirrtstar::NodeId), (arg.workerId, arg.numberOfNode))
33 
34 namespace armarx::addirrtstar
35 {
36  static const std::string ADDIRRTSTAR_TREE_UPDATE_TOPIC_NAME = "ADDIRRTStarTreeUpdateTopic";
37 
38  /**
39  * @brief Returns the update's worker id.
40  * @param u The update.
41  * @return The update's worker id.
42  */
43  template <class T = std::size_t>
44  T
45  getUpdatesWorkerId(const Update& u)
46  {
47  ARMARX_CHECK_EXPRESSION(u.workerId >= 0);
48  return static_cast<std::size_t>(u.workerId);
49  }
50 
51  /**
52  * @brief Returns the update's sub id's predecessor (number of update for its worker -2).
53  * @param u The update.
54  * @return The update's sub id's predecessor.
55  */
56  template <class T = std::size_t>
57  T
58  getUpdatesPreviousUpdateSubId(const Update& u)
59  {
60  const auto workerId = getUpdatesWorkerId(u);
61  ARMARX_CHECK_EXPRESSION(workerId < u.dependetOnUpdateIds.size());
62  return static_cast<T>(u.dependetOnUpdateIds.at(workerId));
63  }
64 
65  /**
66  * @brief Returns the update's sub id (number of update for its worker -1).
67  * @param u The update.
68  * @return The update's sub id.
69  */
70  template <class T = std::size_t>
71  T
72  getUpdatesSubId(const Update& u)
73  {
74  return getUpdatesPreviousUpdateSubId(u) + 1;
75  }
76 
77  /**
78  * @brief Returns whether the update update depends on dependency.
79  * @param update The update.
80  * @param dependency The dependency to check.
81  * @return Whether the update update depends on dependency.
82  */
83  inline bool
84  updateDependsOn(const Update& update, const Update& dependency)
85  {
86  return update.dependetOnUpdateIds.at(getUpdatesWorkerId(dependency)) >=
87  getUpdatesSubId<Ice::Long>(dependency);
88  }
89 
90  /**
91  * @brief Generates standard add parameters from a dcd stepsize.
92  * @param dcdStepsize The dcd stepsize.
93  * @return The add parameters.
94  */
95  inline AdaptiveDynamicDomainParameters
96  generateADDParamsFromDCDStepsize(float dcdStepsize)
97  {
98  AdaptiveDynamicDomainParameters result;
99  result.alpha = 0.05f;
100  result.initialBorderRadius = 20 * dcdStepsize;
101  result.minimalRadius = 5 * dcdStepsize;
102  return result;
103  }
104 
105  /**
106  * @brief Returns a node id as string.
107  * @param id The node id.
108  * @return The node id as string.
109  */
110  std::string nodeId2String(const NodeId& id);
111 } // namespace armarx::addirrtstar
ARMARX_OVERLOAD_STD_HASH
#define ARMARX_OVERLOAD_STD_HASH(Type, Members)
Overloads the std::hash template for Type.
Definition: HashingUtil.h:49
armarx::addirrtstar::nodeId2String
std::string nodeId2String(const NodeId &id)
Definition: util.cpp:30
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:68
ExpressionException.h
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27