Frankx  0.2.0
A High-Level Motion API for Franka
measure.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 
6 
7 
8 namespace movex {
9 
10 class Condition {
11  using RobotState_ = RobotState<7>;
12 public:
13  using CallbackType = std::function<bool(const RobotState_&, double)>;
14 
15  explicit Condition(CallbackType callback): callback(callback) { }
16 
18  callback = [this, rhs](const RobotState_& robot_state, double time) {
19  return callback(robot_state, time) && rhs.callback(robot_state, time);
20  };
21  return *this;
22  }
23 
25  callback = [this, rhs](const RobotState_& robot_state, double time) {
26  return callback(robot_state, time) || rhs.callback(robot_state, time);
27  };
28  return *this;
29  }
30 
32  bool operator()(const RobotState_& robot_state, double time) {
33  return callback(robot_state, time);
34  }
35 
36 private:
37  CallbackType callback;
38 };
39 
40 
41 class Measure {
42  using RobotState_ = RobotState<7>;
43  using MeasureCallback = std::function<double(const RobotState_&, double)>;
44 
45  MeasureCallback callback;
46  explicit Measure(MeasureCallback callback): callback(callback) { }
47 
48 public:
49  static Measure ForceX() {
50  return Measure([](const RobotState_& robot_state, double time) {
51  return robot_state.O_F_ext_hat_K[0];
52  });
53  }
54 
55  static Measure ForceY() {
56  return Measure([](const RobotState_& robot_state, double time) {
57  return robot_state.O_F_ext_hat_K[1];
58  });
59  }
60 
61  static Measure ForceZ() {
62  return Measure([](const RobotState_& robot_state, double time) {
63  return robot_state.O_F_ext_hat_K[2];
64  });
65  }
66 
67  static Measure ForceXYNorm() {
68  return Measure([](const RobotState_& robot_state, double time) {
69  return std::pow(robot_state.O_F_ext_hat_K[0], 2) + std::pow(robot_state.O_F_ext_hat_K[1], 2);
70  });
71  }
72 
73  static Measure ForceXYZNorm() {
74  return Measure([](const RobotState_& robot_state, double time) {
75  return std::pow(robot_state.O_F_ext_hat_K[0], 2) + std::pow(robot_state.O_F_ext_hat_K[1], 2) + std::pow(robot_state.O_F_ext_hat_K[2], 2);
76  });
77  }
78 
79  static Measure Time() {
80  return Measure([](const RobotState_& robot_state, double time) {
81  return time;
82  });
83  }
84 
85  Condition operator==(double threshold) {
86  return Condition([*this, threshold](const RobotState_& robot_state, double time) {
87  return callback(robot_state, time) == threshold;
88  });
89  }
90 
91  Condition operator!=(double threshold) {
92  return Condition([*this, threshold](const RobotState_& robot_state, double time) {
93  return callback(robot_state, time) != threshold;
94  });
95  }
96 
97  Condition operator<(double threshold) {
98  return Condition([*this, threshold](const RobotState_& robot_state, double time) {
99  return callback(robot_state, time) < threshold;
100  });
101  }
102 
103  Condition operator<=(double threshold) {
104  return Condition([*this, threshold](const RobotState_& robot_state, double time) {
105  return callback(robot_state, time) <= threshold;
106  });
107  }
108 
109  Condition operator>(double threshold) {
110  return Condition([*this, threshold](const RobotState_& robot_state, double time) {
111  return callback(robot_state, time) > threshold;
112  });
113  }
114 
115  Condition operator>=(double threshold) {
116  return Condition([*this, threshold](const RobotState_& robot_state, double time) {
117  return callback(robot_state, time) >= threshold;
118  });
119  }
120 };
121 
122 } // namespace movex
movex::Condition::operator&&
Condition & operator&&(const Condition &rhs)
Definition: measure.hpp:17
robot_state.hpp
movex::Measure::ForceXYZNorm
static Measure ForceXYZNorm()
Definition: measure.hpp:73
movex::Measure::ForceZ
static Measure ForceZ()
Definition: measure.hpp:61
movex::Condition::CallbackType
std::function< bool(const RobotState_ &, double)> CallbackType
Definition: measure.hpp:13
movex::Condition
Definition: measure.hpp:10
movex::Condition::operator||
Condition & operator||(const Condition &rhs)
Definition: measure.hpp:24
movex::Measure::ForceXYNorm
static Measure ForceXYNorm()
Definition: measure.hpp:67
movex::Measure
Definition: measure.hpp:41
movex::Measure::operator>=
Condition operator>=(double threshold)
Definition: measure.hpp:115
movex::Measure::operator!=
Condition operator!=(double threshold)
Definition: measure.hpp:91
movex::Measure::operator==
Condition operator==(double threshold)
Definition: measure.hpp:85
movex::Measure::operator<=
Condition operator<=(double threshold)
Definition: measure.hpp:103
movex::Condition::operator()
bool operator()(const RobotState_ &robot_state, double time)
Check if the condition is fulfilled.
Definition: measure.hpp:32
movex::RobotState
The overall state of the robot.
Definition: robot_state.hpp:8
movex::Measure::ForceY
static Measure ForceY()
Definition: measure.hpp:55
movex::RobotState::O_F_ext_hat_K
std::array< double, 6 > O_F_ext_hat_K
Definition: robot_state.hpp:21
movex::Measure::ForceX
static Measure ForceX()
Definition: measure.hpp:49
movex::Measure::operator<
Condition operator<(double threshold)
Definition: measure.hpp:97
movex::Condition::Condition
Condition(CallbackType callback)
Definition: measure.hpp:15
movex
Definition: motion_impedance.hpp:13
movex::Measure::Time
static Measure Time()
Definition: measure.hpp:79
movex::Measure::operator>
Condition operator>(double threshold)
Definition: measure.hpp:109