ocra-recipes
Doxygen documentation for the ocra-recipes repository
TaskState.cpp
Go to the documentation of this file.
2 
3 using namespace ocra;
4 
6 : containsPosition(false)
7 , containsVelocity(false)
8 , containsAcceleration(false)
9 , containsQ(false)
10 , containsQd(false)
11 , containsQdd(false)
12 , containsTorque(false)
13 , containsWrench(false)
14 {
15  position = Eigen::Displacementd::Identity();
16  velocity = Eigen::Twistd(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
17  acceleration = Eigen::Twistd(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
18 
19  q = Eigen::VectorXd::Zero(1);
20  qd = Eigen::VectorXd::Zero(1);
21  qdd = Eigen::VectorXd::Zero(1);
22  torque = Eigen::VectorXd::Zero(1);
23 
24  wrench = Eigen::Wrenchd(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
25 }
27 {
28  // Do nothing
29 }
30 
31 Eigen::Displacementd TaskState::getPosition() const
32 {
33  return this->position;
34 }
35 
36 
37 Eigen::Twistd TaskState::getVelocity() const
38 {
39  return this->velocity;
40 }
41 
42 
43 Eigen::Twistd TaskState::getAcceleration() const
44 {
45  return this->acceleration;
46 }
47 
48 
49 Eigen::VectorXd TaskState::getQ() const
50 {
51  return this->q;
52 }
53 
54 
55 Eigen::VectorXd TaskState::getQd() const
56 {
57  return this->qd;
58 }
59 
60 
61 Eigen::VectorXd TaskState::getQdd() const
62 {
63  return this->qdd;
64 }
65 
66 
67 Eigen::VectorXd TaskState::getTorque() const
68 {
69  return this->torque;
70 }
71 
72 
73 Eigen::Wrenchd TaskState::getWrench() const
74 {
75  return this->wrench;
76 }
77 
78 
79 void TaskState::setPosition(const Eigen::Displacementd& newPosition)
80 {
81  this->position = newPosition;
82  this->containsPosition = true;
83 }
84 
85 
86 void TaskState::setVelocity(const Eigen::Twistd& newVelocity)
87 {
88  this->velocity = newVelocity;
89  this->containsVelocity = true;
90 }
91 
92 
93 void TaskState::setAcceleration(const Eigen::Twistd& newAcceleration)
94 {
95  this->acceleration = newAcceleration;
96  this->containsAcceleration = true;
97 }
98 
99 
100 void TaskState::setQ(const Eigen::VectorXd& newQ)
101 {
102  this->q = newQ;
103  this->containsQ = true;
104 }
105 
106 
107 void TaskState::setQd(const Eigen::VectorXd& newQd)
108 {
109  this->qd = newQd;
110  this->containsQd = true;
111 }
112 
113 
114 void TaskState::setQdd(const Eigen::VectorXd& newQdd)
115 {
116  this->qdd = newQdd;
117  this->containsQdd = true;
118 }
119 
120 
121 void TaskState::setTorque(const Eigen::VectorXd& newTorque)
122 {
123  this->torque = newTorque;
124  this->containsTorque = true;
125 }
126 
127 
128 void TaskState::setWrench(const Eigen::Wrenchd& newWrench)
129 {
130  this->wrench = newWrench;
131  this->containsWrench = true;
132 }
133 
135 {
136  return this->containsPosition;
137 }
138 
140 {
141  return this->containsVelocity;
142 }
143 
145 {
146  return this->containsAcceleration;
147 }
148 
149 bool TaskState::hasQ() const
150 {
151  return this->containsQ;
152 }
153 
154 bool TaskState::hasQd() const
155 {
156  return this->containsQd;
157 }
158 
159 bool TaskState::hasQdd() const
160 {
161  return this->containsQdd;
162 }
163 
165 {
166  return this->containsTorque;
167 }
168 
170 {
171  return this->containsWrench;
172 }
173 
174 bool TaskState::extractFromBottle(const yarp::os::Bottle& bottle, int& sizeOfState)
175 {
176  int i = 0;
177  if (bottle.get(i).asInt() == TASK_STATE_BOTTLE)
178  {
179  this->containsPosition = bottle.get(++i).asBool();
180  this->containsVelocity = bottle.get(++i).asBool();
181  this->containsAcceleration = bottle.get(++i).asBool();
182  this->containsQ = bottle.get(++i).asBool();
183  this->containsQd = bottle.get(++i).asBool();
184  this->containsQdd = bottle.get(++i).asBool();
185  this->containsTorque = bottle.get(++i).asBool();
186  this->containsWrench = bottle.get(++i).asBool();
187  int indexesToSkip;
188 
189 
190  if (this->hasPosition()) {
191  this->setPosition( util::pourBottleIntoDisplacementd(util::trimBottle(bottle, i+1), indexesToSkip) );
192  i += indexesToSkip;
193  }
194  if (this->hasVelocity()) {
195  this->setVelocity( util::pourBottleIntoTwistd(util::trimBottle(bottle, i+1), indexesToSkip) );
196  i += indexesToSkip;
197  }
198  if (this->hasAcceleration()) {
199  this->setAcceleration( util::pourBottleIntoTwistd(util::trimBottle(bottle, i+1), indexesToSkip) );
200  i += indexesToSkip;
201  }
202  if (this->hasQ()) {
203  this->setQ( util::pourBottleIntoEigenVector(util::trimBottle(bottle, i+1), indexesToSkip) );
204  i += indexesToSkip;
205  }
206  if (this->hasQd()) {
207  this->setQd( util::pourBottleIntoEigenVector(util::trimBottle(bottle, i+1), indexesToSkip) );
208  i += indexesToSkip;
209  }
210  if (this->hasQdd()) {
211  this->setQdd( util::pourBottleIntoEigenVector(util::trimBottle(bottle, i+1), indexesToSkip) );
212  i += indexesToSkip;
213  }
214  if (this->hasTorque()) {
215  this->setTorque( util::pourBottleIntoEigenVector(util::trimBottle(bottle, i+1), indexesToSkip) );
216  i += indexesToSkip;
217  }
218  if (this->hasWrench()) {
219  this->setWrench( util::pourBottleIntoWrenchd(util::trimBottle(bottle, i+1), indexesToSkip) );
220  i += indexesToSkip;
221  }
222 
223  sizeOfState = i;
224  return true;
225  }
226  return false;
227 
228 }
229 
230 void TaskState::putIntoBottle(yarp::os::Bottle& bottle) const
231 {
232  bottle.addInt(TASK_STATE_BOTTLE);
233 
234  bottle.addInt(this->hasPosition());
235  bottle.addInt(this->hasVelocity());
236  bottle.addInt(this->hasAcceleration());
237  bottle.addInt(this->hasQ());
238  bottle.addInt(this->hasQd());
239  bottle.addInt(this->hasQdd());
240  bottle.addInt(this->hasTorque());
241  bottle.addInt(this->hasWrench());
242 
243  if (this->hasPosition()) {
245  }
246  if (this->hasVelocity()) {
247  util::pourTwistdIntoBottle(this->getVelocity(), bottle);
248  }
249  if (this->hasAcceleration()) {
251  }
252  if (this->hasQ()) {
253  util::pourEigenVectorIntoBottle(this->getQ(), bottle);
254  }
255  if (this->hasQd()) {
256  util::pourEigenVectorIntoBottle(this->getQd(), bottle);
257  }
258  if (this->hasQdd()) {
259  util::pourEigenVectorIntoBottle(this->getQdd(), bottle);
260  }
261  if (this->hasTorque()) {
263  }
264  if (this->hasWrench()) {
265  util::pourWrenchdIntoBottle(this->getWrench(), bottle);
266  }
267 
268 }
virtual ~TaskState()
Definition: TaskState.cpp:26
void setPosition(const Eigen::Displacementd &newPosition)
Definition: TaskState.cpp:79
Eigen::Wrenchd pourBottleIntoWrenchd(yarp::os::Bottle bottle, int &indexesToSkip)
Definition: YarpUtilities.h:78
void setTorque(const Eigen::VectorXd &newTorque)
Definition: TaskState.cpp:121
bool hasVelocity() const
Definition: TaskState.cpp:139
void setAcceleration(const Eigen::Twistd &newAcceleration)
Definition: TaskState.cpp:93
yarp::os::Bottle trimBottle(const yarp::os::Bottle &bottle, int startIndex, int endIndex=-1)
void pourDisplacementdIntoBottle(const Eigen::Displacementd &disp, yarp::os::Bottle &bottle)
bool hasPosition() const
Definition: TaskState.cpp:134
bool hasQ() const
Definition: TaskState.cpp:149
Eigen::VectorXd getQdd() const
Definition: TaskState.cpp:61
void setVelocity(const Eigen::Twistd &newVelocity)
Definition: TaskState.cpp:86
void putIntoBottle(yarp::os::Bottle &bottle) const
Definition: TaskState.cpp:230
bool hasQd() const
Definition: TaskState.cpp:154
bool extractFromBottle(const yarp::os::Bottle &bottle, int &sizeOfOptions)
Definition: TaskState.cpp:174
Eigen::VectorXd getQd() const
Definition: TaskState.cpp:55
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
bool hasAcceleration() const
Definition: TaskState.cpp:144
Eigen::VectorXd getQ() const
Definition: TaskState.cpp:49
bool hasTorque() const
Definition: TaskState.cpp:164
Eigen::Twistd pourBottleIntoTwistd(yarp::os::Bottle bottle, int &indexesToSkip)
Definition: YarpUtilities.h:64
void setQd(const Eigen::VectorXd &newQd)
Definition: TaskState.cpp:107
void pourTwistdIntoBottle(const Eigen::Twistd &twist, yarp::os::Bottle &bottle)
Eigen::VectorXd getTorque() const
Definition: TaskState.cpp:67
bool hasWrench() const
Definition: TaskState.cpp:169
void setQdd(const Eigen::VectorXd &newQdd)
Definition: TaskState.cpp:114
Eigen::Wrenchd getWrench() const
Definition: TaskState.cpp:73
void pourEigenVectorIntoBottle(const Eigen::VectorXd &vec, yarp::os::Bottle &bottle)
bool hasQdd() const
Definition: TaskState.cpp:159
void setWrench(const Eigen::Wrenchd &newWrench)
Definition: TaskState.cpp:128
Eigen::Twistd getAcceleration() const
Definition: TaskState.cpp:43
void setQ(const Eigen::VectorXd &newQ)
Definition: TaskState.cpp:100
Eigen::Displacementd getPosition() const
Definition: TaskState.cpp:31
Eigen::Twistd getVelocity() const
Definition: TaskState.cpp:37
Eigen::VectorXd pourBottleIntoEigenVector(yarp::os::Bottle bottle, int &indexesToSkip)
Definition: YarpUtilities.h:27
void pourWrenchdIntoBottle(const Eigen::Wrenchd &wrench, yarp::os::Bottle &bottle)
Eigen::Displacementd pourBottleIntoDisplacementd(yarp::os::Bottle bottle, int &indexesToSkip)
Definition: YarpUtilities.h:49