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 #include "../../util/HashingUtil.h"
30 
31 ARMARX_OVERLOAD_STD_HASH((armarx::addirrtstar::NodeId), (arg.workerId, arg.numberOfNode))
32 
33 namespace armarx::addirrtstar
34 {
35  static const std::string ADDIRRTSTAR_TREE_UPDATE_TOPIC_NAME = "ADDIRRTStarTreeUpdateTopic";
36 
37  /**
38  * @brief Returns the update's worker id.
39  * @param u The update.
40  * @return The update's worker id.
41  */
42  template<class T = std::size_t>
43  T getUpdatesWorkerId(const Update& u)
44  {
45  ARMARX_CHECK_EXPRESSION(u.workerId >= 0);
46  return static_cast<std::size_t>(u.workerId);
47  }
48 
49  /**
50  * @brief Returns the update's sub id's predecessor (number of update for its worker -2).
51  * @param u The update.
52  * @return The update's sub id's predecessor.
53  */
54  template<class T = std::size_t>
55  T getUpdatesPreviousUpdateSubId(const Update& u)
56  {
57  const auto workerId = getUpdatesWorkerId(u);
58  ARMARX_CHECK_EXPRESSION(workerId < u.dependetOnUpdateIds.size());
59  return static_cast<T>(u.dependetOnUpdateIds.at(workerId));
60  }
61 
62  /**
63  * @brief Returns the update's sub id (number of update for its worker -1).
64  * @param u The update.
65  * @return The update's sub id.
66  */
67  template<class T = std::size_t>
68  T getUpdatesSubId(const Update& u)
69  {
70  return getUpdatesPreviousUpdateSubId(u) + 1;
71  }
72 
73  /**
74  * @brief Returns whether the update update depends on dependency.
75  * @param update The update.
76  * @param dependency The dependency to check.
77  * @return Whether the update update depends on dependency.
78  */
79  inline bool updateDependsOn(const Update& update, const Update& dependency)
80  {
81  return update.dependetOnUpdateIds.at(getUpdatesWorkerId(dependency)) >= getUpdatesSubId<Ice::Long>(dependency);
82  }
83 
84  /**
85  * @brief Generates standard add parameters from a dcd stepsize.
86  * @param dcdStepsize The dcd stepsize.
87  * @return The add parameters.
88  */
89  inline AdaptiveDynamicDomainParameters generateADDParamsFromDCDStepsize(float dcdStepsize)
90  {
91  AdaptiveDynamicDomainParameters result;
92  result.alpha = 0.05f;
93  result.initialBorderRadius = 20 * dcdStepsize;
94  result.minimalRadius = 5 * dcdStepsize;
95  return result;
96  }
97 
98  /**
99  * @brief Returns a node id as string.
100  * @param id The node id.
101  * @return The node id as string.
102  */
103  std::string nodeId2String(const NodeId& id);
104 }
105 
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:29
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
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:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28