NJointControllers.cpp
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 * @package ...
17 * @author Jianfeng Gao ( jianfeng dot gao at kit dot edu )
18 * @date 2025
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "NJointControllers.h"
24
25#include <SimoxUtility/color/Color.h>
26#include <VirtualRobot/MathTools.h>
27#include <VirtualRobot/RobotNodeSet.h>
28
30#include <ArmarXCore/core/PackagePath.h> // for GUI
34
38
41
43{
44 /// ================================== TSMixImpVel ==================================
45 // NJointControllerRegistration<NJointTSMixImpVelController>
46 // registrationControllerNJointTaskspaceController(
47 // "NJointTSMixImpVelController");
48
49 std::string NJointTSMixImpVelController::getClassName(const Ice::Current &) const
50 {
51 return "NJointTSMixImpVelController";
52 }
53
54 void
56 {
57 const auto nDoF = static_cast<Eigen::Index>(arm->jointNames.size());
58
59 const auto checkSize = [nDoF](const auto& v) { ARMARX_CHECK_EQUAL(v.rows(), nDoF); };
60 const auto checkNonNegative = [](const auto& v) { ARMARX_CHECK((v.array() >= 0).all()); };
61 checkSize(configData.desiredNullspaceJointAngles.value());
62 checkSize(configData.kdNullspaceTorque);
63 checkSize(configData.kpNullspaceTorque);
64 checkSize(configData.kdNullspaceVel);
65 checkSize(configData.kpNullspaceVel);
66
67 checkNonNegative(configData.kdNullspaceTorque);
68 checkNonNegative(configData.kpNullspaceTorque);
69 checkNonNegative(configData.kpNullspaceVel);
70 checkNonNegative(configData.kdNullspaceVel);
71 checkNonNegative(configData.kdImpedance);
72 checkNonNegative(configData.kpImpedance);
73 }
74
75 void
77 {
78 auto cfg = arm->bufferConfigRtToOnPublish.getUpToDateReadBuffer();
79 common::debugEigenVec(datafields, "kpImpedance", cfg.kpImpedance);
80 common::debugEigenVec(datafields, "kdImpedance", cfg.kdImpedance);
81 common::debugEigenVec(datafields, "kpCartesianVel", cfg.kpCartesianVel);
82 common::debugEigenVec(datafields, "kdCartesianVel", cfg.kdCartesianVel);
83 if (cfg.desiredNullspaceJointAngles.has_value())
84 {
85 common::debugEigenVec(datafields,
86 "desiredNullspaceJointAngles",
87 cfg.desiredNullspaceJointAngles.value());
88 }
89
90 datafields["poseError_threshold_position"] = new Variant(cfg.safeDistanceMMToGoal);
91 datafields["poseError_threshold_angle"] = new Variant(cfg.safeRotAngleDegreeToGoal);
92 datafields["safeForceGuardThreshold"] =
93 new Variant(cfg.ftConfig.safeGuardForceThreshold);
94 datafields["safeTorqueGuardThreshold"] =
95 new Variant(cfg.ftConfig.safeGuardTorqueThreshold);
96 }
97
98 /// ================================== TSImp ==================================
99 std::string NJointTSImpController::getClassName(const Ice::Current &) const
100 {
101 return "NJointTSImpController";
102 }
103
104 void
105 NJointTSImpController::validateConfigDataCheckSize(Config& configData, ArmPtr& arm)
106 {
107 const auto nDoF = static_cast<Eigen::Index>(arm->jointNames.size());
108
109 const auto checkSize = [nDoF](const auto& v) { ARMARX_CHECK_EQUAL(v.rows(), nDoF); };
110 const auto checkNonNegative = [](const auto& v) { ARMARX_CHECK((v.array() >= 0).all()); };
111 checkSize(configData.desiredNullspaceJointAngles.value());
112 checkSize(configData.kdNullspaceTorque);
113 checkSize(configData.kpNullspaceTorque);
114
115 checkNonNegative(configData.kdNullspaceTorque);
116 checkNonNegative(configData.kpNullspaceTorque);
117 checkNonNegative(configData.kdImpedance);
118 checkNonNegative(configData.kpImpedance);
119 }
120
121 void
123 {
124 auto cfg = arm->bufferConfigRtToOnPublish.getUpToDateReadBuffer();
125 common::debugEigenVec(datafields, "kpImpedance", cfg.kpImpedance);
126 common::debugEigenVec(datafields, "kdImpedance", cfg.kdImpedance);
127 if (cfg.desiredNullspaceJointAngles.has_value())
128 {
129 common::debugEigenVec(datafields,
130 "desiredNullspaceJointAngles",
131 cfg.desiredNullspaceJointAngles.value());
132 }
133
134 datafields["poseError_threshold_position"] = new Variant(cfg.safeDistanceMMToGoal);
135 datafields["poseError_threshold_angle"] = new Variant(cfg.safeRotAngleDegreeToGoal);
136 datafields["safeForceGuardThreshold"] =
137 new Variant(cfg.ftConfig.safeGuardForceThreshold);
138 datafields["safeTorqueGuardThreshold"] =
139 new Variant(cfg.ftConfig.safeGuardTorqueThreshold);
140 }
141} // namespace armarx::control::njoint_controller::task_space
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
================================== TSImp ==================================
Definition Base.cpp:1498
void limbPublishConfig(StringVariantBaseMap &datafields, ArmPtr &arm) override
Definition Base.cpp:1522
void validateConfigDataCheckSize(Config &configData, ArmPtr &arm) override
Definition Base.cpp:1504
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
================================== TSMixImpVel ==================================
Definition Base.cpp:1437
void limbPublishConfig(StringVariantBaseMap &datafields, ArmPtr &arm) override
Definition Base.cpp:1464
void validateConfigDataCheckSize(Config &configData, ArmPtr &arm) override
Definition Base.cpp:1443
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
void debugEigenVec(StringVariantBaseMap &datafields, const std::string &name, Eigen::VectorXf vec)
Definition utils.cpp:190
double v(double t, double v0, double a0, double j)
Definition CtrlUtil.h:39
std::map< std::string, VariantBasePtr > StringVariantBaseMap