MoveJointsWithVelocity.cpp
Go to the documentation of this file.
2 
4 
6 
8 {
9 
11  ::armarx::skills::SimpleSpecializedSkill<ParamType>(GetSkillDescription()), srv_(srv)
12  {
13  }
14 
15  std::map<std::string, float>
16  MoveJointsWithVelocity::filterJointTargetValues(
17  const NameValueMap& jointsTargetValues,
18  const std::vector<std::string>& disabledJoints) const
19  {
20  std::map<std::string, float> filtered;
21  for (const auto& [jointName, v] : jointsTargetValues)
22  {
23  if (std::find(disabledJoints.begin(), disabledJoints.end(), jointName) !=
24  disabledJoints.end())
25  {
26  ARMARX_INFO << "Disable joint " << jointName
27  << " because it was explictly disabled in skill params.";
28  continue;
29  }
30  filtered[jointName] = v;
31  }
32  return filtered;
33  }
34 
36  MoveJointsWithVelocity::exit(const SpecializedExitInput& in)
37  {
38  auto filtered = this->filterJointTargetValues(in.parameters.jointsTargetVelocities,
39  in.parameters.disabledJoints);
40 
41  auto jointNames = simox::alg::get_keys(filtered);
42 
43  for (auto& [k, v] : filtered)
44  {
45  filtered[k] = 0.0;
46  }
47 
48  srv_.kinematicUnit->setJointVelocities(filtered);
49 
50  srv_.kinematicUnit->releaseJoints(jointNames);
51  return {::armarx::skills::TerminatedSkillStatus::Succeeded};
52  }
53 
55  MoveJointsWithVelocity::main(const SpecializedMainInput& in)
56  {
57  auto filtered = this->filterJointTargetValues(in.parameters.jointsTargetVelocities,
58  in.parameters.disabledJoints);
59 
60  auto jointNames = simox::alg::get_keys(filtered);
61 
62  // request joints
63  ARMARX_INFO << "Requesting joints";
64  try
65  {
66  srv_.kinematicUnit->requestJoints(jointNames);
67  }
68  catch (const armarx::KinematicUnitUnavailable& e)
69  {
70  ARMARX_IMPORTANT << "Failed to request joints. Terminating. Joints unavailable:"
71  << e.nodeOwners;
72  return MakeFailedResult();
73  }
74 
75  // move joints
76  ARMARX_INFO << "Moving joints with vel " << filtered;
77 
78  switchControlMode(filtered, eVelocityControl);
79 
80  moveJoints(filtered, in.parameters.duration);
81  return MakeSucceededResult();
82  }
83 
84  void
85  MoveJointsWithVelocity::switchControlMode(const NameValueMap& jointsTargetValues,
86  const ControlMode controlMode)
87  {
88  armarx::NameControlModeMap modeMap;
89  for (const auto& [jointName, _] : jointsTargetValues)
90  {
91  modeMap[jointName] = controlMode;
92  }
93  srv_.kinematicUnit->switchControlMode(modeMap);
94  }
95 
96  void
97  MoveJointsWithVelocity::moveJoints(const NameValueMap& jointsTargetVelocities,
99  {
100  srv_.kinematicUnit->setJointVelocities(jointsTargetVelocities);
101 
102  const Clock clock;
103  const Duration sleepTime = Duration::MilliSeconds(50);
104 
107  {
109  clock.waitFor(sleepTime);
110  }
111  }
112 
113 } // namespace armarx::control::skills::skills
skills
This file is part of ArmarX.
armarx::skills::SimpleSpecializedSkill< arondto::MoveJointsWithVelocityParams >::ParamType
arondto::MoveJointsWithVelocityParams ParamType
Definition: SimpleSpecializedSkill.h:14
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
Trajectory.h
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:51
armarx::control::skills::skills::MoveJointsWithVelocity::Services
Definition: MoveJointsWithVelocity.h:27
armarx::control::skills::skills::MoveJointsWithVelocity::Services::kinematicUnit
::armarx::KinematicUnitInterfacePrx kinematicUnit
Definition: MoveJointsWithVelocity.h:29
armarx::skills::SimpleSpecializedSkill< arondto::MoveJointsWithVelocityParams >::exit
Skill::ExitResult exit() final
Definition: SimpleSpecializedSkill.h:81
Clock.h
armarx::skills::Skill::MakeFailedResult
static MainResult MakeFailedResult()
Definition: Skill.cpp:338
MoveJointsWithVelocity.h
armarx::skills::Skill::started
armarx::core::time::DateTime started
Definition: Skill.h:284
armarx::skills::Skill::MakeSucceededResult
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition: Skill.cpp:329
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:39
armarx::skills::Skill::ExitResult
A result struct for skill exit function.
Definition: Skill.h:46
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:88
armarx::control::skills::skills::MoveJointsWithVelocity::MoveJointsWithVelocity
MoveJointsWithVelocity(const Services &)
Definition: MoveJointsWithVelocity.cpp:10
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::skills::SimpleSpecializedSkill< arondto::MoveJointsWithVelocityParams >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
armarx::control::skills::skills
Definition: ExecuteTrajectory.cpp:18
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:16
armarx::skills::Skill::throwIfSkillShouldTerminate
void throwIfSkillShouldTerminate(const std::string &abortedMessage="")
Definition: Skill.cpp:305
stopwatch::Clock
std::chrono::system_clock Clock
Definition: Stopwatch.h:10
armarx::armem::Duration
armarx::core::time::Duration Duration
Definition: forward_declarations.h:14
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:48