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