MoveJointPlatformTrajectory.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotSkillTemplates::MotionAndPlatformControlGroup
17 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * @date 2016
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <chrono>
26
29
31
32#include <RobotSkillTemplates/statecharts/MotionAndPlatformControlGroup/MoveJointPlatformTrajectory.generated.h>
33
34#include "MotionAndPlatformControlGroupStatechartContext.generated.h"
35
37{
39 public MoveJointPlatformTrajectoryGeneratedBase<MoveJointPlatformTrajectory>
40 {
41 public:
43 std::pair<DataFieldIdentifierBaseList, DataFieldIdentifierBaseList>;
44 using TimedVariantBaseLists = std::pair<TimedVariantBaseList, TimedVariantBaseList>;
45
48 MoveJointPlatformTrajectoryGeneratedBase<MoveJointPlatformTrajectory>(stateData)
49 {
50 }
51
52 // inherited from StateBase
53 void onEnter() override;
54 void run() override;
55 void onBreak() override;
56 void onExit() override;
57 void waitForDone(bool stopAtCurrentPos);
58
59 // static functions for AbstractFactory Method
61 static SubClassRegistry Registry;
62
64 getDataFieldIdentifiers(const std::string& channelName)
65 {
67 datafields.first.reserve(3);
68 datafields.second.reserve(jointNames.size() - 3);
69 {
70 const std::string platformObserverName =
71 context->getProperty<std::string>("PlatformUnitObserverName").getValue();
72 if (channelName == "jointangles")
73 {
74 datafields.first.emplace_back(
75 new DataFieldIdentifier{platformObserverName, "platformPose", "positionX"});
76 datafields.first.emplace_back(
77 new DataFieldIdentifier{platformObserverName, "platformPose", "positionY"});
78 datafields.first.emplace_back(
79 new DataFieldIdentifier{platformObserverName, "platformPose", "rotation"});
80 }
81 else
82 {
83 datafields.first.emplace_back(new DataFieldIdentifier{
84 platformObserverName, "platformVelocity", "velocityX"});
85 datafields.first.emplace_back(new DataFieldIdentifier{
86 platformObserverName, "platformVelocity", "velocityY"});
87 datafields.first.emplace_back(new DataFieldIdentifier{
88 platformObserverName, "platformVelocity", "velocityRotation"});
89 }
90 };
91 const std::string observerName =
92 context->getProperty<std::string>("KinematicUnitObserverName").getValue();
93 for (size_t i = 3; i < jointNames.size(); ++i)
94 {
95 datafields.second.emplace_back(
96 new DataFieldIdentifier{observerName, channelName, jointNames.at(i)});
97 }
98 return datafields;
99 }
100
101 void ctrlInterpol();
102 void ctrlNative();
103
104 //helper
105 bool
107 {
108 return currentCfgIt == lastCfgIt;
109 }
110
111 bool
113 {
114 return currentCfgIt == t->end();
115 }
116
117 void
119 {
120 cachedValues.first =
121 context->getPlatformUnitObserver()->getDataFields(datafieldsValues.first);
122 cachedValues.second =
123 context->getKinematicUnitObserver()->getDataFields(datafieldsValues.second);
124 }
125
126 void
128 {
129 cachedVelocities.first =
130 context->getPlatformUnitObserver()->getDataFields(datafieldsVelocities.first);
131 cachedVelocities.second =
132 context->getKinematicUnitObserver()->getDataFields(datafieldsVelocities.second);
133 }
134
135 static float
136 getFromList(const TimedVariantBaseLists& lists, std::size_t i)
137 {
138 if (i < 3)
139 {
140 return lists.first.at(i)->getFloat();
141 }
142 return lists.second.at(i - 3)->getFloat();
143 }
144
145 float getValue(std::size_t i) const;
146 float getVelocity(std::size_t i) const;
147
148 void
149 setVelocity(NameValueMap& vels)
150 {
151 const auto x = vels.at("x");
152 const auto y = vels.at("y");
153 const auto a = vels.at("alpha");
154 context->getPlatformUnit()->move(x, y, a);
155 ARMARX_INFO << "VelocitiesPlatform: x= " << x << " y=" << y << " alpha=" << a;
156 vels.erase("x");
157 vels.erase("y");
158 vels.erase("alpha");
160 {
161 vels["x"] = x;
162 vels["y"] = y;
163 vels["alpha"] = a;
164 };
165 context->getKinematicUnit()->setJointVelocities(vels);
166 }
167
168 void
169 setValues(NameValueMap& values)
170 {
171 const auto x = values.at("x");
172 const auto y = values.at("y");
173 const auto a = values.at("alpha");
174 context->getPlatformUnit()->moveTo(
176 values.erase("x");
177 values.erase("y");
178 values.erase("alpha");
180 {
181 values["x"] = x;
182 values["y"] = y;
183 values["alpha"] = a;
184 };
185 context->getKinematicUnit()->setJointAngles(values);
186 }
187
188 void
189 setMaxVelocity(NameValueMap& vels)
190 {
191 const auto x = vels.at("x");
192 const auto y = vels.at("y");
193 const auto a = vels.at("alpha");
194 context->getPlatformUnit()->setMaxVelocities((x + y) / 2.0, a);
195 vels.erase("x");
196 vels.erase("y");
197 vels.erase("alpha");
199 {
200 vels["x"] = x;
201 vels["y"] = y;
202 vels["alpha"] = a;
203 };
204 context->getKinematicUnit()->setJointVelocities(vels);
205 }
206
207 void
208 setControlMode(ControlMode mode)
209 {
210 NameControlModeMap controlModes;
211 for (size_t i = 3; i < jointNames.size(); i++)
212 {
213 controlModes[jointNames.at(i)] = mode;
214 }
215 context->getKinematicUnit()->switchControlMode(controlModes);
216 }
217
218 bool
220 {
221 return jointNames.size() >= 3 && jointNames.at(0) == "x" && jointNames.at(1) == "y" &&
222 jointNames.at(2) == "alpha";
223 }
224
225 float
226 getMaxVel(std::size_t joint) const
227 {
228 return (joint < jointMaxSpeeds.size() ? jointMaxSpeeds.at(joint)
229 : in.getJointMaxSpeed());
230 }
231
232 float
233 getMaxAcc(std::size_t joint) const
234 {
235 return (joint < maxAccs.size() ? maxAccs.at(joint) : in.getJointMaxAccel());
236 }
237
238 float
239 getTargetTolerance(std::size_t i) const
240 {
242 }
243
244 float
245 getConfigChangeTolerance(std::size_t i) const
246 {
247 if (doingLastConfig())
248 {
249 return getTargetTolerance(i);
250 }
251 return i < 2 ? in.getNextConfigTranslationTolerance() : in.getNextConfigTolerance();
252 }
253
254 static int sign(double val);
255
256 // DO NOT INSERT ANY CLASS MEMBERS,
257 // use stateparameters instead,
258 // if classmember are neccessary nonetheless, reset them in onEnter
260 std::vector<std::string> jointNames;
261 std::vector<float> maxAccs;
262 std::vector<float> jointMaxSpeeds;
263 MotionAndPlatformControlGroupStatechartContext* context;
264
267
270
271 const std::chrono::milliseconds period{10};
272 const float secondsPerPeriod = static_cast<float>(period.count()) / 1000.f;
275 typename Trajectory::ordered_view::const_iterator lastCfgIt;
276 typename Trajectory::ordered_view::const_iterator currentCfgIt;
277
278 ConditionIdentifier targetReachedCondition;
279 ActionEventIdentifier timeoutEvent;
280 };
281} // namespace armarx::MotionAndPlatformControlGroup
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
std::pair< TimedVariantBaseList, TimedVariantBaseList > TimedVariantBaseLists
std::pair< DataFieldIdentifierBaseList, DataFieldIdentifierBaseList > DataFieldIdentifierBaseLists
DataFieldIdentifierBaseLists getDataFieldIdentifiers(const std::string &channelName)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
static float getFromList(const TimedVariantBaseLists &lists, std::size_t i)
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ON_SCOPE_EXIT
Executes given code when the enclosing scope is left.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Trajectory > TrajectoryPtr
Definition Trajectory.h:52
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64