20 #ifdef FARSA_USE_YARP_AND_ICUB
22 #ifndef PHYICUBHELPERS_H
23 #define PHYICUBHELPERS_H
25 #include "worldsimconfig.h"
28 #include "wquaternion.h"
30 #include "yarpobject.h"
33 #include "phyobject.h"
43 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
44 #pragma GCC diagnostic push
45 #pragma GCC diagnostic ignored "-Wunused-parameter"
47 #pragma GCC diagnostic ignored "-Wunused-parameter"
50 #include "yarp/dev/CartesianControl.h"
51 #include "yarp/os/ConnectionReader.h"
52 #include "yarp/os/PortReader.h"
53 #include "iCub/iKin/iKinHlp.h"
54 #include "iCub/iKin/iKinSlv.h"
56 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
57 #pragma GCC diagnostic pop
59 #pragma GCC diagnostic warning "-Wunused-parameter"
73 FARSA_WSIM_API std::ostream& operator<<(std::ostream &os,
const wMatrix &m);
82 FARSA_WSIM_API std::ostream& operator<<(std::ostream &os,
const wVector &v);
90 FARSA_WSIM_API
void convertYarpMatrixToWorldMatrix(
const yarp::sig::Matrix &y, wMatrix &w);
98 FARSA_WSIM_API
void convertWorldMatrixToYarpMatrix(
const wMatrix &w, yarp::sig::Matrix &y);
142 real position()
const
144 return m_curPosition;
153 void setLinkAngle(real newAngle);
160 void setDesideredPosition(real desideredAngle);
168 void setDesideredVelocity(real velocity);
292 void setKinematic(
bool b);
301 void setStatic(
bool b);
310 void enableJoints(
bool b);
318 void updateRelativePositions();
324 void resetObjectPositions()
355 void setDOFPosition(real pos, ChainIDType chainID, ElementIDType dof);
363 void updateFromDOF();
370 virtual void preUpdate();
377 virtual void postUpdate();
396 virtual void changedMatrix();
407 struct ObjectAndMatrix
415 ObjectAndMatrix(PhyObject* obj, wMatrix mtr) :
431 QMap<ChainIDType, QVector<ObjectAndMatrix> > m_objects;
437 struct DOFAndListener
446 DOFAndListener(PhyJoint* j,
unsigned int d, DOFStatusListener* l) :
455 DOFStatusListener* listener;
464 QMap<ChainIDType, QVector<DOFAndListener> > m_joints;
571 void setBuddies(QSet<KinematicLinkInfo*> buddies);
580 void setWObject(
WObject* wObject,
const wMatrix &m = s_identityMatrix);
601 return m_objectMatrix;
627 return m_worldTm->rotateVector(m_axis);
658 return m_worldTm->transformVector(m_bottom);
684 return m_worldTm->transformVector(m_top);
694 real getHeight()
const
720 return m_objectMatrix.unrotateVector(m_rotAxis);
748 return m_objectMatrix.untransformVector(m_rotCenter);
763 void setWorldMatrix(
const wMatrix *mtr);
786 yarp::sig::Matrix getYarpMatrix()
const
788 return m_chain->getH(m_linkID,
true);
802 convertYarpMatrixToWorldMatrix(m_chain->getH(m_linkID,
true), mtr);
812 const iCub::iKin::iKinLink& getiKinLink()
const
814 return (*(m_chain->asChain()))[m_linkID];
823 void updateInformationFromiKin();
829 void updateMatrixFromiKin();
846 void setJoint(
PhyJoint *joint,
bool invertedJointAxis =
true,
unsigned int dof = 0,
bool doConnection =
true, Qt::ConnectionType connType = Qt::DirectConnection);
863 unsigned int getJointDOF()
const
865 return m_phyJointDOF;
874 void setLinkAngle(real newAngle);
881 void setDesideredPosition(real desideredAngle);
889 void setDesideredVelocity(real velocity);
897 void setiKinLinkLimits(real
min, real
max);
917 void setWObject_NB(
WObject* wObject,
const wMatrix &m = s_identityMatrix);
928 void setWorldMatrix_NB(
const wMatrix *mtr);
936 void updateInformationFromiKin_NB();
945 void updateMatrixFromiKin_NB();
964 void setJoint_NB(
PhyJoint *joint,
bool invertedJointAxis =
true,
unsigned int dof = 0,
bool doConnection =
true, Qt::ConnectionType connType = Qt::DirectConnection);
973 void setLinkAngle_NB(real newAngle);
982 void setDesideredPosition_NB(real desideredAngle);
992 void setDesideredVelocity_NB(real velocity);
1002 void setiKinLinkLimits_NB(real
min, real
max);
1010 void updateLink_NB();
1018 mutable QSet<KinematicLinkInfo*> m_buddies;
1031 bool m_isMasterBuddy;
1036 iCub::iKin::iKinLimb* m_chain;
1041 unsigned int m_linkID;
1125 unsigned int m_phyJointDOF;
1131 bool m_invertedJointAxis;
1155 bool m_linkAngleUpdated;
1161 static const wMatrix s_identityMatrix;
1175 template <
class iKinLimb_t>
1254 for (
int i = 0; i < m_links.size(); i++) {
1270 return m_links[0].getWorldMatrix();
1279 void updateInformationFromiKin()
1281 for (
int i = 0; i < m_links.size(); i++) {
1282 m_links[i].updateInformationFromiKin();
1304 void updateMatrixFromiKin(
int updateObjMatrixFromLink = 0,
int updateObjMatrixUpToLink = -1)
1306 if (updateObjMatrixFromLink < 0) {
1307 updateObjMatrixFromLink = 0;
1309 if ((updateObjMatrixUpToLink < 0) || (updateObjMatrixUpToLink >= m_links.size())) {
1310 updateObjMatrixUpToLink = m_links.size() - 1;
1314 for (
int i = updateObjMatrixFromLink; i <= updateObjMatrixUpToLink; i++) {
1315 m_links[i].updateLink();
1319 for (
int i = updateObjMatrixFromLink; i <= updateObjMatrixUpToLink; i++) {
1320 m_links[i].updateMatrixFromiKin();
1334 m_rootObject = rootObject;
1344 return m_rootObject;
1370 PhyJoint* createJoint(
int linkID,
bool invertAxis =
true,
bool doConnection =
true, Qt::ConnectionType connType = Qt::DirectConnection,
unsigned int dof = 0)
1373 const wVector axis = invertAxis ? -getLinkInfo(linkID).getRotAxisWObject() : getLinkInfo(linkID).getRotAxisWObject();
1375 if (parent == NULL) {
1383 WObject*
const childWObject = (linkID <= 0) ? m_rootObject : getLinkInfo(linkID - 1).getWObject();
1385 if ((child == NULL) && (
typeid(childWObject) ==
typeid(
PhyObjectsGroup*))) {
1387 child = (
dynamic_cast<PhyObjectsGroup*
>(childWObject))->getHeadObject();
1390 Q_ASSERT_X((parent != NULL),
"PhyObjectsGroup::createJoint",
"This is going to crash, parent object in joint is NULL");
1393 PhyJoint* joint =
new PhyHinge(axis, getLinkInfo(linkID).getRotCenterWObject(), parent, child);
1394 getLinkInfo(linkID).setJoint(joint, invertAxis, dof, doConnection, connType);
1403 void initLinkInfoList()
1406 for (
unsigned int i = 0; i < this->getN(); i++) {
1408 this->releaseLink(i);
1415 QVector<KinematicLinkInfo> m_links;
1424 WObject *m_rootObject;
1430 #endif // FARSA_USE_YARP_AND_ICUB