25 #include <dmp/io/MMMConverter.h>
26 #include <Ice/ObjectAdapter.h>
33 DMP::Vec<DMP::DMPState> res;
34 res.resize(state.size());
36 for (
size_t i = 0; i < state.size(); i++)
38 res[i].pos = state[i].pos;
39 res[i].vel = state[i].vel;
48 res.resize(state.size());
49 for (
size_t i = 0; i < state.size(); i++)
51 res[i].push_back(state[i].pos);
52 res[i].push_back(state[i].vel);
58 armarx::cStateVec
getcStateVec(
const DMP::Vec<DMP::DMPState>& dmpstate)
61 sv.resize(dmpstate.size());
63 for (
size_t i = 0; i < dmpstate.size(); i++)
65 sv[i].pos = dmpstate[i].pos;
66 sv[i].vel = dmpstate[i].vel;
75 sv.resize(dmpstate.size());
77 for (
size_t i = 0; i < dmpstate.size(); i++)
79 sv[i].pos = dmpstate[i].at(0);
80 sv[i].vel = dmpstate[i].at(1);
101 ARMARX_WARNING <<
"Canonical value is not specified. It will be set 1.0.";
106 if (currentDMPState.size() == 0)
108 ARMARX_ERROR <<
"The current state is not available. Please specify current state with setDMPState().";
115 <<
" ctime: " <<
ctime
117 double temporalFactor =
dmp->getTemporalFactor();
129 armarx::nStateValues
DMPInstance::calcNextState(
double t,
const Ice::DoubleSeq& goal,
double currentT,
const Vec2D& currentStates,
const Ice::DoubleSeq& canonicalValues,
double temporalFactor, const ::Ice::Current&)
137 if (currentStates.size() == 0)
139 ARMARX_ERROR <<
"Current DMP State has to be specified";
144 if (goal.size() == 0)
151 DMP::DVec2d curStates;
153 for (std::size_t i = 0; i < currentStates.size() ; ++i)
155 curStates.emplace_back(
DMP::DVec(currentStates.at(i)));
160 DMP::DVec2d tmp_result =
dmp->calculateTrajectoryPointBase(t, goal_v, currentT, curStates, canValues, temporalFactor);
162 Ice::DoubleSeq tmpCanVal;
163 for (std::size_t i = 0; i < canValues.size(); i++)
165 tmpCanVal.emplace_back(canValues.at(i));
170 result.canonicalValues = tmpCanVal;
173 for (std::size_t i = 0; i < tmp_result.size() ; ++i)
175 ::Ice::DoubleSeq dblseq = ::Ice::DoubleSeq(tmp_result.at(i));
177 nState.emplace_back(dblseq);
180 result.nextState = nState;
197 std::map<std::string, paraType >
configMap;
198 for (::std::map< ::std::string, ::Ice::DoubleSeq>::const_iterator it = conf.begin(); it != conf.end(); ++it)
201 dmp->setConfiguration(it->first, it->second);
209 if (paraIDs.size() != paraVals.size())
211 ARMARX_WARNING <<
"ID list and value list have different sizes, which may cause error.";
215 for (
size_t i = 0; i < paraIDs.size(); i++)
223 configs[paraIDs[i]] = paraVals[i];
296 return dmp->getAmpl(dim);
301 return dmp->getTemporalFactor();
306 return dmp->_getPerturbationForce(dim, canVal[0]);
314 for (
size_t i = 0; i < goals.size(); ++i)
316 res.push_back(goals.at(i));
326 Ice::DoubleSeq trajGoal;
327 for (
size_t i = 0; i <
trajs[0].dim(); i++)
329 trajGoal.push_back(
trajs[0].rbegin()->getPosition(i));
338 cStateVec startState;
340 for (
size_t i = 0; i <
trajs[0].dim(); i++)
343 state.pos =
trajs[0].begin()->getPosition(i);
344 state.vel =
trajs[0].begin()->getDeriv(i, 1);
345 state.acc =
trajs[0].begin()->getDeriv(i, 2);
347 startState.push_back(state);
355 std::string ext = file.rfind(
".") == file.npos ? file : file.substr(file.rfind(
".") + 1);
363 else if (ext ==
"csv")
365 DMP::SampledTrajectoryV2 traj;
366 traj.readFromCSVFile(file);
367 traj.gaussianFilter(0.01);
369 double startTime = 0;
370 double endTime = times;
374 trajs.push_back(traj);
375 dmp->setDim(traj.dim());
380 else if (ext ==
"vsg")
398 const ::Ice::DoubleSeq& goal,
399 const cStateVec& states,
400 const ::Ice::DoubleSeq& canonicalValues,
double temporalFactor,
const Ice::Current&)
409 Vec2D resultingTrajectory;
411 cStateVec nextStates = states;
412 while (
ctime < endTime)
415 ::Ice::DoubleSeq positions;
417 positions.push_back(
ctime);
418 for (
unsigned int d = 0; d < states.size(); d++)
420 positions.push_back(nextStates.at(d).pos);
423 resultingTrajectory.push_back(positions);
428 return resultingTrajectory;
434 const Ice::DoubleSeq& goal,
435 const Vec2D& initStates,
436 const Ice::DoubleSeq& canonicalValues,
double temporalFactor,
const Ice::Current&)
440 if (timestampsLocal.size() == 0)
445 DMP::DVec::const_iterator it = timestamps.begin();
446 Vec2D previousState = initStates;
447 Vec2D resultingTrajectory;
451 double prevTimestamp = *it;
455 for (; it != timestamps.end(); it++)
457 nStateValues nState =
calcNextState(*it, goal, prevTimestamp, previousState, canValues, temporalFactor);
458 canValues = nState.canonicalValues;
459 previousState = nState.nextState;
462 ::Ice::DoubleSeq positions;
463 for (
unsigned int d = 0; d < previousState.size(); d++)
465 positions.push_back(previousState.at(d)[0]);
467 resultingTrajectory.push_back(positions);
470 return resultingTrajectory;
474 const Vec2D& initStates,
475 const Ice::DoubleSeq& canonicalValues,
const Ice::Current&)