31 using namespace PlatformGroup;
33 #define STATE_POSITION 0
34 #define STATE_VELOCITY 1
36 #define MAX_TRANSLATION_ACCEL 0.5 // m/s²
37 #define MAX_ROTATION_ACCEL 0.75 // rad/s²
39 #define FACTOR_BETWEEN_TRANS_AND_ROT 500.0
47 double length = t->getLength(0);
49 double timelength = t->getTimeLength();
51 auto timestamps = t->getTimestamps();
53 Ice::DoubleSeq newTimestamps;
54 newTimestamps.push_back(0);
55 for (
size_t var = 0; var < timestamps.size() - 1; ++var)
57 double tBefore = timestamps.at(var);
58 double tAfter = (timestamps.at(var + 1));
60 double partLength = t->getLength(0, tBefore, tAfter);
61 double lengthPortion = partLength / length;
63 newTimestamps.push_back(*newTimestamps.rbegin() + timelength * lengthPortion);
67 for (
size_t d = 0; d < t->dim(); ++d)
69 newTraj->addDimension(t->getDimensionData(d), newTimestamps, t->getDimensionName(d));
78 double totalTime = 0.0;
79 auto timestamps = t->getTimestamps();
80 auto dimNames = t->getDimensionNames();
82 for (
size_t var = 0; var < timestamps.size() - 1; ++var)
84 double xLength = t->getLength(std::find(dimNames.begin(), dimNames.end(),
"x") - dimNames.begin(), 0, timestamps.at(var), timestamps.at(var + 1)) / 1000;
86 double yLength = t->getLength(std::find(dimNames.begin(), dimNames.end(),
"y") - dimNames.begin(), 0, timestamps.at(var), timestamps.at(var + 1)) / 1000;
88 double alphaLength = t->getLength(std::find(dimNames.begin(), dimNames.end(),
"alpha") - dimNames.begin(), 0, timestamps.at(var), timestamps.at(var + 1));
91 double xyLength =
std::sqrt(fabs(xLength * xLength + yLength * yLength));
98 if (xyLength <= 2 * sAcc)
111 double dtime = (xyTime > rotTime) ? xyTime : rotTime;
115 t = t->normalize(0.0, totalTime);
123 Ice::DoubleSeq factors = {1.0, 1.0, factor};
125 t->scaleValue(factors);
133 auto dimNames = platformTraj->getDimensionNames();
134 if (dimNames.at(0) !=
"x" ||
135 dimNames.at(1) !=
"y" ||
136 dimNames.at(2) !=
"alpha")
138 ARMARX_WARNING <<
"Trajectory misses at least one of the following needed dimensions: 'x', 'y' and 'alpha'.";
146 PlatformUnitInterfacePrx platformUnit =
c->platformUnitPrx;
148 auto dimNames = platformTraj->getDimensionNames();
149 float maxTransVel = in.getMaxTranslationVelocity();
150 float maxRotVel = in.getMaxRotationVelocity();
152 if (in.getBalanceTrajectory())
182 double currentTime = 0.0;
183 bool finalPoseReached =
false;
184 int cycleTime = in.getCycleTimeMS();
187 c->debugDrawer->removeLayer(
"ActualRobotPath");
192 while (!isRunningTaskStopped())
197 if (currentTime > platformTraj->getTimeLength())
199 currentTime = platformTraj->getTimeLength();
200 finalPoseReached =
true;
203 float posx = posXRef->getDataField()->getFloat();
204 float posy = posYRef->getDataField()->getFloat();
205 float ori = oriRef->getDataField()->getFloat();
214 std::vector<Ice::DoubleSeq> allStates = platformTraj->getAllStates(currentTime, 1);
215 for (
size_t i = 0; i < platformTraj->dim(); ++i)
220 Eigen::Vector3f pos {posx, posy, 0.0f};
221 Eigen::Vector3f targetPos {targetValues[
"x"], targetValues[
"y"], 0.0f};
223 pidTrans.
update(pos, targetPos);
224 pidRot.
update(ori, targetValues[
"alpha"]);
228 m = Eigen::AngleAxisf(ori, Eigen::Vector3f::UnitZ());
229 Eigen::Vector3f localVel = m.inverse() * globalNewTransVel;
232 ARMARX_INFO <<
"New values: x: " << localVel[0] <<
" , y= " << localVel[1] <<
" , alpha= " << newRotVel;
234 platformUnit->move(localVel[0],
238 if (finalPoseReached && fabs(pidTrans.
previousError) < in.getPositionalAccuracy() && fabs(pidRot.
previousError) < in.getOrientationalAccuracy())
240 disableRunFunction();
241 platformUnit->move(0, 0, 0);
256 PlatformUnitInterfacePrx platformUnit =
c->platformUnitPrx;
257 platformUnit->move(0.0, 0.0, 0.0);