KeypointsAdmittanceController.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 <atomic>
25 
26 #include <Eigen/Core>
27 
28 #include <IceUtil/Time.h>
29 
30 #include <VirtualRobot/VirtualRobot.h>
31 
33 
34 namespace armarx
35 {
36  class SensorValue1DoFActuatorTorque;
37  class SensorValue1DoFActuatorVelocity;
38  class SensorValue1DoFActuatorPosition;
39  class ControlTarget1DoFActuatorTorque;
40 } // namespace armarx
41 
43 {
45  {
46  public:
47  /// you can set the following values from outside of the rt controller via Ice interfaces
48  struct Config
49  {
50  std::string nodeSetName;
51 
54 
58 
59  Eigen::VectorXf kpNullspace;
60  Eigen::VectorXf kdNullspace;
61 
63  Eigen::VectorXf desiredNullspaceJointAngles;
64 
65  float torqueLimit;
66  float qvelFilter;
67 
68  /// keypoints related
69  int numPoints;
70  Eigen::VectorXf keypointKp;
71  Eigen::VectorXf keypointKd;
72 
73  Eigen::VectorXf currentKeypointPosition;
74  Eigen::VectorXf desiredKeypointPosition;
75  Eigen::VectorXf desiredKeypointVelocity;
76  float keypointPositionFilter = 1.0f;
77  float keypointVelocityFilter = 1.0f;
78 
79  bool isRigid = false;
80  Eigen::VectorXf fixedTranslation;
81  };
82 
83  /// internal status of the controller, containing intermediate variables, mutable targets
84  struct Status : Config
85  {
86  /// joint space variable
87  Eigen::VectorXf qpos;
88  Eigen::VectorXf qvel;
89 
90  Eigen::VectorXf nullspaceTorque;
91  Eigen::VectorXf desiredJointTorques;
92 
93  /// task spaace variables
98 
102 
106 
108  Eigen::VectorXf filteredKeypointPosition;
109  Eigen::VectorXf previousKeypointPosition;
110  Eigen::VectorXf currentKeypointVelocity;
111 
112  /// others
113  Eigen::MatrixXf jacobi;
114  double deltaT;
115  };
116 
117  private:
118  /// joint space variables
119  unsigned int numOfJoints;
120  std::atomic_bool enablePreactivateInit{false};
121 
122  Eigen::MatrixXf I;
123 
124  VirtualRobot::DifferentialIKPtr ik;
125 
126  const float lambda = 2.0f;
127 
128  public:
130  VirtualRobot::RobotNodePtr tcp;
131 
132  void initialize(const VirtualRobot::RobotNodeSetPtr& rns,
133  const std::string& configFileName);
134  Config reconfigure(const std::string& configFileName);
135  void preactivateInit(const VirtualRobot::RobotNodeSetPtr& rns);
136  bool
137  updateControlStatus(const Config& cfg,
138  const IceUtil::Time& timeSinceLastIteration,
139  std::vector<const SensorValue1DoFActuatorTorque*> torqueSensors,
140  std::vector<const SensorValue1DoFActuatorVelocity*> velocitySensors,
141  std::vector<const SensorValue1DoFActuatorPosition*> positionSensors);
142 
143  void run(bool rtReady, std::vector<ControlTarget1DoFActuatorTorque*> targets);
144  void firstRun();
145  bool validateTargetPose(Eigen::Matrix4f& targetPose);
146  };
147 } // namespace armarx::control::common::control_law
armarx::control::common::control_law::KeypointsAdmittanceController::Status::currentKeypointVelocity
Eigen::VectorXf currentKeypointVelocity
Definition: KeypointsAdmittanceController.h:110
armarx::control::common::control_law::KeypointsAdmittanceController::Status::qpos
Eigen::VectorXf qpos
joint space variable
Definition: KeypointsAdmittanceController.h:87
armarx::control::common::control_law::KeypointsAdmittanceController::Status::desiredAcc
Eigen::Vector6f desiredAcc
Definition: KeypointsAdmittanceController.h:97
armarx::control::common::control_law::KeypointsAdmittanceController::Status::desiredJointTorques
Eigen::VectorXf desiredJointTorques
Definition: KeypointsAdmittanceController.h:91
armarx::control::common::control_law::KeypointsAdmittanceController::Config::nodeSetName
std::string nodeSetName
Definition: KeypointsAdmittanceController.h:50
armarx::control::common::control_law::KeypointsAdmittanceController::firstRun
void firstRun()
Definition: KeypointsAdmittanceController.cpp:215
armarx::control::common::control_law::KeypointsAdmittanceController::Status::virtualVel
Eigen::Vector6f virtualVel
Definition: KeypointsAdmittanceController.h:104
armarx::control::common::control_law::KeypointsAdmittanceController::Config::fixedTranslation
Eigen::VectorXf fixedTranslation
Definition: KeypointsAdmittanceController.h:80
armarx::control::common::control_law::KeypointsAdmittanceController::Config::kdAdmittance
Eigen::Vector6f kdAdmittance
Definition: KeypointsAdmittanceController.h:56
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::control::common::control_law::KeypointsAdmittanceController::Status::jacobi
Eigen::MatrixXf jacobi
others
Definition: KeypointsAdmittanceController.h:113
armarx::control::common::control_law::KeypointsAdmittanceController::Config::kmAdmittance
Eigen::Vector6f kmAdmittance
Definition: KeypointsAdmittanceController.h:57
armarx::control::common::control_law::KeypointsAdmittanceController
Definition: KeypointsAdmittanceController.h:44
armarx::control::common::control_law::KeypointsAdmittanceController::reconfigure
Config reconfigure(const std::string &configFileName)
Definition: KeypointsAdmittanceController.cpp:131
armarx::control::common::control_law::KeypointsAdmittanceController::Config::isRigid
bool isRigid
Definition: KeypointsAdmittanceController.h:79
armarx::control::common::control_law::KeypointsAdmittanceController::Config::currentKeypointPosition
Eigen::VectorXf currentKeypointPosition
Definition: KeypointsAdmittanceController.h:73
armarx::control::common::control_law::KeypointsAdmittanceController::Config::keypointPositionFilter
float keypointPositionFilter
Definition: KeypointsAdmittanceController.h:76
armarx::control::common::control_law::KeypointsAdmittanceController::Status::previousDesiredPose
Eigen::Matrix4f previousDesiredPose
task spaace variables
Definition: KeypointsAdmittanceController.h:94
armarx::control::common::control_law::KeypointsAdmittanceController::Config::keypointKp
Eigen::VectorXf keypointKp
Definition: KeypointsAdmittanceController.h:70
armarx::control::common::control_law::KeypointsAdmittanceController::Status::desiredVel
Eigen::Vector6f desiredVel
Definition: KeypointsAdmittanceController.h:96
armarx::control::common::control_law::KeypointsAdmittanceController::Config::kpImpedance
Eigen::Vector6f kpImpedance
Definition: KeypointsAdmittanceController.h:52
armarx::control::common::control_law::KeypointsAdmittanceController::s
Status s
Definition: KeypointsAdmittanceController.h:129
armarx::control::common::control_law::KeypointsAdmittanceController::preactivateInit
void preactivateInit(const VirtualRobot::RobotNodeSetPtr &rns)
Definition: KeypointsAdmittanceController.cpp:172
armarx::control::common::control_law::KeypointsAdmittanceController::updateControlStatus
bool updateControlStatus(const Config &cfg, const IceUtil::Time &timeSinceLastIteration, std::vector< const SensorValue1DoFActuatorTorque * > torqueSensors, std::vector< const SensorValue1DoFActuatorVelocity * > velocitySensors, std::vector< const SensorValue1DoFActuatorPosition * > positionSensors)
Definition: KeypointsAdmittanceController.cpp:250
armarx::control::common::control_law::KeypointsAdmittanceController::Config::desiredKeypointVelocity
Eigen::VectorXf desiredKeypointVelocity
Definition: KeypointsAdmittanceController.h:75
armarx::control::common::control_law::KeypointsAdmittanceController::run
void run(bool rtReady, std::vector< ControlTarget1DoFActuatorTorque * > targets)
Definition: KeypointsAdmittanceController.cpp:414
armarx::control::common::control_law::KeypointsAdmittanceController::Status::virtualAcc
Eigen::Vector6f virtualAcc
Definition: KeypointsAdmittanceController.h:105
armarx::control::common::control_law::KeypointsAdmittanceController::Config::currentForceTorque
Eigen::Vector6f currentForceTorque
Definition: KeypointsAdmittanceController.h:62
armarx::control::common::control_law::KeypointsAdmittanceController::Status::previousKeypointPosition
Eigen::VectorXf previousKeypointPosition
Definition: KeypointsAdmittanceController.h:109
armarx::control::common::control_law
This file is part of ArmarX.
Definition: aron_conversions.cpp:68
armarx::control::common::control_law::KeypointsAdmittanceController::Status
internal status of the controller, containing intermediate variables, mutable targets
Definition: KeypointsAdmittanceController.h:84
armarx::control::common::control_law::KeypointsAdmittanceController::Config::kdImpedance
Eigen::Vector6f kdImpedance
Definition: KeypointsAdmittanceController.h:53
armarx::control::common::control_law::KeypointsAdmittanceController::initialize
void initialize(const VirtualRobot::RobotNodeSetPtr &rns, const std::string &configFileName)
Definition: KeypointsAdmittanceController.cpp:30
armarx::control::common::control_law::KeypointsAdmittanceController::Config::keypointKd
Eigen::VectorXf keypointKd
Definition: KeypointsAdmittanceController.h:71
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::common::control_law::KeypointsAdmittanceController::Status::virtualPose
Eigen::Matrix4f virtualPose
Definition: KeypointsAdmittanceController.h:103
armarx::control::common::control_law::KeypointsAdmittanceController::Config::keypointVelocityFilter
float keypointVelocityFilter
Definition: KeypointsAdmittanceController.h:77
armarx::control::common::control_law::KeypointsAdmittanceController::Status::currentPose
Eigen::Matrix4f currentPose
Definition: KeypointsAdmittanceController.h:99
armarx::control::common::control_law::KeypointsAdmittanceController::Config::torqueLimit
float torqueLimit
Definition: KeypointsAdmittanceController.h:65
armarx::control::common::control_law::KeypointsAdmittanceController::Config::qvelFilter
float qvelFilter
Definition: KeypointsAdmittanceController.h:66
armarx::control::common::control_law::KeypointsAdmittanceController::Status::pointTrackingForce
Eigen::Vector6f pointTrackingForce
Definition: KeypointsAdmittanceController.h:107
armarx::control::common::control_law::KeypointsAdmittanceController::tcp
VirtualRobot::RobotNodePtr tcp
Definition: KeypointsAdmittanceController.h:130
armarx::control::common::control_law::KeypointsAdmittanceController::Status::currentTwist
Eigen::Vector6f currentTwist
Definition: KeypointsAdmittanceController.h:100
armarx::control::common::control_law::KeypointsAdmittanceController::Config
you can set the following values from outside of the rt controller via Ice interfaces
Definition: KeypointsAdmittanceController.h:48
armarx::control::common::control_law::KeypointsAdmittanceController::Config::kpAdmittance
Eigen::Vector6f kpAdmittance
Definition: KeypointsAdmittanceController.h:55
armarx::control::common::control_law::KeypointsAdmittanceController::Config::desiredNullspaceJointAngles
Eigen::VectorXf desiredNullspaceJointAngles
Definition: KeypointsAdmittanceController.h:63
Eigen::Matrix< float, 6, 1 >
armarx::control::common::control_law::KeypointsAdmittanceController::Status::desiredPose
Eigen::Matrix4f desiredPose
Definition: KeypointsAdmittanceController.h:95
armarx::control::common::control_law::KeypointsAdmittanceController::Status::forceImpedance
Eigen::Vector6f forceImpedance
Definition: KeypointsAdmittanceController.h:101
armarx::control::common::control_law::KeypointsAdmittanceController::Config::kpNullspace
Eigen::VectorXf kpNullspace
Definition: KeypointsAdmittanceController.h:59
EigenForwardDeclarations.h
armarx::control::common::control_law::KeypointsAdmittanceController::Status::nullspaceTorque
Eigen::VectorXf nullspaceTorque
Definition: KeypointsAdmittanceController.h:90
armarx::control::common::control_law::KeypointsAdmittanceController::Status::deltaT
double deltaT
Definition: KeypointsAdmittanceController.h:114
armarx::control::common::control_law::KeypointsAdmittanceController::Status::qvel
Eigen::VectorXf qvel
Definition: KeypointsAdmittanceController.h:88
armarx::control::common::control_law::KeypointsAdmittanceController::Config::kdNullspace
Eigen::VectorXf kdNullspace
Definition: KeypointsAdmittanceController.h:60
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::control::common::control_law::KeypointsAdmittanceController::Config::desiredKeypointPosition
Eigen::VectorXf desiredKeypointPosition
Definition: KeypointsAdmittanceController.h:74
armarx::control::common::control_law::KeypointsAdmittanceController::Config::numPoints
int numPoints
keypoints related
Definition: KeypointsAdmittanceController.h:69
armarx::control::common::control_law::KeypointsAdmittanceController::Status::filteredKeypointPosition
Eigen::VectorXf filteredKeypointPosition
Definition: KeypointsAdmittanceController.h:108
armarx::control::common::control_law::KeypointsAdmittanceController::validateTargetPose
bool validateTargetPose(Eigen::Matrix4f &targetPose)
Definition: KeypointsAdmittanceController.cpp:228