iCub-main
bvhnodeforcetorque.h
Go to the documentation of this file.
1 /*
2  * bvhnodeforcetorque.h
3  */
4 
5 /*
6  * Copyright (C) 2009 RobotCub Consortium
7  * Author: Alessandro Scalzo alessandro.scalzo@iit.it
8  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
9  *
10  * Based on:
11  *
12  * Qavimator
13  * Copyright (C) 2006 by Zi Ree *
14  * Zi Ree @ SecondLife *
15  * Released under the terms of the GNU GPL v2.0.
16  */
17 
18 #ifndef BVHNODEFORCETORQUE_H
19 #define BVHNODEFORCETORQUE_H
20 
21 #include "bvhnodedh.h"
22 
23 #include <yarp/sig/Vector.h>
24 #include <yarp/os/BufferedPort.h>
25 
26 //#include <yarp/dev/ControlBoardInterfaces.h>
27 //#include <yarp/dev/PolyDriver.h>
28 //#include <yarp/dev/CanBusInterface.h>
29 
31 {
32  public:
33 
34  BVHNodeForceTorque(const QString& name,const QString& portName,int enc,double a,double d,double alpha,double theta0,iCubMesh* mesh=0)
35  : BVHNodeDH(name,enc,a,d,alpha,theta0,mesh)
36  {
37  mPort.open((GUI_NAME+portName.toLatin1().data()).c_str());
38 
39  if (pMesh)
40  {
41  //delete pMesh;
42  //pMesh=0;
43  }
44 
45  //m_Alpha=0.5;
46 
47  for (int i=0; i<6; ++i) dForceTorque[i]=0.0;
48  }
49 
51  {
52  mPort.close();
53  }
54 
55  virtual void drawJoint()
56  {
58 
59  glColor4f(0.4,0.4,1.0,1.0);
60  glPushMatrix();
61  glTranslated(0.0,0.0,15.0);
62  gluDisk(cyl,0.0,27.5,16,16);
63  gluCylinder(cyl,27.5,27.5,18.0,16,16);
64  glTranslated(0.0,0.0,18.0);
65  gluDisk(cyl,0.0,27.5,16,16);
66  glTranslated(0.0,0.0,-9.0);
67 
68  glDisable(GL_DEPTH_TEST);
69 
70  if (mPort.getInputCount()>0)
71  {
72  yarp::sig::Vector *ft=mPort.read(false);
73 
74  if (ft) for (int i=0; i<6; ++i) dForceTorque[i]=(*ft)[i];
75  }
76 
77  // Force
78  glLineWidth(3.0);
79 
80  //dForceTorque[0]=dForceTorque[1]=dForceTorque[2]=300.0;
81 
82  // X
83  glPushMatrix();
84  glColor4f(1.0,0.0,0.0,1.0);
85  glRotated(90.0,0.0,1.0,0.0);
86  drawArrow(0.1*dForceTorque[1]);
87  glPopMatrix();
88 
89  // Y
90  glColor4f(0.0,1.0,0.0,1.0);
91  glPushMatrix();
92  glRotated(-90.0,1.0,0.0,0.0);
93  drawArrow(0.1*dForceTorque[2]);
94  glPopMatrix();
95 
96  // Z
97  glColor4f(0.0,0.0,1.0,1.0);
98  glPushMatrix();
99  drawArrow(0.1*dForceTorque[0]);
100  glPopMatrix();
101 
102  // Torque
103 
104  glLineWidth(2.0);
105  glDisable(GL_LINE_SMOOTH);
106 
107  // X
108  glColor4f(1.0,0.0,0.0,1.0);
109  glPushMatrix();
110  glRotated(90.0,0.0,1.0,0.0);
111  drawArc(0.0005*dForceTorque[4]);
112  glPopMatrix();
113 
114  // Y
115  glColor4f(0.0,1.0,0.0,1.0);
116  glPushMatrix();
117  glRotated(-90.0,1.0,0.0,0.0);
118  glRotated(180.0,0.0,0.0,10.0);
119  drawArc(-0.0005*dForceTorque[3]);
120  glPopMatrix();
121 
122  // Z
123  glColor4f(0.0,0.0,1.0,1.0);
124  glPushMatrix();
125  glRotated(180.0,0.0,0.0,10.0);
126  drawArc(0.0005*dForceTorque[5]);
127  glPopMatrix();
128 
129  glPopMatrix();
130 
131  glEnable(GL_LINE_SMOOTH);
132 
133  glEnable(GL_DEPTH_TEST);
134  }
135 
136 protected:
137  double dForceTorque[6];
138 
139  yarp::os::BufferedPort<yarp::sig::Vector> mPort;
140 };
141 
142 #endif
std::string GUI_NAME
void drawArc(double dOmega)
Definition: bvhnodedh.h:71
void drawArrow(double dMag)
Definition: bvhnodedh.h:93
virtual void drawJoint()
yarp::os::BufferedPort< yarp::sig::Vector > mPort
BVHNodeForceTorque(const QString &name, const QString &portName, int enc, double a, double d, double alpha, double theta0, iCubMesh *mesh=0)
const QString & name() const
Definition: bvhnode.h:221
virtual void drawJoint()
Definition: bvhnode.h:255
iCubMesh * pMesh
Definition: bvhnode.h:286
GLUquadricObj * cyl
Definition: bvhnode.h:281
Definition: mesh.h:54