TVM  0.9.4
defs.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <limits>
6 #include <memory>
7 
8 #include <Eigen/Core>
9 
10 namespace tvm
11 {
12 // forward declarations
13 namespace constraint
14 {
15 namespace abstract
16 {
17 class Constraint;
18 class LinearConstraint;
19 } // namespace abstract
20 } // namespace constraint
21 namespace function
22 {
23 namespace abstract
24 {
25 class Function;
26 class LinearFunction;
27 } // namespace abstract
28 } // namespace function
29 namespace requirements
30 {
33 } // namespace requirements
34 namespace task_dynamics
35 {
36 namespace abstract
37 {
38 class TaskDynamicsImpl;
39 }
40 } // namespace task_dynamics
41 class Clock;
42 class Range;
43 class Robot;
44 class Variable;
45 class VariableVector;
46 
47 // definitions
48 using MatrixConstRef = Eigen::Ref<const Eigen::MatrixXd>;
49 using MatrixRef = Eigen::Ref<Eigen::MatrixXd>;
50 using VectorConstRef = Eigen::Ref<const Eigen::VectorXd>;
51 using VectorRef = Eigen::Ref<Eigen::VectorXd>;
52 
53 using MatrixPtr = std::shared_ptr<Eigen::MatrixXd>;
54 using VectorPtr = std::shared_ptr<Eigen::VectorXd>;
55 
56 using ConstraintPtr = std::shared_ptr<constraint::abstract::Constraint>;
57 using FunctionPtr = std::shared_ptr<function::abstract::Function>;
58 using LinearFunctionPtr = std::shared_ptr<function::abstract::LinearFunction>;
59 using LinearConstraintPtr = std::shared_ptr<constraint::abstract::LinearConstraint>;
60 using ClockPtr = std::shared_ptr<Clock>;
61 using RangePtr = std::shared_ptr<Range>;
62 using RobotPtr = std::shared_ptr<Robot>;
63 using SolvingRequirementsPtr = std::shared_ptr<requirements::SolvingRequirementsWithCallbacks>;
64 using TaskDynamicsPtr = std::shared_ptr<task_dynamics::abstract::TaskDynamicsImpl>;
65 using VariablePtr = std::shared_ptr<Variable>;
66 
67 // constants
68 namespace constant
69 {
70 namespace internal
71 {
75 template<typename T>
76 constexpr T pow(T base, unsigned int exp, T result = 1)
77 { return exp <= 1 ? (exp == 0 ? 1 : result * base) : pow(base * base, exp / 2, (exp % 2) ? result * base : result); }
78 
79 /* Constexpr version of the square root of x
80  * curr is the initial guess for the square root
81  * Adapted from https://gist.github.com/alexshtf/eb5128b3e3e143187794
82  */
83 constexpr double sqrtNewtonRaphson(double x, double curr, double prev = 0)
84 { return curr == prev ? curr : sqrtNewtonRaphson(x, 0.5 * (curr + x / curr), curr); }
85 
89 static constexpr double sqrtGuess = pow(2., std::numeric_limits<double>::max_exponent / 2);
90 static constexpr double sqrtOfMax = sqrtNewtonRaphson(std::numeric_limits<double>::max(), sqrtGuess, 0);
91 } // namespace internal
92 
94 static constexpr double big_number = internal::sqrtOfMax / 2;
95 // assert that the big_number value is correct (no std::abs here because it is not constexpr)
96 static_assert(-(big_number * big_number - std::numeric_limits<double>::max() / 4)
97  < (2 * std::numeric_limits<double>::epsilon()) * std::numeric_limits<double>::max()
98  && (big_number * big_number - std::numeric_limits<double>::max() / 4)
99  < (2 * std::numeric_limits<double>::epsilon()) * std::numeric_limits<double>::max(),
100  "big_number was not computed at compile time or its value was not correct");
101 
103 constexpr double pi = 3.141592653589793238462643383279502884e+00;
104 
108 constexpr int fullRank = -1;
109 
111 static const Eigen::Vector3d gravity{0, 0, 9.81};
112 } // namespace constant
113 
114 } // namespace tvm
Definition: Clock.h:27
Definition: Range.h:19
Definition: Robot.h:49
Definition: VariableVector.h:41
Definition: Variable.h:49
Definition: Function.h:45
Definition: LinearFunction.h:62
Definition: SolvingRequirements.h:108
Definition: SolvingRequirements.h:103
Definition: TaskDynamicsImpl.h:33
constexpr T pow(T base, unsigned int exp, T result=1)
Definition: defs.h:76
constexpr double sqrtNewtonRaphson(double x, double curr, double prev=0)
Definition: defs.h:83
constexpr int fullRank
Definition: defs.h:108
constexpr double pi
Definition: defs.h:103
Definition: Clock.h:12
std::shared_ptr< Robot > RobotPtr
Definition: defs.h:62
std::shared_ptr< Variable > VariablePtr
Definition: defs.h:65
std::shared_ptr< function::abstract::LinearFunction > LinearFunctionPtr
Definition: defs.h:58
std::shared_ptr< Clock > ClockPtr
Definition: defs.h:60
std::shared_ptr< task_dynamics::abstract::TaskDynamicsImpl > TaskDynamicsPtr
Definition: defs.h:64
std::shared_ptr< function::abstract::Function > FunctionPtr
Definition: defs.h:57
Eigen::Ref< Eigen::VectorXd > VectorRef
Definition: defs.h:51
std::shared_ptr< constraint::abstract::Constraint > ConstraintPtr
Definition: defs.h:56
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
Definition: defs.h:50
std::shared_ptr< Eigen::VectorXd > VectorPtr
Definition: defs.h:54
std::shared_ptr< constraint::abstract::LinearConstraint > LinearConstraintPtr
Definition: defs.h:59
std::shared_ptr< Range > RangePtr
Definition: defs.h:61
std::shared_ptr< Eigen::MatrixXd > MatrixPtr
Definition: defs.h:53
Eigen::Ref< Eigen::MatrixXd > MatrixRef
Definition: defs.h:49
Eigen::Ref< const Eigen::MatrixXd > MatrixConstRef
Definition: defs.h:48
std::shared_ptr< requirements::SolvingRequirementsWithCallbacks > SolvingRequirementsPtr
Definition: defs.h:63