TaskspaceMixedImpedanceVelocityController.h
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Jianfeng Gao ( jianfeng dot gao at kit dot edu )
17  * @date 2024
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 #include <Eigen/Core>
25 
26 #include <VirtualRobot/VirtualRobot.h>
27 
28 #include <armarx/control/common/control_law/aron/TaskspaceMixedImpedanceVelocityControllerConfig.aron.generated.h>
31 #include <armarx/control/common/ft/aron/FTConfig.aron.generated.h>
32 
34 {
35 
37  {
38  public:
39  using FTConfig = common::ft::arondto::FTConfig;
40  using Config =
41  common::control_law::arondto::TaskspaceMixedImpedanceVelocityControllerConfig;
42  using ConfigDict =
43  common::control_law::arondto::TaskspaceMixedImpedanceVelocityControllerConfigDict;
44 
45  /// internal status of the controller, containing intermediate variables, mutable targets
46  struct RtStatus : public RobotStatus
47  {
48  /// targets
49  Eigen::VectorXf desiredJointTorques;
50  Eigen::VectorXf desiredJointVelocity;
51  Eigen::VectorXf nullspaceTorque;
52  Eigen::VectorXf nullspaceVelocity;
53 
54  /// force torque
57 
58  /// task space variables
61 
62  /// current status
63  // Eigen::VectorXf qpos;
64  // Eigen::VectorXf qvel;
65  Eigen::VectorXf qvelFiltered;
69 
70  /// intermediate results
73  Eigen::AngleAxisf oriDiffAngleAxis;
74 
75  /// others
76  Eigen::MatrixXf jacobi;
77  Eigen::MatrixXf jtpinv;
78  Eigen::MatrixXf jpinv;
79  bool rtSafe;
80  bool rtTargetSafe = true;
81 
82  size_t nDoFTorque;
83  size_t nDoFVelocity;
84 
85  void
86  reset(const unsigned int nDoF, const size_t numDoFTorque, const size_t numDoFVelocity);
88  };
89 
90  unsigned int numOfJoints; // for nonRT use case
91  size_t nDoFTorque;
92  size_t nDoFVelocity;
93 
94  private:
95  std::atomic_bool enablePreactivateInit{false};
96 
97  Eigen::MatrixXf I;
98 
99  VirtualRobot::DifferentialIKPtr ik;
100 
101  const float lambda = 2.0f;
102 
103  public:
104  VirtualRobot::RobotNodePtr tcp;
105  VirtualRobot::RobotNodePtr rtTCP;
107 
108  std::vector<size_t> jointIDTorqueMode;
109  std::vector<size_t> jointIDVelocityMode;
110 
111  bool isControlModeValid(const std::vector<std::string>& nameList,
112  const std::map<std::string, std::string>& jointControlModeMap);
113  // void updateFT(const FTConfig& c, RtStatus& rtStatus);
114  void initialize(const VirtualRobot::RobotNodeSetPtr& rns,
115  const VirtualRobot::RobotNodeSetPtr& rtRns,
116  const std::vector<size_t>& torqueControlledIndex,
117  const std::vector<size_t>& velocityControlledIndex);
118  void preactivateInit(const VirtualRobot::RobotNodeSetPtr& rns);
119 
120  void run(Config& c, RtStatus& robotStatus);
121  void firstRun();
122  };
123 } // namespace armarx::control::common::control_law
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::desiredPose
Eigen::Matrix4f desiredPose
Definition: TaskspaceMixedImpedanceVelocityController.h:68
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::rtSafe
bool rtSafe
Definition: TaskspaceMixedImpedanceVelocityController.h:79
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::jointIDTorqueMode
std::vector< size_t > jointIDTorqueMode
Definition: TaskspaceMixedImpedanceVelocityController.h:108
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::poseErrorImp
Eigen::Vector6f poseErrorImp
Definition: TaskspaceMixedImpedanceVelocityController.h:72
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::forceImpedance
Eigen::Vector6f forceImpedance
task space variables
Definition: TaskspaceMixedImpedanceVelocityController.h:59
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::jointIDVelocityMode
std::vector< size_t > jointIDVelocityMode
Definition: TaskspaceMixedImpedanceVelocityController.h:109
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::ftsensor
common::ft::FTSensor ftsensor
Definition: TaskspaceMixedImpedanceVelocityController.h:106
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::oriDiffAngleAxis
Eigen::AngleAxisf oriDiffAngleAxis
Definition: TaskspaceMixedImpedanceVelocityController.h:73
common.h
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::preactivateInit
void preactivateInit(const VirtualRobot::RobotNodeSetPtr &rns)
Definition: TaskspaceMixedImpedanceVelocityController.cpp:48
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::ConfigDict
common::control_law::arondto::TaskspaceMixedImpedanceVelocityControllerConfigDict ConfigDict
Definition: TaskspaceMixedImpedanceVelocityController.h:43
FTSensor.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::currentTwist
Eigen::Vector6f currentTwist
Definition: TaskspaceMixedImpedanceVelocityController.h:67
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::tcp
VirtualRobot::RobotNodePtr tcp
Definition: TaskspaceMixedImpedanceVelocityController.h:104
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::nDoFTorque
size_t nDoFTorque
Definition: TaskspaceMixedImpedanceVelocityController.h:91
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::nullspaceVelocity
Eigen::VectorXf nullspaceVelocity
Definition: TaskspaceMixedImpedanceVelocityController.h:52
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::poseDiffMatImp
Eigen::Matrix3f poseDiffMatImp
intermediate results
Definition: TaskspaceMixedImpedanceVelocityController.h:71
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::nDoFVelocity
size_t nDoFVelocity
Definition: TaskspaceMixedImpedanceVelocityController.h:83
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::safeFTGuardOffset
Eigen::Vector6f safeFTGuardOffset
Definition: TaskspaceMixedImpedanceVelocityController.h:56
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::currentPose
Eigen::Matrix4f currentPose
Definition: TaskspaceMixedImpedanceVelocityController.h:66
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController
Definition: TaskspaceMixedImpedanceVelocityController.h:36
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::firstRun
void firstRun()
Definition: TaskspaceMixedImpedanceVelocityController.cpp:54
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::rtTargetSafe
bool rtTargetSafe
Definition: TaskspaceMixedImpedanceVelocityController.h:80
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::isControlModeValid
bool isControlModeValid(const std::vector< std::string > &nameList, const std::map< std::string, std::string > &jointControlModeMap)
Definition: TaskspaceMixedImpedanceVelocityController.cpp:60
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::rtPreActivate
void rtPreActivate(const Eigen::Matrix4f &currentPose)
Definition: TaskspaceMixedImpedanceVelocityController.cpp:296
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::Config
common::control_law::arondto::TaskspaceMixedImpedanceVelocityControllerConfig Config
Definition: TaskspaceMixedImpedanceVelocityController.h:41
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::desiredJointVelocity
Eigen::VectorXf desiredJointVelocity
Definition: TaskspaceMixedImpedanceVelocityController.h:50
armarx::control::common::control_law::RobotStatus
Definition: common.h:32
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus
internal status of the controller, containing intermediate variables, mutable targets
Definition: TaskspaceMixedImpedanceVelocityController.h:46
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::jpinv
Eigen::MatrixXf jpinv
Definition: TaskspaceMixedImpedanceVelocityController.h:78
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::reset
void reset(const unsigned int nDoF, const size_t numDoFTorque, const size_t numDoFVelocity)
Definition: TaskspaceMixedImpedanceVelocityController.cpp:243
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::desiredJointTorques
Eigen::VectorXf desiredJointTorques
targets
Definition: TaskspaceMixedImpedanceVelocityController.h:49
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::nDoFVelocity
size_t nDoFVelocity
Definition: TaskspaceMixedImpedanceVelocityController.h:92
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::run
void run(Config &c, RtStatus &robotStatus)
Definition: TaskspaceMixedImpedanceVelocityController.cpp:112
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::initialize
void initialize(const VirtualRobot::RobotNodeSetPtr &rns, const VirtualRobot::RobotNodeSetPtr &rtRns, const std::vector< size_t > &torqueControlledIndex, const std::vector< size_t > &velocityControlledIndex)
Definition: TaskspaceMixedImpedanceVelocityController.cpp:23
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::jtpinv
Eigen::MatrixXf jtpinv
Definition: TaskspaceMixedImpedanceVelocityController.h:77
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::rtTCP
VirtualRobot::RobotNodePtr rtTCP
Definition: TaskspaceMixedImpedanceVelocityController.h:105
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::FTConfig
common::ft::arondto::FTConfig FTConfig
Definition: TaskspaceMixedImpedanceVelocityController.h:39
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::nullspaceTorque
Eigen::VectorXf nullspaceTorque
Definition: TaskspaceMixedImpedanceVelocityController.h:51
Eigen::Matrix< float, 6, 1 >
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::jacobi
Eigen::MatrixXf jacobi
others
Definition: TaskspaceMixedImpedanceVelocityController.h:76
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::qvelFiltered
Eigen::VectorXf qvelFiltered
current status
Definition: TaskspaceMixedImpedanceVelocityController.h:65
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::cartesianVelTarget
Eigen::Vector6f cartesianVelTarget
Definition: TaskspaceMixedImpedanceVelocityController.h:60
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::nDoFTorque
size_t nDoFTorque
Definition: TaskspaceMixedImpedanceVelocityController.h:82
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::numOfJoints
unsigned int numOfJoints
Definition: TaskspaceMixedImpedanceVelocityController.h:90
armarx::control::common::ft::FTSensor
Definition: FTSensor.h:51
armarx::control::common::control_law::TaskspaceMixedImpedanceVelocityController::RtStatus::currentForceTorque
Eigen::Vector6f currentForceTorque
force torque
Definition: TaskspaceMixedImpedanceVelocityController.h:55