ZeroTorqueOrVelocityController.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 <VirtualRobot/VirtualRobot.h>
25 
26 #include <armarx/control/common/control_law/aron/ZeroTorqueOrVelocityControllerConfig.aron.generated.h>
29 #include <armarx/control/common/ft/aron/FTConfig.aron.generated.h>
30 
32 {
33 
35  {
36  public:
37  /// you can set the following values from outside of the rt controller via Ice interfaces
38  // struct Config
39  // {
40  // // torque controlled joint names
41  // std::vector<std::string> jointNameListTorque;
42  // std::vector<std::string> jointNameListVelocity;
43 
44  // // parameters for velocity controller
45  // Eigen::Vector6f kpCartesianVel;
46  // Eigen::Vector6f kdCartesianVel;
47 
48  // // std::map<std::string, std::string> jointControlModeMap;
49 
50  // float torqueLimit;
51  // float velocityLimit;
52  // float qvelFilter;
53  // float cartesianLinearVelLimit;
54  // float cartesianAngularVelLimit;
55  // // bool useZeroVelocityModeForWrist;
56 
57  // /// force torque sensor config
58  // common::ft::FTSensor::FTConfig ftConfig;
59  // };
60 
61  using Config = arondto::ZeroTorqueOrVelocityControllerConfig;
62  using ConfigDict = arondto::ZeroTorqueOrVelocityControllerConfigDict;
63 
64  // struct ConfigDict
65  // {
66  // std::map<std::string, Config> cfg;
67  // };
68 
69  /// internal status of the controller, containing intermediate variables, mutable targets
70  struct RtStatus : public RobotStatus
71  {
72  /// targets
73  Eigen::VectorXf desiredJointTorques;
74  Eigen::VectorXf desiredJointVelocity;
75 
76  /// force torque
78 
79  /// task space variables
81 
82  /// current status
83  Eigen::VectorXf qpos;
84  Eigen::VectorXf qvel;
85  Eigen::VectorXf qvelFiltered;
87 
88  /// others
89  Eigen::MatrixXf jacobi;
90  Eigen::MatrixXf jpinv;
91  bool rtSafe;
92 
93  size_t nDoFTorque;
94  size_t nDoFVelocity;
95  };
96 
97  unsigned int numOfJoints; // for nonRT use case
98  size_t nDoFTorque;
99  size_t nDoFVelocity;
100 
101  private:
102  // std::atomic_bool enablePreactivateInit{false};
103 
104  Eigen::MatrixXf I;
105 
106  VirtualRobot::DifferentialIKPtr ik;
107 
108  const float lambda = 2.0f;
109 
110  public:
111  VirtualRobot::RobotNodePtr tcp;
112  VirtualRobot::RobotNodePtr rtTCP;
114 
115  std::vector<size_t> jointIDTorqueMode;
116  std::vector<size_t> jointIDVelocityMode;
117 
118  // bool isControlModeValid(const std::vector<std::string>& nameList,
119  // const std::map<std::string, std::string>& jointControlModeMap);
120  // void updateFT(const common::ft::arondto::FTConfig& c, RtStatus& rtStatus);
121 
122  void initialize(const VirtualRobot::RobotNodeSetPtr& rns,
123  const VirtualRobot::RobotNodeSetPtr& rtRns,
124  const std::vector<size_t>& torqueControlledIndex,
125  const std::vector<size_t>& velocityControlledIndex);
126  void preactivateInit(const VirtualRobot::RobotNodeSetPtr& rns);
127 
128  void run(Config& c, RtStatus& robotStatus);
129  void firstRun();
130  };
131 } // namespace armarx::control::common::control_law
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::desiredJointTorques
Eigen::VectorXf desiredJointTorques
targets
Definition: ZeroTorqueOrVelocityController.h:73
armarx::control::common::control_law::ZeroTorqueOrVelocityController::jointIDTorqueMode
std::vector< size_t > jointIDTorqueMode
Definition: ZeroTorqueOrVelocityController.h:115
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::rtSafe
bool rtSafe
Definition: ZeroTorqueOrVelocityController.h:91
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::nDoFVelocity
size_t nDoFVelocity
Definition: ZeroTorqueOrVelocityController.h:94
armarx::control::common::control_law::ZeroTorqueOrVelocityController::ftsensor
common::ft::FTSensor ftsensor
Definition: ZeroTorqueOrVelocityController.h:113
common.h
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::cartesianVelTarget
Eigen::Vector6f cartesianVelTarget
task space variables
Definition: ZeroTorqueOrVelocityController.h:80
FTSensor.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::control::common::control_law::ZeroTorqueOrVelocityController::initialize
void initialize(const VirtualRobot::RobotNodeSetPtr &rns, const VirtualRobot::RobotNodeSetPtr &rtRns, const std::vector< size_t > &torqueControlledIndex, const std::vector< size_t > &velocityControlledIndex)
Definition: ZeroTorqueOrVelocityController.cpp:19
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::currentForceTorque
Eigen::Vector6f currentForceTorque
force torque
Definition: ZeroTorqueOrVelocityController.h:77
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::jacobi
Eigen::MatrixXf jacobi
others
Definition: ZeroTorqueOrVelocityController.h:89
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::qvel
Eigen::VectorXf qvel
Definition: ZeroTorqueOrVelocityController.h:84
armarx::control::common::control_law::ZeroTorqueOrVelocityController::jointIDVelocityMode
std::vector< size_t > jointIDVelocityMode
Definition: ZeroTorqueOrVelocityController.h:116
armarx::control::common::control_law::ZeroTorqueOrVelocityController::tcp
VirtualRobot::RobotNodePtr tcp
Definition: ZeroTorqueOrVelocityController.h:111
armarx::control::common::control_law::ZeroTorqueOrVelocityController::ConfigDict
arondto::ZeroTorqueOrVelocityControllerConfigDict ConfigDict
Definition: ZeroTorqueOrVelocityController.h:62
armarx::control::common::control_law::RobotStatus
Definition: common.h:32
armarx::control::common::control_law::ZeroTorqueOrVelocityController::run
void run(Config &c, RtStatus &robotStatus)
Definition: ZeroTorqueOrVelocityController.cpp:106
armarx::control::common::control_law::ZeroTorqueOrVelocityController::preactivateInit
void preactivateInit(const VirtualRobot::RobotNodeSetPtr &rns)
Definition: ZeroTorqueOrVelocityController.cpp:44
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::currentTwist
Eigen::Vector6f currentTwist
Definition: ZeroTorqueOrVelocityController.h:86
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
armarx::control::common::control_law::ZeroTorqueOrVelocityController::nDoFTorque
size_t nDoFTorque
Definition: ZeroTorqueOrVelocityController.h:98
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::qpos
Eigen::VectorXf qpos
current status
Definition: ZeroTorqueOrVelocityController.h:83
armarx::control::common::control_law::ZeroTorqueOrVelocityController::Config
arondto::ZeroTorqueOrVelocityControllerConfig Config
you can set the following values from outside of the rt controller via Ice interfaces
Definition: ZeroTorqueOrVelocityController.h:61
armarx::control::common::control_law::ZeroTorqueOrVelocityController::rtTCP
VirtualRobot::RobotNodePtr rtTCP
Definition: ZeroTorqueOrVelocityController.h:112
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::jpinv
Eigen::MatrixXf jpinv
Definition: ZeroTorqueOrVelocityController.h:90
Eigen::Matrix< float, 6, 1 >
armarx::control::common::control_law::ZeroTorqueOrVelocityController::firstRun
void firstRun()
Definition: ZeroTorqueOrVelocityController.cpp:49
armarx::control::common::control_law::ZeroTorqueOrVelocityController::numOfJoints
unsigned int numOfJoints
Definition: ZeroTorqueOrVelocityController.h:97
armarx::control::common::control_law::ZeroTorqueOrVelocityController
Definition: ZeroTorqueOrVelocityController.h:34
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::qvelFiltered
Eigen::VectorXf qvelFiltered
Definition: ZeroTorqueOrVelocityController.h:85
armarx::control::common::ft::FTSensor
Definition: FTSensor.h:51
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::nDoFTorque
size_t nDoFTorque
Definition: ZeroTorqueOrVelocityController.h:93
armarx::control::common::control_law::ZeroTorqueOrVelocityController::nDoFVelocity
size_t nDoFVelocity
Definition: ZeroTorqueOrVelocityController.h:99
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus
internal status of the controller, containing intermediate variables, mutable targets
Definition: ZeroTorqueOrVelocityController.h:70
armarx::control::common::control_law::ZeroTorqueOrVelocityController::RtStatus::desiredJointVelocity
Eigen::VectorXf desiredJointVelocity
Definition: ZeroTorqueOrVelocityController.h:74