joint_wall.h
Go to the documentation of this file.
1 // Copyright (c) 2022 Franka Emika GmbH
2 #pragma once
3 
4 #include <array>
5 #include <memory>
6 
7 // clang-format off
17 // clang-format on
18 
20 
22 class JointWall {
23  public:
27  JointWall() = delete;
28 
39  JointWall(double soft_upper_joint_position_limit,
40  double soft_lower_joint_position_limit,
41  double PD_zone_width,
42  double D_zone_width,
43  double PD_zone_stiffness,
44  double PD_zone_damping,
45  double D_zone_damping);
46 
54  double computeTorque(double q, double dq);
55 
62  void reset();
63 
64  private:
68  enum class MotionInWall {
74  };
75 
76  // Joint wall parameters
79  double PD_zone_width_{0};
80  double D_zone_width_{0};
81  double PD_zone_stiffness_{0};
82  double PD_zone_damping_{0};
83  double D_zone_damping_{0};
84 
85  bool initialized_{false}; // Internal states q, dq will be reset to the current states in
86  // computeTorque if initialized_ = false;
87 
88  // Indicates whether the joint wall is still moving, which occurs after initializing the state
89  // inside joint wall.
90  bool moving_wall_{false};
91 
92  double zone_width_scale_{1};
93 
101  static bool inRange(double low, double high, double x);
102 
108  static double positiveCheck(double value);
109 
115  void init(double q, double dq);
116 
122  void adjustMovingWall(double q, double dq);
123 
129  MotionInWall getMotionInWall(double q, double dq) const;
130 };
131 
136 template <size_t num_dof>
138  public:
151  JointWallContainer(const std::array<double, num_dof>& soft_upper_joint_position_limits,
152  const std::array<double, num_dof>& soft_lower_joint_position_limits,
153  const std::array<double, num_dof>& PD_zone_widths,
154  const std::array<double, num_dof>& D_zone_widths,
155  const std::array<double, num_dof>& PD_zone_stiffnesses,
156  const std::array<double, num_dof>& PD_zone_dampings,
157  const std::array<double, num_dof>& D_zone_dampings) {
158  for (size_t i = 0; i < num_dof; i++) {
159  joint_walls_.at(i) = std::make_unique<JointWall>(
160  soft_upper_joint_position_limits[i], soft_lower_joint_position_limits[i],
161  PD_zone_widths[i], D_zone_widths[i], PD_zone_stiffnesses[i], PD_zone_dampings[i],
162  D_zone_dampings[i]);
163  }
164  }
165 
166  JointWallContainer() = delete;
167 
174  std::array<double, num_dof> computeTorque(const std::array<double, num_dof>& q,
175  const std::array<double, num_dof>& dq) {
176  std::array<double, num_dof> torque;
177  for (size_t i = 0; i < num_dof; i++) {
178  torque[i] = joint_walls_[i]->computeTorque(q[i], dq[i]);
179  };
180  return torque;
181  }
182 
189  void reset() {
190  for (auto& jw : joint_walls_) {
191  jw->reset();
192  }
193  }
194 
195  private:
196  std::array<std::unique_ptr<JointWall>, num_dof> joint_walls_;
197 };
198 
199 } // namespace franka_example_controllers
MotionInWall getMotionInWall(double q, double dq) const
Checks the motion type in joint wall.
Definition: joint_wall.cpp:135
std::array< std::unique_ptr< JointWall >, num_dof > joint_walls_
Definition: joint_wall.h:196
void reset()
Resets the initialized flags of all walls to false.
Definition: joint_wall.h:189
void reset()
Resets the initialized flag to false.
Definition: joint_wall.cpp:62
std::array< double, num_dof > computeTorque(const std::array< double, num_dof > &q, const std::array< double, num_dof > &dq)
Computes the torques generated by virtual walls.
Definition: joint_wall.h:174
static bool inRange(double low, double high, double x)
Checks if x is in range [low, high].
Definition: joint_wall.cpp:66
JointWallContainer(const std::array< double, num_dof > &soft_upper_joint_position_limits, const std::array< double, num_dof > &soft_lower_joint_position_limits, const std::array< double, num_dof > &PD_zone_widths, const std::array< double, num_dof > &D_zone_widths, const std::array< double, num_dof > &PD_zone_stiffnesses, const std::array< double, num_dof > &PD_zone_dampings, const std::array< double, num_dof > &D_zone_dampings)
Creates a new virtual joint position wall instance.
Definition: joint_wall.h:151
void adjustMovingWall(double q, double dq)
Moves the wall with given state if the state is initialized inside the wall.
Definition: joint_wall.cpp:102
A class that offers an implementation of a virtual wall for a single joint.
Definition: joint_wall.h:22
double computeTorque(double q, double dq)
Computes the torque with given q and dq.
Definition: joint_wall.cpp:33
MotionInWall
Indicates the status of moving wall, which occurs after initializing the state inside a wall...
Definition: joint_wall.h:68
static double positiveCheck(double value)
Check if the input is positive number, if not print error and return its abs.
Definition: joint_wall.cpp:126
void init(double q, double dq)
Initializes the joint wall computation with initial states.
Definition: joint_wall.cpp:70
JointWall()=delete
Creates a JointWall instance with default params.
A class that organizes multiple virtual joint walls.
Definition: joint_wall.h:137


franka_example_controllers
Author(s): Franka Emika GmbH
autogenerated on Mon Sep 19 2022 03:06:01