1 #ifndef YARP_UTILITIES_H 2 #define YARP_UTILITIES_H 8 #include <yarp/os/Bottle.h> 18 int nVals = bottle.get(0).asInt();
19 std::vector<double> returnVector(nVals);
20 for (
auto i = 0; i < nVals; ++i) {
21 returnVector[i] = bottle.tail().get(i).asDouble();
23 indexesToSkip = nVals + 1;
29 int nVals = bottle.get(0).asInt();
30 Eigen::VectorXd returnVector(nVals);
31 for (
auto i = 0; i < nVals; ++i) {
32 returnVector(i) = bottle.tail().get(i).asDouble();
34 indexesToSkip = nVals + 1;
40 int nVals = bottle.get(0).asInt();
41 Eigen::VectorXi returnVector(nVals);
42 for (
auto i = 0; i < nVals; ++i) {
43 returnVector(i) = bottle.tail().get(i).asInt();
45 indexesToSkip = nVals + 1;
51 int nVals = bottle.get(0).asInt();
52 double x = bottle.get(1).asDouble();
53 double y = bottle.get(2).asDouble();
54 double z = bottle.get(3).asDouble();
55 double qw = bottle.get(4).asDouble();
56 double qx = bottle.get(5).asDouble();
57 double qy = bottle.get(6).asDouble();
58 double qz = bottle.get(7).asDouble();
59 Eigen::Displacementd disp(x,y,z,qw,qx,qy,qz);
60 indexesToSkip = nVals + 1;
66 int nVals = bottle.get(0).asInt();
67 double rx = bottle.get(1).asDouble();
68 double ry = bottle.get(2).asDouble();
69 double rz = bottle.get(3).asDouble();
70 double vx = bottle.get(4).asDouble();
71 double vy = bottle.get(5).asDouble();
72 double vz = bottle.get(6).asDouble();
73 Eigen::Twistd twist(rx,ry,rz,vx,vy,vz);
74 indexesToSkip = nVals + 1;
80 int nVals = bottle.get(0).asInt();
81 double tx = bottle.get(1).asDouble();
82 double ty = bottle.get(2).asDouble();
83 double tz = bottle.get(3).asDouble();
84 double fx = bottle.get(4).asDouble();
85 double fy = bottle.get(5).asDouble();
86 double fz = bottle.get(6).asDouble();
87 Eigen::Wrenchd wrench(tx,ty,tz,fx,fy,fz);
88 indexesToSkip = nVals + 1;
94 int nRows = bottle.get(0).asInt();
95 int nCols = bottle.get(1).asInt();
96 Eigen::MatrixXd returnMatrix(nRows,nCols);
99 for (
auto i = 0; i < nRows; ++i) {
100 for (
auto j = 0; j < nCols; ++j) {
101 returnMatrix(i,j) = bottle.get(startIndex).asDouble();
105 indexesToSkip = nRows + nCols + 1;
112 bottle.addInt(vec.size());
113 for (
auto val : vec) {
114 bottle.addDouble(val);
124 bottle.addInt(vec.size());
125 for (
auto i=0; i<vec.size(); ++i) {
126 bottle.addDouble(vec(i));
136 bottle.addInt(vec.size());
137 for (
auto i=0; i<vec.size(); ++i) {
138 bottle.addInt(vec(i));
148 bottle.addInt(mat.rows());
149 bottle.addInt(mat.cols());
150 for (
auto i=0; i<mat.rows(); ++i) {
151 for (
auto j=0; j<mat.cols(); ++j) {
152 bottle.addDouble(mat(i,j));
162 const int DISPLACEMENT_VECTOR_SIZE = 7;
163 bottle.addInt(DISPLACEMENT_VECTOR_SIZE);
165 bottle.addDouble(disp.x());
166 bottle.addDouble(disp.y());
167 bottle.addDouble(disp.z());
168 bottle.addDouble(disp.qw());
169 bottle.addDouble(disp.qx());
170 bottle.addDouble(disp.qy());
171 bottle.addDouble(disp.qz());
177 const int TWIST_VECTOR_SIZE = 6;
178 bottle.addInt(TWIST_VECTOR_SIZE);
180 double rx = twist(0);
181 double ry = twist(1);
182 double rz = twist(2);
183 double vx = twist(3);
184 double vy = twist(4);
185 double vz = twist(5);
187 bottle.addDouble(rx);
188 bottle.addDouble(ry);
189 bottle.addDouble(rz);
190 bottle.addDouble(vx);
191 bottle.addDouble(vy);
192 bottle.addDouble(vz);
197 const int WRENCH_VECTOR_SIZE = 6;
198 bottle.addInt(WRENCH_VECTOR_SIZE);
200 bottle.addDouble(wrench.tx());
201 bottle.addDouble(wrench.ty());
202 bottle.addDouble(wrench.tz());
203 bottle.addDouble(wrench.fx());
204 bottle.addDouble(wrench.fy());
205 bottle.addDouble(wrench.fz());
208 inline yarp::os::Bottle
trimBottle(
const yarp::os::Bottle& bottle,
int startIndex,
int endIndex=-1)
210 int btlSize = bottle.size();
211 int lastIndex = btlSize - 1;
212 int trimFrom, trimTo;
218 trimTo = (endIndex <= btlSize) ? endIndex : btlSize;
221 trimFrom = (startIndex >= 0) ? startIndex : 0;
222 trimFrom = ( startIndex < (trimTo-2) ) ? startIndex : (trimTo-2);
224 yarp::os::Bottle tmpBtl;
225 while(trimFrom<trimTo)
227 tmpBtl.add(bottle.get(trimFrom));
236 #endif // YARP_UTILITIES_H void pourEigenVectorXiIntoBottle(const Eigen::VectorXi &vec, yarp::os::Bottle &bottle)
Eigen::Wrenchd pourBottleIntoWrenchd(yarp::os::Bottle bottle, int &indexesToSkip)
std::vector< double > pourBottleIntoStdVector(yarp::os::Bottle bottle, int &indexesToSkip)
yarp::os::Bottle trimBottle(const yarp::os::Bottle &bottle, int startIndex, int endIndex=-1)
void pourDisplacementdIntoBottle(const Eigen::Displacementd &disp, yarp::os::Bottle &bottle)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Eigen::MatrixXd pourBottleIntoEigenMatrix(yarp::os::Bottle bottle, int &indexesToSkip)
Eigen::VectorXi pourBottleIntoEigenVectorXi(yarp::os::Bottle bottle, int &indexesToSkip)
void pourEigenMatrixIntoBottle(const Eigen::MatrixXd &mat, yarp::os::Bottle &bottle)
Eigen::Twistd pourBottleIntoTwistd(yarp::os::Bottle bottle, int &indexesToSkip)
void pourTwistdIntoBottle(const Eigen::Twistd &twist, yarp::os::Bottle &bottle)
void pourStdVectorIntoBottle(const std::vector< double > &vec, yarp::os::Bottle &bottle)
void pourEigenVectorIntoBottle(const Eigen::VectorXd &vec, yarp::os::Bottle &bottle)
Eigen::VectorXd pourBottleIntoEigenVector(yarp::os::Bottle bottle, int &indexesToSkip)
void pourWrenchdIntoBottle(const Eigen::Wrenchd &wrench, yarp::os::Bottle &bottle)
Eigen::Displacementd pourBottleIntoDisplacementd(yarp::os::Bottle bottle, int &indexesToSkip)