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