ExecuteTrajectory.cpp
Go to the documentation of this file.
1 #include "ExecuteTrajectory.h"
2 
4 
6 //#include <armarx/control/common/mp/MP.h>
7 //#include <armarx/control/common/mp/aron/MPConfig.aron.generated.h>
8 //#include <armarx/control/common/utils.h>
9 
10 #include <SimoxUtility/json/json.hpp>
11 
12 //#include <armarx/control/interface/ConfigurableNJointControllerInterface.h>
14 //#include <armarx/control/njoint_mp_controller/task_space/MixedImpedanceVelocityController.h>
15 //#include <armarx/control/skills/constants/constants.h>
17 
19 {
20 
22  ::armarx::skills::SimpleSpecializedSkill<ParamType>(GetSkillDescription()), srv_(srv)
23  {
24  }
25 
27  ExecuteTrajectory::exit(const SpecializedExitInput& in)
28  {
29 
30  return {::armarx::skills::TerminatedSkillStatus::Succeeded};
31  }
32 
34  ExecuteTrajectory::main(const SpecializedMainInput& in)
35  {
36  ARMARX_INFO << "in main of execute trajectory";
38 
39  // Currently controller only works for right arm
40  // ARMARX_CHECK(in.parameters.robotNodeset == "" or in.parameters.robotNodeset == "RightArm")
41  // << "Controller currently only works for right arm.";
42 
43  // std::string robotNodesetName =
44  // in.parameters.robotNodeset == "" ? "RightArm" : in.parameters.robotNodeset;
45 
46  // create controller
47  std::string controllerNamePrefix = "executeTrajectory";
48 
49  // auto controlType = armarx::control::common::ControllerType::TSMPMixImpVel;
50  // if (in.parameters.inSimulation)
51  // {
52  // controlType = armarx::control::common::ControllerType::TSMPVel;
53  // }
54  auto builder =
56  // ->createControllerBuilder<armarx::control::common::ControllerType::TSMPVel>();
57  // ->createControllerBuilder<armarx::control::common::ControllerType::TSMPMixImpVel>();
59  // auto ctrlWrapper = builder.createTSComplianceCtrl(
60  // controllerNamePrefix, nullptr, in.parameters.controllerConfigPath);
61  // auto ctrlWrapper = builder.createTSComplianceMPCtrl(controllerNamePrefix,
62  // in.parameters.mpConfigList.toAronDTO(),
63  // nullptr,
64  // in.parameters.controllerConfigPath);
65 
66 
67  // armarx::control::NJointTSMixedImpedanceVelocityMPControllerInterfacePrx ctrl =
68  // armarx::control::NJointTSMixedImpedanceVelocityMPControllerInterfacePrx::checkedCast(
69  // ctrlWrapper->ctrl());
70  // ARMARX_TRACE;
71  // ARMARX_CHECK_NOT_NULL(ctrl);
72  //
73  // ctrl->updateMPConfig(in.parameters.mpConfigList.toAronDTO());
74  // ctrl->trainMP();
75  //
76  // // start controller
77  // ARMARX_CHECK_NOT_NULL(ctrl);
78  // ctrl->startAll();
79 
80  // wait until execution is finished, or termination is requested
81  // ARMARX_TRACE;
82 
83  // /// add hand controller
84  // armarx::skills::manager::dto::SkillExecutionRequest exec;
85  // exec.skillId = {
86  // {::armarx::control::skills::constants::CONTROL_SKILL_PROVIDER_NAME},
87  // ::armarx::control::skills::skills::ShapeHand::GetSkillDescription().skillId.skillName};
88 
89  // ::armarx::control::skills::skills::ShapeHand::ParamType shapeHandParamsContact;
90  // ::armarx::control::skills::arondto::Hand hand;
91  // if (robotNodesetName.find("Left") != std::string::npos)
92  // {
93  // hand = ::armarx::control::skills::arondto::Hand::Hand::Left;
94  // }
95  // else
96  // {
97  // hand = ::armarx::control::skills::arondto::Hand::Hand::Right;
98  // }
99  // toAron(shapeHandParamsContact.hand, hand);
100 
101 
102  // ///
103  // ARMARX_INFO << "-- parsing hand via points";
104  // std::vector<std::pair<int, double>> indexCanValueList;
105  // for (size_t i = 0; i < in.parameters.viapointListHandShape.size(); ++i)
106  // {
107  // indexCanValueList.push_back(
108  // std::make_pair(i, in.parameters.viapointListHandShape.at(i).canVal));
109  // }
110  // std::sort(indexCanValueList.begin(),
111  // indexCanValueList.end(),
112  // [](const std::pair<int, double>& a, const std::pair<int, double>& b)
113  // { return a.second > b.second; });
114  // ARMARX_INFO << "-- size: " << in.parameters.viapointListHandShape.size();
115  // ARMARX_INFO << "-- size: " << indexCanValueList.size();
116 
117  auto ctrl = builder.createGetTSComplianceMPCtrl(controllerNamePrefix,
118  in.parameters.mpConfigList.toAronDTO(),
119  nullptr,
120  in.parameters.controllerConfigPath);
121  std::string mainCanValName;
122  std::string nodeSetName;
123  for (auto& mpCfg : in.parameters.mpConfigList.mpList)
124  {
125  if (mpCfg.role == "taskspace")
126  {
127  mainCanValName = mpCfg.name;
128  nodeSetName = mpCfg.nodeSetName;
129  break;
130  }
131  }
132  ARMARX_CHECK_NOT_NULL(ctrl);
134  // size_t handViaPointIdx = 0;
135  // bool forceTorqueGuardToggled = false;
136  while (!ctrl->isFinishedAll() and not shouldSkillTerminate())
137  {
138  auto canVal = ctrl->getCanVal(mainCanValName);
139  // ARMARX_INFO << "-- at " << canVal;
140  // if (handViaPointIdx < in.parameters.viapointListHandShape.size() and
141  // canVal < indexCanValueList.at(handViaPointIdx).second)
142  // {
143  // ARMARX_INFO << "-- at " << canVal << " with idx: " << handViaPointIdx;
144  // shapeHandParamsContact.shapeName =
145  // in.parameters.viapointListHandShape
146  // .at(indexCanValueList.at(handViaPointIdx).first)
147  // .handShapeName;
148  // exec.parameters = shapeHandParamsContact.toAron()->toAronDictDTO();
149 
150  // manager->begin_executeSkill(exec);
151  // ARMARX_INFO << "-- index: " << handViaPointIdx
152  // << "\n-- shapeName: " << shapeHandParamsContact.shapeName.value()
153  // << "\n-- canVal: " << indexCanValueList.at(handViaPointIdx).second;
154  // handViaPointIdx++;
155  // }
156 
157  //// TODO add force torque guard in the mp controllers, see MPPool.cpp
158  // if (not forceTorqueGuardToggled and canVal < in.parameters.forceTorqueGuardCanVal)
159  // {
160  // ARMARX_IMPORTANT << "-- enable force torque guard at " << canVal;
161  // forceTorqueGuardToggled = true;
162  // ctrl->enableSafeGuardForceTorque(robotNodesetName, true, false);
163  // }
164  if (not ctrl->isSafeForceTorque(nodeSetName))
165  {
166  ARMARX_IMPORTANT << "!!!! Force Torque Guard Triggered Stopping !!! at " << canVal;
167  ctrl->pauseAll();
168  break;
169  }
171  }
173  // auto canVal = ctrl->getCanVal("default");
174  // ARMARX_INFO << "--- done with force torque guard safe status <<< "
175  // << ctrl->isSafeForceTorque(robotNodesetName) << " >>> with canVal " << canVal;
176  // if (not shouldSkillTerminate() and
177  // handViaPointIdx < in.parameters.viapointListHandShape.size())
178  // {
179  // ARMARX_INFO << "--- execute the last hand shape";
180  // shapeHandParamsContact.shapeName =
181  // in.parameters.viapointListHandShape.at(indexCanValueList.at(handViaPointIdx).first)
182  // .handShapeName;
183  // exec.parameters = shapeHandParamsContact.toAron()->toAronDictDTO();
184  // manager->begin_executeSkill(exec);
185  // }
186  // ARMARX_INFO << "-- deleting controller";
187 
188  // while (ctrl->isControllerActive())
189  // {
190  // ctrl->deactivateController();
191  // usleep(10000);
192  // }
193  // ctrl->deleteController();
194 
195  return MakeSucceededResult();
196  }
197 
198 
199 } // namespace armarx::control::skills::skills
skills
This file is part of ArmarX.
armarx::skills::SimpleSpecializedSkill< arondto::ExecuteTrajectoryParams >::ParamType
arondto::ExecuteTrajectoryParams ParamType
Definition: SimpleSpecializedSkill.h:14
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
Trajectory.h
armarx::core::time::Clock::WaitFor
static void WaitFor(const Duration &duration)
Wait for a certain duration on the virtual clock.
Definition: Clock.cpp:104
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
aron_conversions.h
armarx::control::skills::skills::ExecuteTrajectory::ExecuteTrajectory
ExecuteTrajectory(const Services &)
Definition: ExecuteTrajectory.cpp:21
ExecuteTrajectory.h
armarx::skills::SimpleSpecializedSkill< arondto::ExecuteTrajectoryParams >::exit
Skill::ExitResult exit() final
Definition: SimpleSpecializedSkill.h:81
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::core::time::Duration::Seconds
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition: Duration.cpp:83
armarx::control::common::ControllerType::TSMPMixImpVelCol
@ TSMPMixImpVelCol
armarx::control::skills::skills::ExecuteTrajectory::Services
Definition: ExecuteTrajectory.h:28
armarx::control::client::ComponentPlugin::createControllerBuilder
auto createControllerBuilder(Args... args)
Definition: ComponentPlugin.h:83
ShapeHand.h
armarx::skills::Skill::MakeSucceededResult
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition: Skill.cpp:315
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:48
controller_descriptions.h
armarx::skills::Skill::ExitResult
A result struct for skill exit function.
Definition: Skill.h:55
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::skills::SimpleSpecializedSkill< arondto::ExecuteTrajectoryParams >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
armarx::control::skills::skills
Definition: ExecuteTrajectory.cpp:18
armarx::skills::Skill::shouldSkillTerminate
bool shouldSkillTerminate() const
Returns whether the skill should terminate as soon as possible.
Definition: Skill.cpp:371
armarx::skills::Skill::throwIfSkillShouldTerminate
void throwIfSkillShouldTerminate(const std::string &abortedMessage="")
Definition: Skill.cpp:291
armarx::control::skills::skills::ExecuteTrajectory::Services::controlComponentPluginUser
::armarx::control::client::ComponentPlugin * controlComponentPluginUser
Definition: ExecuteTrajectory.h:30
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55