iCub-main
bvhnodeinertial.h
Go to the documentation of this file.
1 /*
2  * bvhnodeinertial.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 BVHNODEINERTIAL_H
19 #define BVHNODEINERTIAL_H
20 
21 #include "bvhnodeend.h"
22 #include <yarp/dev/PolyDriver.h>
23 #include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
24 #include <cstring>
25 
26 constexpr double DEG2RAD=3.14159265/180.0;
27 extern std::string GUI_NAME;
29 {
30 public:
31 
32  BVHNodeINERTIAL(const QString& name,double a,double d,double alpha,double theta0,const QString& portIMUName,iCubMesh* mesh=nullptr)
33  : BVHNodeEND(name,-1,a,d,alpha,theta0,mesh)
34  {
35  Property masConf {{"device",Value("multipleanalogsensorsclient")},
36  {"local", Value( GUI_NAME+"/inertials")},
37  {"remote",Value(portIMUName.toStdString())},
38  {"timeout",Value(0.04)},
39  {"externalConnection",Value(true)}};
40 
41  if (!dd_MASClient.open(masConf))
42  {
43  yError("unable to open the MAS client\n");
44  }
45 
46  if(!dd_MASClient.view(iAcc) || !dd_MASClient.view(iGyro))
47  {
48  yError("view of one of the MAS interfaces required failed\n");
49  }
50 
51  acc.resize(3);
52  gyro.resize(3);
53  }
54 
55  virtual ~BVHNodeINERTIAL()
56  {
57  dd_MASClient.close();
58  qDebug("CLOSING INERTIAL");
59  }
60 
61  void drawJoint() override
62  {
63  if (dd_MASClient.isValid())
64  {
65  bool ok{true};
66 
67  double ts;
68 
69  ok &= iAcc->getThreeAxisLinearAccelerometerMeasure(0, acc, ts);
70  ok &= iGyro->getThreeAxisGyroscopeMeasure(0, gyro, ts);
71  if (ok) {
72 
73  gyro[0]*=DEG2RAD;
74  gyro[1]*=DEG2RAD;
75  gyro[2]*=DEG2RAD;
76 
77  glTranslated(40.0,0.0,230.0);
78  glColor4f(0.4,0.4,1.0,1.0);
79  glutSolidCube(22.0);
80 
81  // Accelerometer
82  glLineWidth(3.0);
83  glColor4f(1.0,0.0,0.0,1.0);
84  glBegin(GL_LINES);
85  glVertex3d(0.0,0.0,0.0);
86  glVertex3d(-10.0*acc[0],0.0,0.0);
87  glEnd();
88 
89  glColor4f(0.0,1.0,0.0,1.0);
90  glBegin(GL_LINES);
91  glVertex3d(0.0,0.0,0.0);
92  glVertex3d(0.0,-10.0*acc[1],0.0);
93  glEnd();
94 
95  glColor4f(0.0,0.0,1.0,1.0);
96  glBegin(GL_LINES);
97  glVertex3d(0.0,0.0,0.0);
98  glVertex3d(0.0,0.0,-10.0*acc[2]);
99  glEnd();
100 
101  // Gyro
102 
103  glLineWidth(2.0);
104  glDisable(GL_LINE_SMOOTH);
105 
106  glColor4f(1.0,0.0,0.0,1.0);
107  glPushMatrix();
108  glRotated(90.0,0.0,1.0,0.0);
109  drawArc(gyro[0]);
110  glPopMatrix();
111 
112  glColor4f(0.0,1.0,0.0,1.0);
113  glPushMatrix();
114  glRotated(-90.0,1.0,0.0,0.0);
115  drawArc(gyro[1]);
116  glPopMatrix();
117 
118  glColor4f(0.0,0.0,1.0,1.0);
119  glPushMatrix();
120  glRotated(-90.0,0.0,0.0,1.0);
121  drawArc(gyro[2]);
122  glPopMatrix();
123 
124  glEnable(GL_LINE_SMOOTH);
125 
126  }
127  }
128  }
129 
130 private:
131  yarp::dev::PolyDriver dd_MASClient;
132  yarp::dev::IThreeAxisGyroscopes* iGyro{nullptr};
133  yarp::dev::IThreeAxisLinearAccelerometers* iAcc{nullptr};
134  yarp::sig::Vector gyro;
135  yarp::sig::Vector acc;
136 
137 };
138 
139 #endif
constexpr double DEG2RAD
std::string GUI_NAME
void drawArc(double dOmega)
Definition: bvhnodedh.h:71
BVHNodeINERTIAL(const QString &name, double a, double d, double alpha, double theta0, const QString &portIMUName, iCubMesh *mesh=nullptr)
void drawJoint() override
virtual ~BVHNodeINERTIAL()
const QString & name() const
Definition: bvhnode.h:221
Definition: mesh.h:54