V-ART
dofmover.cpp
Go to the documentation of this file.
1 
5 #include "vart/dofmover.h"
6 #include "vart/interpolator.h"
7 #include "vart/dof.h"
8 
9 //#include <iostream>
10 using namespace std;
11 
16 unsigned int VART::DofMover::priority = 1;
17 
18 VART::DofMover::DofMover() : active (false)
19 {
20 }
21 
23  : targetPosition( dofMover.targetPosition )
24  , initialPosition( dofMover.initialPosition )
25  , initialTime( dofMover.initialTime )
26  , activationTime( dofMover.activationTime )
27  , finalTime( dofMover.finalTime )
28  , positionRange( dofMover.positionRange )
29  , timeRange( dofMover.timeRange )
30  , targetDofPtr( dofMover.targetDofPtr )
31  , active( false )
32 {
33 }
34 
35 // FixMe: Consider turning Initialize into the default constructor.
36 void VART::DofMover::Initialize(float iniTime, float finTime, float finPos)
37 // virtual method
38 {
39  initialTime = iniTime;
40  finalTime = finTime;
41  targetPosition = finPos;
42 }
43 
45 {
46  if ((goalTime > initialTime) && (goalTime < finalTime))
47  {
48  float interpolationIndex;
49  float goalPosition;
50 
51  if (!active)
52  { // Activate
53  initialPosition = targetDofPtr->GetCurrent();
54  active = true;
55  positionRange = targetPosition - initialPosition;
56  timeRange = finalTime - goalTime;
57  // Validade against minimum duration to avoid movements that are too fast.
58  if (timeRange < minimumDuration)
59  timeRange = minimumDuration;
60  activationTime = goalTime;
61  // Move to current position, so that lower priority movers do not take effect
62  targetDofPtr->MoveTo(initialPosition, priority);
63  }
64  else
65  {
66  // Really move
67  interpolationIndex = (goalTime - activationTime)/timeRange;
68  goalPosition = interpolatorPtr->GetValue(interpolationIndex,initialPosition,positionRange);
69  targetDofPtr->MoveTo(goalPosition, priority);
70  }
71  }
72  else
73  // If outside its time range, the dof mover could be deactivating.
74  active = false;
75 }
76 
77 void VART::DofMover::GetFinalTime(list<float>* resultPtr)
78 {
79  list<float>::iterator iter = resultPtr->begin();
80 
81  while ((iter != resultPtr->end()) && (*iter < finalTime))
82  ++iter;
83  if (!((iter != resultPtr->end()) && (*iter == finalTime)))
84  resultPtr->insert(iter, finalTime);
85 }
86 
87 ostream& VART::operator<<(ostream& output, const VART::DofMover& mover)
88 {
89  output << "initialTime=\"" << mover.initialTime
90  << "\" finalTime=\"" << mover.finalTime
91  << "\" finalPosition=\"" << mover.targetPosition << "\"";
92  return output;
93 }
Header file for V-ART class "Dof".
static bool cycle
Indicates whether the current action is cyclic.
Definition: dofmover.h:76
static float goalTime
Time of next snapshot, normalized to joint movement's duration.
Definition: dofmover.h:74
std::ostream & operator<<(std::ostream &output, const Joint::DofID &dofId)
static float minimumDuration
Minimum duration when computing motion paths.
Definition: dofmover.h:82
float finalTime
Normalized deactivation time.
Definition: dofmover.h:59
static const Interpolator * interpolatorPtr
Position interpolator.
Definition: dofmover.h:78
Controller for DOF movement.
Definition: dofmover.h:24
Interpolator representation.
Definition: interpolator.h:17
Header file for V-ART class "DofMover".
float initialTime
Time of predicted activation (normalized).
Definition: dofmover.h:55
void GetFinalTime(std::list< float > *resultPtr)
Adds the final time to the list.
Definition: dofmover.cpp:77
static unsigned int priority
Priority of active action.
Definition: dofmover.h:80
virtual void Move()
Changes target DOF.
Definition: dofmover.cpp:44
Header file for V-ART class "Interpolator".
DofMover()
Creates an unitialized DOF mover.
Definition: dofmover.cpp:18
virtual void Initialize(float iniTime, float finTime, float finPos)
Definition: dofmover.cpp:36
float targetPosition
Target position.
Definition: dofmover.h:51