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  {
45 
46 // Eigen::Vector6f kpAdmittance; /// might not be needed anymore
49 
50  Eigen::VectorXf kpNullspace;
51  Eigen::VectorXf kdNullspace;
52 
53  std::optional<Eigen::VectorXf> desiredNullspaceJointAngles;
54 
55  float torqueLimit;
56  float qvelFilter;
57 
58  /// keypoints related
59  int numPoints;
60  Eigen::VectorXf keypointKp;
61  Eigen::VectorXf keypointKd;
62  Eigen::VectorXf fixedTranslation;
63  float densityForceScaling = 1.0;
64 // Eigen::VectorXf currentKeypointPosition;
65 // Eigen::VectorXf desiredKeypointPosition;
66 // Eigen::VectorXf desiredKeypointVelocity;
67 // Eigen::VectorXf desiredDensityForce;
68  float keypointPositionFilter = 1.0f;
69  float keypointVelocityFilter = 1.0f;
70 
71  bool isRigid = false;
72  };
73 
74  /// internal status of the controller, containing intermediate variables, mutable targets
75  struct RtStatus
76  {
77  /// targets
78  Eigen::VectorXf desiredJointTorques;
79 
82 
83  /// task space variables
85  Eigen::VectorXf nullspaceTorque;
86  };
87 
88  struct NonRtStatus
89  {
90  /// joint space variable
91  Eigen::VectorXf qpos;
92  Eigen::VectorXf qvel;
93 
94  /// task space variables
97 
101 
102  /// others
103  Eigen::MatrixXf jacobi;
104  Eigen::MatrixXf jtpinv;
105 
106  /// keypoint status
108  Eigen::VectorXf filteredKeypointPosition;
109  Eigen::VectorXf previousKeypointPosition;
110 
111  Eigen::VectorXf currentKeypointPosition;
112  Eigen::VectorXf currentKeypointVelocity;
113 
114  Eigen::VectorXf desiredKeypointPosition;
115  Eigen::VectorXf desiredKeypointVelocity;
116  Eigen::VectorXf desiredDensityForce;
117  };
118 
119  private:
120  /// joint space variables
121  unsigned int numOfJoints;
122  std::atomic_bool enablePreactivateInit{false};
123 
124  Eigen::MatrixXf I;
125 
126  VirtualRobot::DifferentialIKPtr ik;
127 
128  const float lambda = 2.0f;
129  public:
131 
134 
135  VirtualRobot::RobotNodePtr tcp;
136 
137  void initialize(const VirtualRobot::RobotNodeSetPtr& rns);
138  // Config reconfigure(const std::string &configFileName);
139  void preactivateInit(const VirtualRobot::RobotNodeSetPtr& rns, const Config& c);
140  bool updateControlStatus(
141  const Config& cfg,
142  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:56
armarx::control::common::control_law::KeypointsImpedanceController::Config::fixedTranslation
Eigen::VectorXf fixedTranslation
Definition: KeypointsImpedanceController.h:62
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:155
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::currentTwist
Eigen::Vector6f currentTwist
Definition: KeypointsImpedanceController.h:96
armarx::control::common::control_law::KeypointsImpedanceController::Config::kpNullspace
Eigen::VectorXf kpNullspace
Definition: KeypointsImpedanceController.h:50
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:51
armarx::control::common::control_law::KeypointsImpedanceController::Config::kmAdmittance
Eigen::Vector6f kmAdmittance
Definition: KeypointsImpedanceController.h:48
armarx::control::common::control_law::KeypointsImpedanceController::Config::numPoints
int numPoints
keypoints related
Definition: KeypointsImpedanceController.h:59
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::jtpinv
Eigen::MatrixXf jtpinv
Definition: KeypointsImpedanceController.h:104
common.h
armarx::control::common::control_law::KeypointsImpedanceController::Config::densityForceScaling
float densityForceScaling
Definition: KeypointsImpedanceController.h:63
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus
Definition: KeypointsImpedanceController.h:88
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::control::common::control_law::KeypointsImpedanceController::tcp
VirtualRobot::RobotNodePtr tcp
Definition: KeypointsImpedanceController.h:135
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::previousKeypointPosition
Eigen::VectorXf previousKeypointPosition
Definition: KeypointsImpedanceController.h:109
armarx::control::common::control_law::KeypointsImpedanceController::Config::keypointPositionFilter
float keypointPositionFilter
Definition: KeypointsImpedanceController.h:68
armarx::control::common::control_law::KeypointsImpedanceController::Config::isRigid
bool isRigid
Definition: KeypointsImpedanceController.h:71
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus
internal status of the controller, containing intermediate variables, mutable targets
Definition: KeypointsImpedanceController.h:75
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredKeypointVelocity
Eigen::VectorXf desiredKeypointVelocity
Definition: KeypointsImpedanceController.h:115
armarx::control::common::control_law::KeypointsImpedanceController::bufferNonRtToRt
TripleBuffer< NonRtStatus > bufferNonRtToRt
Definition: KeypointsImpedanceController.h:132
armarx::control::common::control_law::KeypointsImpedanceController::Config::kdAdmittance
Eigen::Vector6f kdAdmittance
Definition: KeypointsImpedanceController.h:47
armarx::control::common::control_law::KeypointsImpedanceController::bufferRtToOnPublish
TripleBuffer< RtStatus > bufferRtToOnPublish
Definition: KeypointsImpedanceController.h:130
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:84
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::jacobi
Eigen::MatrixXf jacobi
others
Definition: KeypointsImpedanceController.h:103
armarx::control::common::control_law::RobotStatus
Definition: common.h:30
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredDensityForce
Eigen::VectorXf desiredDensityForce
Definition: KeypointsImpedanceController.h:116
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredKeypointPosition
Eigen::VectorXf desiredKeypointPosition
Definition: KeypointsImpedanceController.h:114
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::currentPose
Eigen::Matrix4f currentPose
task space variables
Definition: KeypointsImpedanceController.h:95
armarx::control::common::control_law::KeypointsImpedanceController::bufferNonRtToOnPublish
TripleBuffer< NonRtStatus > bufferNonRtToOnPublish
Definition: KeypointsImpedanceController.h:133
armarx::control::common::control_law
namespace armarx::control::common::ft
Definition: aron_conversions.cpp:62
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:92
armarx::control::common::control_law::KeypointsImpedanceController::Config::keypointKp
Eigen::VectorXf keypointKp
Definition: KeypointsImpedanceController.h:60
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredVel
Eigen::Vector6f desiredVel
Definition: KeypointsImpedanceController.h:99
armarx::control::common::control_law::KeypointsImpedanceController::Config::kpImpedance
Eigen::Vector6f kpImpedance
Definition: KeypointsImpedanceController.h:43
armarx::control::common::control_law::KeypointsImpedanceController::Config::kdImpedance
Eigen::Vector6f kdImpedance
Definition: KeypointsImpedanceController.h:44
TripleBuffer.h
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::qpos
Eigen::VectorXf qpos
joint space variable
Definition: KeypointsImpedanceController.h:91
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::control::common::control_law::KeypointsImpedanceController::Config::keypointVelocityFilter
float keypointVelocityFilter
Definition: KeypointsImpedanceController.h:69
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredAcc
Eigen::Vector6f desiredAcc
Definition: KeypointsImpedanceController.h:100
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::currentKeypointPosition
Eigen::VectorXf currentKeypointPosition
Definition: KeypointsImpedanceController.h:111
armarx::control::common::control_law::KeypointsImpedanceController::Config::keypointKd
Eigen::VectorXf keypointKd
Definition: KeypointsImpedanceController.h:61
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus::nullspaceTorque
Eigen::VectorXf nullspaceTorque
Definition: KeypointsImpedanceController.h:85
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus::desiredJointTorques
Eigen::VectorXf desiredJointTorques
targets
Definition: KeypointsImpedanceController.h:78
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::RtStatus::desiredTwist
Eigen::Vector6f desiredTwist
Definition: KeypointsImpedanceController.h:81
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::pointTrackingForce
Eigen::Vector6f pointTrackingForce
keypoint status
Definition: KeypointsImpedanceController.h:107
Eigen::Matrix< float, 6, 1 >
armarx::control::common::control_law::KeypointsImpedanceController::Config::desiredNullspaceJointAngles
std::optional< Eigen::VectorXf > desiredNullspaceJointAngles
Definition: KeypointsImpedanceController.h:53
armarx::control::common::control_law::KeypointsImpedanceController::RtStatus::desiredPose
Eigen::Matrix4f desiredPose
Definition: KeypointsImpedanceController.h:80
armarx::control::common::control_law::ControlTarget
Definition: common.h:44
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::filteredKeypointPosition
Eigen::VectorXf filteredKeypointPosition
Definition: KeypointsImpedanceController.h:108
armarx::control::common::control_law::KeypointsImpedanceController::Config::torqueLimit
float torqueLimit
Definition: KeypointsImpedanceController.h:55
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::currentKeypointVelocity
Eigen::VectorXf currentKeypointVelocity
Definition: KeypointsImpedanceController.h:112
SensorValue1DoFActuator.h
armarx::TripleBuffer
A simple triple buffer for lockfree comunication between a single writer and a single reader.
Definition: TripleBuffer.h:71
armarx::control::common::control_law::KeypointsImpedanceController::NonRtStatus::desiredPose
Eigen::Matrix4f desiredPose
Definition: KeypointsImpedanceController.h:98