3#include <armarx/control/common/common.aron.generated.h>
4#include <armarx/control/common/control_law/aron/TaskspaceControllerConfig.aron.generated.h>
5#include <armarx/control/common/coordination/aron/CoordinationConfig.aron.generated.h>
12 using namespace armarx::control::common;
32 const auto& robotUnit =
35 auto names = robotUnit->getActivatedNJointControllerNames();
41 if (candidateCtrlNames.size() > 1)
43 ARMARX_WARNING <<
"There are more than one controllers matching your name pattern: "
48 if (candidateCtrlNames.empty())
51 << in.parameters.controllerNamePattern
56 const std::string candidateName = candidateCtrlNames[0];
57 ARMARX_INFO <<
"Found matching controller " << candidateName;
58 const bool enable = in.parameters.enable;
60 auto controller = Ice::checkedCast<armarx::control::TSColAvoidCtrlInterfacePrx>(
61 robotUnit->getNJointController(candidateName));
65 auto cfgCoord = coordination::arondto::SyncModeConfig();
68 in.parameters.configRelPath);
69 auto filename = configPath.toSystemPath();
70 ARMARX_INFO <<
"using coordination config: " << filename;
72 << filename <<
" does not exists";
74 std::ifstream ifs{filename};
76 nlohmann::json jsonConfig;
79 armarx::aron::data::reader::NlohmannJSONReaderWithoutTypeCheck reader;
80 cfgCoord.read(reader, jsonConfig);
83 auto cfgDTO = controller->getConfig();
84 auto cfg = control_law::arondto::TSMixImpVelColConfigDict();
86 auto& desiredPose = cfgCoord.desiredPose;
87 auto& poseL = cfg.limbs.at(
"LeftArm").desiredPose;
88 auto& poseR = cfg.limbs.at(
"RightArm").desiredPose;
89 if (cfgCoord.leadershipMode == coordination::arondto::LeadershipMode::object_as_leader)
92 desiredPose.block<3, 1>(0, 3) = 0.5 * (
getPos(poseL) +
getPos(poseR));
94 else if (cfgCoord.leadershipMode ==
95 coordination::arondto::LeadershipMode::left_as_leader)
99 else if (cfgCoord.leadershipMode ==
100 coordination::arondto::LeadershipMode::right_as_leader)
104 if (cfgCoord.followerFrameMode == armarx::control::common::arondto::PoseFrameMode::root)
110 <<
"The pose target computation only support 'root' mode. Please fix the code "
111 "before. Now the followerFrameMode is set to 'PoseFrameMode::root'.";
112 cfgCoord.followerFrameMode = armarx::control::common::arondto::PoseFrameMode::root;
115 for (
auto& pair : cfg.limbs)
117 ARMARX_INFO <<
"Disableing force torque guard for " << pair.first;
118 controller->enableSafeGuardForceTorque(pair.first,
false,
false);
120 controller->useCoordinator(
"", cfgCoord.toAronDTO());
124 controller->disableCoordinator();
129 std::vector<std::string>
131 const std::vector<std::string>& patterns)
133 if (patterns.empty())
135 return controllerNames;
138 std::vector<std::string> matches;
141 for (
const auto& name : controllerNames)
143 bool allPatternsFound =
true;
145 for (
const auto& pattern : patterns)
147 if (name.find(pattern) == std::string::npos)
149 allPatternsFound =
false;
154 if (allPatternsFound)
156 matches.push_back(name);
armarx::plugins::RobotUnitComponentPlugin & getRobotUnitPlugin()
SwitchCoordinationMode(const Services &)
::armarx::skills::SkillDescription GetSkillDescription()
std::vector< std::string > filterControllerNames(const std::vector< std::string > &controllerNames, const std::vector< std::string > &patterns)
RobotUnitInterfacePrx getRobotUnit() const
arondto::SwitchCoordinationModeParams ParamType
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
virtual MainResult main()
Override this method with the actual implementation.
virtual ExitResult exit()
Override this method with the actual implementation.
static MainResult MakeFailedResult(aron::data::DictPtr data=nullptr)
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::string sVecToString(const std::vector< std::string > &vec, const std::string &delimiter)
Eigen::Block< Eigen::Matrix4f, 3, 1 > getPos(Eigen::Matrix4f &matrix)
This file offers overloads of toIce() and fromIce() functions for STL container types.
This file is part of ArmarX.
::armarx::control::client::ComponentPlugin * controlComponentPluginUser
A result struct for skill exit function.
A result struct for th main method of a skill.