MoveJointsToPosition.cpp
Go to the documentation of this file.
2
4
5namespace armarx::skills
6{
7 namespace
8 {
9 joint_control::arondto::MoveJointsToPositionAcceptedType
10 GetDefaultParameterization()
11 {
12 joint_control::arondto::MoveJointsToPositionAcceptedType ret;
13 ret.jointTargetTolerance = 0.05;
14 return ret;
15 }
16 } // namespace
17
18 SkillDescription MoveJointsToPosition::Description = skills::SkillDescription{
19 "MoveJointsToPosition",
20 "Move the joints to position",
21 {},
23 joint_control::arondto::MoveJointsToPositionAcceptedType::ToAronType(),
24 GetDefaultParameterization().toAron()};
25
30 PeriodicSimpleSpecializedSkill<joint_control::arondto::MoveJointsToPositionAcceptedType>(
32 armarx::core::time::Frequency::Hertz(10))
33 {
34 }
35
36 void
37 MoveJointsToPosition::reset()
38 {
39 already_running = false;
40 }
41
42 Skill::InitResult
43 MoveJointsToPosition::init(const SpecializedInitInput& in)
44 {
46 return {.status = TerminatedSkillStatus::Succeeded};
47 }
48
50 MoveJointsToPosition::step(const SpecializedMainInput& in)
51 {
52 auto robot = robotReader.queryState({in.parameters.robotName}, armem::Time::Now());
53 if (!robot)
54 {
55 ARMARX_WARNING << "Unable to get robot from robotstatememory. Abort.";
57 }
58
59 if ((armem::Time::Now() - robot->timestamp).toMilliSeconds() > 300)
60 {
61 ARMARX_WARNING << deactivateSpam(1) << "Robot from Memory is too old. Try again.";
63 }
64
65 std::map<std::string, float> filteredTargets;
66 auto currentValues = robot->jointMap;
67 for (const auto& [key, val] : in.parameters.targetJointMap)
68 {
69 if (const auto& it = currentValues.find(key); it != currentValues.end())
70 {
71 ARMARX_INFO << deactivateSpam(1) << "Current value of " << key << " is "
72 << it->second << " and it will be set to " << val;
73 filteredTargets.insert({key, val});
74 }
75 }
76
77 if (filteredTargets.size() == 0)
78 {
80 }
81
82 auto currentJointValueTolerance = in.parameters.jointTargetTolerance;
84 << "Joint target tolerance: " << currentJointValueTolerance;
85
86 auto currentMaxDelta = std::numeric_limits<float>::max();
87
88 robot = robotReader.queryState({in.parameters.robotName}, armem::Time::Now());
89
90 currentValues = robot->jointMap;
91 float maxDeltaTmp = 0;
92 for (const auto& [key, value] : filteredTargets)
93 {
94 const float delta = fabs((value - currentValues.at(key)));
95 maxDeltaTmp = std::max(delta, maxDeltaTmp);
96 }
97 currentMaxDelta = maxDeltaTmp;
98
99 ARMARX_IMPORTANT << deactivateSpam(1) << "Current joint values are: \n" << currentValues;
100 ARMARX_IMPORTANT << deactivateSpam(1) << "MaxDelta is: " << currentMaxDelta;
101
102 if (currentMaxDelta <= currentJointValueTolerance)
103 {
105 }
106
107 if (!already_running)
108 {
109 already_running = true;
110
111 NameControlModeMap controlModes;
112 for (const auto& p : filteredTargets)
113 {
114 controlModes[p.first] = ePositionControl;
115 }
116 context.kinematicUnitPrx->switchControlMode(controlModes);
117
118 context.kinematicUnitPrx->setJointAngles(filteredTargets);
119 }
121 }
122
124 MoveJointsToPosition::exit(const SpecializedExitInput& in)
125 {
126 std::vector<std::string> joints;
127 std::for_each(in.parameters.targetJointMap.begin(),
128 in.parameters.targetJointMap.end(),
129 [&joints](const std::pair<std::string, float>& p)
130 { joints.push_back(p.first); });
131
132 stopJointMovement(joints);
133
134 return {.status = TerminatedSkillStatus::Succeeded};
135 }
136} // namespace armarx::skills
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
The memory name system (MNS) client.
virtual void connect(armem::client::MemoryNameSystem &memoryNameSystem)
static DateTime Now()
Definition DateTime.cpp:51
Represents a frequency.
Definition Frequency.h:17
JointControlSkill(armem::client::MemoryNameSystem &mns, JointControlSkillContext &c)
JointControlSkillContext & context
TerminatedSkillStatus stopJointMovement(const std::vector< std::string > &joints)
armem::client::MemoryNameSystem & mns
MoveJointsToPosition(armem::client::MemoryNameSystem &mns, JointControlSkillContext &context)
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
A result struct for skill exit function.
Definition Skill.h:69
armem::robot_state::VirtualRobotReader robotReader