KeypointsImpedanceController.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 2022
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 
29 
31 
33 
35 {
37  {
38  public:
39  /// you can set the following values from outside of the rt controller via Ice interfaces
40  struct Config
41  {
42  std::string nodeSetName;
43 
46 
47  // Eigen::Vector6f kpAdmittance; /// might not be needed anymore
50 
51  Eigen::VectorXf kpNullspace;
52  Eigen::VectorXf kdNullspace;
53 
54  std::optional<Eigen::VectorXf> desiredNullspaceJointAngles;
55 
56  float torqueLimit;
57  float qvelFilter;
58 
59  /// keypoints related
60  int numPoints;
61  Eigen::VectorXf keypointKp;
62  Eigen::VectorXf keypointKd;
63  Eigen::VectorXf fixedTranslation;
64  float densityForceScaling = 1.0;
65  // Eigen::VectorXf currentKeypointPosition;
66  // Eigen::VectorXf desiredKeypointPosition;
67  // Eigen::VectorXf desiredKeypointVelocity;
68  // Eigen::VectorXf desiredDensityForce;
69  float keypointPositionFilter = 1.0f;
70  float keypointVelocityFilter = 1.0f;
71 
72  bool isRigid = false;
73  };
74 
75  /// internal status of the controller, containing intermediate variables, mutable targets
76  struct RtStatus
77  {
78  /// targets
79  Eigen::VectorXf desiredJointTorques;
80 
83 
84  /// task space variables
86  Eigen::VectorXf nullspaceTorque;
87  };
88 
89  struct NonRtStatus
90  {
91  /// joint space variable
92  Eigen::VectorXf qpos;
93  Eigen::VectorXf qvel;
94 
95  /// task space variables
98 
102 
103  /// others
104  Eigen::MatrixXf jacobi;
105  Eigen::MatrixXf jtpinv;
106 
107  /// keypoint status
109  Eigen::VectorXf filteredKeypointPosition;
110  Eigen::VectorXf previousKeypointPosition;
111 
112  Eigen::VectorXf currentKeypointPosition;
113  Eigen::VectorXf currentKeypointVelocity;
114 
115  Eigen::VectorXf desiredKeypointPosition;
116  Eigen::VectorXf desiredKeypointVelocity;
117  Eigen::VectorXf desiredDensityForce;
118  };
119 
120  private:
121  /// joint space variables
122  unsigned int numOfJoints;
123  std::atomic_bool enablePreactivateInit{false};
124 
125  Eigen::MatrixXf I;
126 
127  VirtualRobot::DifferentialIKPtr ik;
128 
129  const float lambda = 2.0f;
130 
131  public:
133 
136 
137  VirtualRobot::RobotNodePtr tcp;
138 
139  void initialize(const VirtualRobot::RobotNodeSetPtr& rns);
140  // Config reconfigure(const std::string &configFileName);
141  void preactivateInit(const VirtualRobot::RobotNodeSetPtr& rns, const Config& c);
142  bool updateControlStatus(const Config& cfg, const RobotStatus& robotStatus);
143  // bool updateControlStatus(
144  // const Config& cfg,
145  // const IceUtil::Time& timeSinceLastIteration,
146  // std::vector<const SensorValue1DoFActuatorTorque*> torqueSensors,
147  // std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors,
148  // std::vector<const SensorValue1DoFActuatorPosition*> positionSensors);
149 
150  // void run(bool rtReady, std::vector<ControlTarget1DoFActuatorTorque*> targets);
151  void run(const Config& cfg, ControlTarget& targets);
152  void firstRun();
153 
154  // bool validateTargetPose(Eigen::Matrix4f &targetPose);
155  std::atomic<bool> isInitialized{false};
156  };
157 } // namespace armarx::control::common::control_law
armarx::control::common::control_law::KeypointsImpedanceController::Config::qvelFilter
float qvelFilter
Definition: KeypointsImpedanceController.h:57
armarx::control::common::control_law::KeypointsImpedanceController::Config::fixedTranslation
Eigen::VectorXf fixedTranslation
Definition: KeypointsImpedanceController.h:63
armarx::control::common::control_law::KeypointsImpedanceController::Config
you can set the following values from outside of the rt controller via Ice interfaces
Definition: KeypointsImpedanceController.h:40
armarx::control::common::control_law::KeypointsImpedanceController::initialize
void initialize(const VirtualRobot::RobotNodeSetPtr &rns)
Definition: KeypointsImpedanceController.cpp:26
armarx::control::common::control_law::KeypointsImpedanceController::isInitialized
std::atomic< bool > isInitialized
Definition: KeypointsImpedanceController.h:155
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::currentTwist
Eigen::Vector6f currentTwist
Definition: KeypointsImpedanceController.h:97
armarx::control::common::control_law::KeypointsImpedanceController::Config::kpNullspace
Eigen::VectorXf kpNullspace
Definition: KeypointsImpedanceController.h:51
armarx::control::common::control_law::KeypointsImpedanceController::firstRun
void firstRun()
Definition: KeypointsImpedanceController.cpp:101
armarx::control::common::control_law::KeypointsImpedanceController::Config::kdNullspace
Eigen::VectorXf kdNullspace
Definition: KeypointsImpedanceController.h:52
armarx::control::common::control_law::KeypointsImpedanceController::Config::kmAdmittance
Eigen::Vector6f kmAdmittance
Definition: KeypointsImpedanceController.h:49
armarx::control::common::control_law::KeypointsImpedanceController::Config::numPoints
int numPoints
keypoints related
Definition: KeypointsImpedanceController.h:60
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::jtpinv
Eigen::MatrixXf jtpinv
Definition: KeypointsImpedanceController.h:105
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
common.h
armarx::control::common::control_law::KeypointsImpedanceController::Config::densityForceScaling
float densityForceScaling
Definition: KeypointsImpedanceController.h:64
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus
Definition: KeypointsImpedanceController.h:89
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::control::common::control_law::KeypointsImpedanceController::tcp
VirtualRobot::RobotNodePtr tcp
Definition: KeypointsImpedanceController.h:137
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::previousKeypointPosition
Eigen::VectorXf previousKeypointPosition
Definition: KeypointsImpedanceController.h:110
armarx::control::common::control_law::KeypointsImpedanceController::Config::keypointPositionFilter
float keypointPositionFilter
Definition: KeypointsImpedanceController.h:69
armarx::control::common::control_law::KeypointsImpedanceController::Config::isRigid
bool isRigid
Definition: KeypointsImpedanceController.h:72
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus
internal status of the controller, containing intermediate variables, mutable targets
Definition: KeypointsImpedanceController.h:76
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredKeypointVelocity
Eigen::VectorXf desiredKeypointVelocity
Definition: KeypointsImpedanceController.h:116
armarx::control::common::control_law::KeypointsImpedanceController::bufferNonRtToRt
TripleBuffer< NonRtStatus > bufferNonRtToRt
Definition: KeypointsImpedanceController.h:134
armarx::control::common::control_law::KeypointsImpedanceController::Config::kdAdmittance
Eigen::Vector6f kdAdmittance
Definition: KeypointsImpedanceController.h:48
armarx::control::common::control_law::KeypointsImpedanceController::bufferRtToOnPublish
TripleBuffer< RtStatus > bufferRtToOnPublish
Definition: KeypointsImpedanceController.h:132
armarx::control::common::control_law::KeypointsImpedanceController::preactivateInit
void preactivateInit(const VirtualRobot::RobotNodeSetPtr &rns, const Config &c)
Definition: KeypointsImpedanceController.cpp:40
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus::forceImpedance
Eigen::Vector6f forceImpedance
task space variables
Definition: KeypointsImpedanceController.h:85
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::jacobi
Eigen::MatrixXf jacobi
others
Definition: KeypointsImpedanceController.h:104
armarx::control::common::control_law::RobotStatus
Definition: common.h:32
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredDensityForce
Eigen::VectorXf desiredDensityForce
Definition: KeypointsImpedanceController.h:117
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredKeypointPosition
Eigen::VectorXf desiredKeypointPosition
Definition: KeypointsImpedanceController.h:115
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::currentPose
Eigen::Matrix4f currentPose
task space variables
Definition: KeypointsImpedanceController.h:96
armarx::control::common::control_law::KeypointsImpedanceController::bufferNonRtToOnPublish
TripleBuffer< NonRtStatus > bufferNonRtToOnPublish
Definition: KeypointsImpedanceController.h:135
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
armarx::control::common::control_law::KeypointsImpedanceController
Definition: KeypointsImpedanceController.h:36
armarx::control::common::control_law::KeypointsImpedanceController::run
void run(const Config &cfg, ControlTarget &targets)
Definition: KeypointsImpedanceController.cpp:262
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::qvel
Eigen::VectorXf qvel
Definition: KeypointsImpedanceController.h:93
armarx::control::common::control_law::KeypointsImpedanceController::Config::keypointKp
Eigen::VectorXf keypointKp
Definition: KeypointsImpedanceController.h:61
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredVel
Eigen::Vector6f desiredVel
Definition: KeypointsImpedanceController.h:100
armarx::control::common::control_law::KeypointsImpedanceController::Config::kpImpedance
Eigen::Vector6f kpImpedance
Definition: KeypointsImpedanceController.h:44
armarx::control::common::control_law::KeypointsImpedanceController::Config::kdImpedance
Eigen::Vector6f kdImpedance
Definition: KeypointsImpedanceController.h:45
TripleBuffer.h
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::qpos
Eigen::VectorXf qpos
joint space variable
Definition: KeypointsImpedanceController.h:92
armarx::control::common::control_law::KeypointsImpedanceController::Config::keypointVelocityFilter
float keypointVelocityFilter
Definition: KeypointsImpedanceController.h:70
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredAcc
Eigen::Vector6f desiredAcc
Definition: KeypointsImpedanceController.h:101
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::currentKeypointPosition
Eigen::VectorXf currentKeypointPosition
Definition: KeypointsImpedanceController.h:112
armarx::control::common::control_law::KeypointsImpedanceController::Config::keypointKd
Eigen::VectorXf keypointKd
Definition: KeypointsImpedanceController.h:62
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus::nullspaceTorque
Eigen::VectorXf nullspaceTorque
Definition: KeypointsImpedanceController.h:86
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus::desiredJointTorques
Eigen::VectorXf desiredJointTorques
targets
Definition: KeypointsImpedanceController.h:79
armarx::control::common::control_law::KeypointsImpedanceController::updateControlStatus
bool updateControlStatus(const Config &cfg, const RobotStatus &robotStatus)
Definition: KeypointsImpedanceController.cpp:118
armarx::control::common::control_law::KeypointsImpedanceController::Config::nodeSetName
std::string nodeSetName
Definition: KeypointsImpedanceController.h:42
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus::desiredTwist
Eigen::Vector6f desiredTwist
Definition: KeypointsImpedanceController.h:82
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::pointTrackingForce
Eigen::Vector6f pointTrackingForce
keypoint status
Definition: KeypointsImpedanceController.h:108
Eigen::Matrix< float, 6, 1 >
armarx::control::common::control_law::KeypointsImpedanceController::Config::desiredNullspaceJointAngles
std::optional< Eigen::VectorXf > desiredNullspaceJointAngles
Definition: KeypointsImpedanceController.h:54
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus::desiredPose
Eigen::Matrix4f desiredPose
Definition: KeypointsImpedanceController.h:81
EigenForwardDeclarations.h
armarx::control::common::control_law::ControlTarget
Definition: common.h:52
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::filteredKeypointPosition
Eigen::VectorXf filteredKeypointPosition
Definition: KeypointsImpedanceController.h:109
armarx::control::common::control_law::KeypointsImpedanceController::Config::torqueLimit
float torqueLimit
Definition: KeypointsImpedanceController.h:56
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::currentKeypointVelocity
Eigen::VectorXf currentKeypointVelocity
Definition: KeypointsImpedanceController.h:113
armarx::TripleBuffer< RtStatus >
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredPose
Eigen::Matrix4f desiredPose
Definition: KeypointsImpedanceController.h:99