Frankx  0.2.0
A High-Level Motion API for Franka
motion_impedance.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <optional>
5 
6 #include <Eigen/Core>
7 #include <Eigen/Geometry>
8 
9 #include <affx/affine.hpp>
11 
12 
13 namespace movex {
14 
17 
18  enum class Axis { X, Y, Z };
19 
20  enum class Type {
21  Cartesian,
22  Joint
23  };
24 
25  enum class TargetMotion {
27  Linear,
28  Spiral,
29  };
30 
33  double duration;
34  bool initialized {false};
35  bool finish_after {true};
36  double finish_wait_factor {1.2};
37  };
38 
40  Affine center; // In XY-plane
43  bool initialized {false};
44  };
45 
47 
49  double exponential_decay {0.005};
52 
53  std::map<Axis, double> force_constraints;
54 
55 public:
56  const double translational_stiffness {2000.0}; // in [10, 3000] N/m
57  const double rotational_stiffness {200.0}; // in [1, 300] Nm/rad
58  const double joint_stiffness {200.0}; // ?
59 
61  bool is_active {false};
62  bool should_finish {false};
63 
64  explicit ImpedanceMotion() { }
67 
68 
69  Affine getTarget() const {
70  return target;
71  }
72 
73  void setTarget(const Affine& new_target) {
74  if (is_active) {
75  target = new_target;
76  }
78  }
79 
80  void setLinearRelativeTargetMotion(const Affine& relative_target, double duration) {
81  linear_motion = {relative_target, duration};
83  }
84 
85  void setSpiralTargetMotion(const Affine& center, double revolutions_per_second, double radius_per_revolution) {
86  spiral_motion = {center, revolutions_per_second, radius_per_revolution};
88  }
89 
90  void addForceConstraint(Axis axis, double value) {
91  if (is_active) {
92  return;
93  }
94 
95  force_constraints[axis] = value;
96  }
97 
98  void addForceConstraint(std::optional<double> x = std::nullopt, std::optional<double> y = std::nullopt, std::optional<double> z = std::nullopt) {
99  if (is_active) {
100  return;
101  }
102 
103  if (x) {
104  force_constraints[Axis::X] = x.value();
105  }
106  if (y) {
107  force_constraints[Axis::Y] = y.value();
108  }
109  if (z) {
110  force_constraints[Axis::Z] = z.value();
111  }
112  }
113 
114  bool isActive() const {
115  return is_active;
116  }
117 
118  void finish() {
119  should_finish = true;
120  }
121 };
122 
123 } // namespace movex
movex::ImpedanceMotion::joint_stiffness
const double joint_stiffness
Definition: motion_impedance.hpp:58
movex::ImpedanceMotion::isActive
bool isActive() const
Definition: motion_impedance.hpp:114
movex::ImpedanceMotion::addForceConstraint
void addForceConstraint(Axis axis, double value)
Definition: motion_impedance.hpp:90
movex::ImpedanceMotion::TargetMotion::Spiral
@ Spiral
movex::ImpedanceMotion::target
Affine target
Definition: motion_impedance.hpp:60
movex::ImpedanceMotion::Type
Type
Definition: motion_impedance.hpp:20
movex::ImpedanceMotion::SpiralTargetMotion::center
Affine center
Definition: motion_impedance.hpp:40
movex::ImpedanceMotion::Axis
Axis
Definition: motion_impedance.hpp:18
movex::ImpedanceMotion::Affine
affx::Affine Affine
Definition: motion_impedance.hpp:16
movex::ImpedanceMotion::Type::Cartesian
@ Cartesian
movex::ImpedanceMotion::SpiralTargetMotion::initialized
bool initialized
Definition: motion_impedance.hpp:43
movex::ImpedanceMotion::addForceConstraint
void addForceConstraint(std::optional< double > x=std::nullopt, std::optional< double > y=std::nullopt, std::optional< double > z=std::nullopt)
Definition: motion_impedance.hpp:98
movex::ImpedanceMotion::TargetMotion::Linear
@ Linear
movex::ImpedanceMotion::LinearTargetMotion::finish_after
bool finish_after
Definition: motion_impedance.hpp:35
movex::ImpedanceMotion::spiral_motion
SpiralTargetMotion spiral_motion
Definition: motion_impedance.hpp:51
movex::ImpedanceMotion::LinearTargetMotion::finish_wait_factor
double finish_wait_factor
Definition: motion_impedance.hpp:36
movex::ImpedanceMotion::SpiralTargetMotion
Definition: motion_impedance.hpp:39
movex::ImpedanceMotion::LinearTargetMotion::initialized
bool initialized
Definition: motion_impedance.hpp:34
movex::ImpedanceMotion::SpiralTargetMotion::radius_per_revolution
double radius_per_revolution
Definition: motion_impedance.hpp:42
movex::ImpedanceMotion::TargetMotion::Exponential
@ Exponential
movex::ImpedanceMotion
Definition: motion_impedance.hpp:15
movex::ImpedanceMotion::exponential_decay
double exponential_decay
Definition: motion_impedance.hpp:49
movex::ImpedanceMotion::translational_stiffness
const double translational_stiffness
Definition: motion_impedance.hpp:56
movex::ImpedanceMotion::setTarget
void setTarget(const Affine &new_target)
Definition: motion_impedance.hpp:73
motion_data.hpp
movex::ImpedanceMotion::finish
void finish()
Definition: motion_impedance.hpp:118
movex::ImpedanceMotion::getTarget
Affine getTarget() const
Definition: motion_impedance.hpp:69
movex::ImpedanceMotion::type
Type type
Definition: motion_impedance.hpp:46
movex::ImpedanceMotion::Axis::Z
@ Z
movex::ImpedanceMotion::ImpedanceMotion
ImpedanceMotion(double translational_stiffness, double rotational_stiffness)
Definition: motion_impedance.hpp:66
movex::ImpedanceMotion::force_constraints
std::map< Axis, double > force_constraints
Definition: motion_impedance.hpp:53
movex::ImpedanceMotion::LinearTargetMotion::relative_target
Affine relative_target
Definition: motion_impedance.hpp:32
frankx::Affine
affx::Affine Affine
Definition: motion_generator.hpp:15
movex::ImpedanceMotion::setLinearRelativeTargetMotion
void setLinearRelativeTargetMotion(const Affine &relative_target, double duration)
Definition: motion_impedance.hpp:80
movex::ImpedanceMotion::SpiralTargetMotion::revolutions_per_second
double revolutions_per_second
Definition: motion_impedance.hpp:41
movex::ImpedanceMotion::Type::Joint
@ Joint
movex::ImpedanceMotion::LinearTargetMotion::duration
double duration
Definition: motion_impedance.hpp:33
movex::ImpedanceMotion::is_active
bool is_active
Definition: motion_impedance.hpp:61
movex::ImpedanceMotion::linear_motion
LinearTargetMotion linear_motion
Definition: motion_impedance.hpp:50
movex::ImpedanceMotion::target_motion
TargetMotion target_motion
Definition: motion_impedance.hpp:48
movex::ImpedanceMotion::Axis::X
@ X
movex
Definition: motion_impedance.hpp:13
movex::ImpedanceMotion::setSpiralTargetMotion
void setSpiralTargetMotion(const Affine &center, double revolutions_per_second, double radius_per_revolution)
Definition: motion_impedance.hpp:85
movex::ImpedanceMotion::LinearTargetMotion
Definition: motion_impedance.hpp:31
movex::ImpedanceMotion::TargetMotion
TargetMotion
Definition: motion_impedance.hpp:25
movex::ImpedanceMotion::should_finish
bool should_finish
Definition: motion_impedance.hpp:62
movex::ImpedanceMotion::Axis::Y
@ Y
movex::ImpedanceMotion::ImpedanceMotion
ImpedanceMotion(double joint_stiffness)
Definition: motion_impedance.hpp:65
movex::ImpedanceMotion::ImpedanceMotion
ImpedanceMotion()
Definition: motion_impedance.hpp:64
movex::ImpedanceMotion::rotational_stiffness
const double rotational_stiffness
Definition: motion_impedance.hpp:57