iCub-main
main.cpp
Go to the documentation of this file.
1 
13 #include <cstdlib>
14 #include <memory>
15 #include <cmath>
16 #include <string>
17 #include <iostream>
18 #include <algorithm>
19 
20 #include <yarp/os/all.h>
21 #include <yarp/sig/all.h>
22 #include <iCub/iKin/iKinFwd.h>
23 
24 using namespace std;
25 using namespace yarp::os;
26 using namespace yarp::sig;
27 using namespace iCub::iKin;
28 
29 /****************************************************************/
30 int main(int argc, char *argv[])
31 {
32  ResourceFinder rf;
33  rf.configure(argc, argv);
34  if (rf.check("help"))
35  {
36  cout << "Options:" << endl;
37  cout << "--kinematics eye|arm|leg" << endl;
38  cout << "--type left|right|left_v2|..." << endl;
39  cout << "--q \"(1.0 ... n)\"" << endl;
40  return EXIT_SUCCESS;
41  }
42 
43  string kinematics = rf.check("kinematics", Value("eye")).asString();
44  string type = rf.check("type", Value("left")).asString();
45 
46  transform(kinematics.begin(), kinematics.end(), kinematics.begin(), ::tolower);
47  transform(type.begin(), type.end(), type.begin(), ::tolower);
48 
49  if ((kinematics != "eye") && (kinematics != "arm") && (kinematics != "leg"))
50  {
51  cerr << "unrecognized kinematics \"" << kinematics << "\"" << endl;
52  return EXIT_FAILURE;
53  }
54 
55  unique_ptr<iKinLimb> limb;
56  if (kinematics == "eye")
57  {
58  limb = unique_ptr<iKinLimb>(new iCubEye(type));
59  }
60  else if (kinematics == "arm")
61  {
62  limb = unique_ptr<iKinLimb>(new iCubArm(type));
63  }
64  else
65  {
66  limb = unique_ptr<iKinLimb>(new iCubLeg(type));
67  }
68 
69  cout << "Asked for type \"" << type << "\"" << endl;
70  cout << "Type used \"" << limb->getType() << "\"" << endl;
71 
72  iKinChain* chain = limb->asChain();
73  chain->setAllConstraints(false);
74  for (size_t i = 0; i < chain->getN(); i++)
75  {
76  chain->releaseLink(i);
77  }
78 
79  Vector q(chain->getN(), 0.0);
80  if (Bottle *b = rf.find("q").asList())
81  {
82  size_t len = std::min(q.length(), (size_t)b->size());
83  for (size_t i = 0; i < len; i++)
84  {
85  q[i] = b->get(i).asFloat64();
86  }
87  }
88 
89  Matrix H = chain->getH((M_PI / 180.0) * q);
90 
91  cout << "kinematics=\"" << kinematics << "/" << type << "\"" << endl;
92  cout << "q=(" << ((180.0 / M_PI) * chain->getAng()).toString(5, 5) << ")" << endl;
93  cout << "H=" << endl << H.toString(5, 5) << endl;
94  cout << endl;
95 
96  return EXIT_SUCCESS;
97 }
#define M_PI
Definition: XSensMTx.cpp:24
A class for defining the iCub Arm.
Definition: iKinFwd.h:1193
A class for defining the iCub Eye.
Definition: iKinFwd.h:1385
A class for defining the iCub Leg.
Definition: iKinFwd.h:1348
A Base class for defining a Serial Link Chain.
Definition: iKinFwd.h:354
yarp::sig::Matrix getH(const unsigned int i, const bool allLink=false)
Returns the rigid roto-translation matrix from the root reference frame to the ith frame in Denavit-H...
Definition: iKinFwd.cpp:732
bool releaseLink(const unsigned int i)
Releases the ith Link.
Definition: iKinFwd.cpp:463
yarp::sig::Vector getAng()
Returns the current free joint angles values.
Definition: iKinFwd.cpp:611
unsigned int getN() const
Returns the number of Links belonging to the Chain.
Definition: iKinFwd.h:549
void setAllConstraints(bool _constrained)
Sets the constraint status of all chain links.
Definition: iKinFwd.cpp:498
int main(int argc, char *argv[])
Definition: main.cpp:31
std::string toString(const T &t)
Definition: compensator.h:200
const FSC min
Definition: strain.h:49