MoveJointsWithVelocity.cpp
Go to the documentation of this file.
2 
4 
6 {
7 
9  ::armarx::skills::SimpleSpecializedSkill<ParamType>(GetSkillDescription()), srv_(srv)
10  {
11  }
12 
13  std::map<std::string, float>
14  MoveJointsWithVelocity::filterJointTargetValues(
15  const NameValueMap& jointsTargetValues,
16  const std::vector<std::string>& disabledJoints) const
17  {
18  std::map<std::string, float> filtered;
19  for (const auto& [jointName, v] : jointsTargetValues)
20  {
21  if (std::find(disabledJoints.begin(), disabledJoints.end(), jointName) !=
22  disabledJoints.end())
23  {
24  ARMARX_INFO << "Disable joint " << jointName
25  << " because it was explictly disabled in skill params.";
26  continue;
27  }
28  filtered[jointName] = v;
29  }
30  return filtered;
31  }
32 
34  MoveJointsWithVelocity::exit(const SpecializedExitInput& in)
35  {
36  auto filtered = this->filterJointTargetValues(in.parameters.jointsTargetVelocities,
37  in.parameters.disabledJoints);
38 
39  auto jointNames = simox::alg::get_keys(filtered);
40 
41  for (auto& [k, v] : filtered)
42  {
43  filtered[k] = 0.0;
44  }
45 
46  srv_.kinematicUnit->setJointVelocities(filtered);
47 
48  srv_.kinematicUnit->releaseJoints(jointNames);
49  return {::armarx::skills::TerminatedSkillStatus::Succeeded};
50  }
51 
53  MoveJointsWithVelocity::main(const SpecializedMainInput& in)
54  {
55  auto filtered = this->filterJointTargetValues(in.parameters.jointsTargetVelocities,
56  in.parameters.disabledJoints);
57 
58  auto jointNames = simox::alg::get_keys(filtered);
59 
60  // request joints
61  ARMARX_INFO << "Requesting joints";
62  try
63  {
64  srv_.kinematicUnit->requestJoints(jointNames);
65  }
66  catch (const armarx::KinematicUnitUnavailable& e)
67  {
68  ARMARX_IMPORTANT << "Failed to request joints. Terminating. Joints unavailable:"
69  << e.nodeOwners;
70  return MakeFailedResult();
71  }
72 
73  // move joints
74  ARMARX_INFO << "Moving joints with vel " << filtered;
75 
76  switchControlMode(filtered, eVelocityControl);
77 
78  moveJoints(filtered, in.parameters.duration);
79  return MakeSucceededResult();
80  }
81 
82  void
83  MoveJointsWithVelocity::switchControlMode(const NameValueMap& jointsTargetValues,
84  const ControlMode controlMode)
85  {
86  armarx::NameControlModeMap modeMap;
87  for (const auto& [jointName, _] : jointsTargetValues)
88  {
89  modeMap[jointName] = controlMode;
90  }
91  srv_.kinematicUnit->switchControlMode(modeMap);
92  }
93 
94  void
95  MoveJointsWithVelocity::moveJoints(const NameValueMap& jointsTargetVelocities,
97  {
98  srv_.kinematicUnit->setJointVelocities(jointsTargetVelocities);
99 
100  const Clock clock;
101  const Duration sleepTime = Duration::MilliSeconds(50);
102 
105  {
107  clock.waitFor(sleepTime);
108  }
109  }
110 
111 } // 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:183
Trajectory.h
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
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
armarx::skills::Skill::MakeFailedResult
static MainResult MakeFailedResult()
Definition: Skill.cpp:324
MoveJointsWithVelocity.h
armarx::skills::Skill::started
armarx::core::time::DateTime started
Definition: Skill.h:320
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
armarx::skills::Skill::ExitResult
A result struct for skill exit function.
Definition: Skill.h:55
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:91
armarx::control::skills::skills::MoveJointsWithVelocity::MoveJointsWithVelocity
MoveJointsWithVelocity(const Services &)
Definition: MoveJointsWithVelocity.cpp:8
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:174
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:17
armarx::skills::Skill::throwIfSkillShouldTerminate
void throwIfSkillShouldTerminate(const std::string &abortedMessage="")
Definition: Skill.cpp:291
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:28
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55