MoveMasterModel.cpp
Go to the documentation of this file.
1 // *****************************************************************
2 // Filename: SearchModule.cpp
3 // Copyright: Kai Welke, Chair Prof. Dillmann (IAIM),
4 // Institute for Computer Science and Engineering (CSE),
5 // University of Karlsruhe. All rights reserved.
6 // Author: Kai Welke
7 // Date: 25.09.2008
8 // *****************************************************************
9 
10 // *****************************************************************
11 // includes
12 // *****************************************************************
13 #include "MoveMasterModel.h"
14 
15 namespace visionx
16 {
17  // *****************************************************************
18  // initialization of static members
19  // *****************************************************************
20  const std::string CMoveMasterModel::keypoint[NO_KEYPOINTS] = {"PalmCenter",
21  "IndexTip",
22  "MiddleTip",
23  "ThumbTip"};
24  const std::string CMoveMasterModel::jointname[NO_JOINTS] = {"Body",
25  "Shoulder",
26  "Elbow",
27  "Wrist_pan",
28  "Wrist_rotate",
29  "Palm",
30  "Index_0",
31  "Index_1",
32  "Middle_0",
33  "Middle_1",
34  "Ring_0",
35  "Ring_1",
36  "Pinky_0",
37  "Pinky_1",
38  "Thumb_0",
39  "Thumb_1",
40  "Actuator_Thumb_1",
41  "Actuator_Thumb_2",
42  "Actuator_Index_1",
43  "Actuator_Index_2",
44  "Actuator_Middle_1",
45  "Actuator_Middle_2",
46  "Actuator_Ring_1",
47  "Actuator_Ring_2",
48  "Actuator_Pinky_1",
49  "Actuator_Pinky_2"};
50 
51  // *****************************************************************
52  // implementation of CMoveMasterModel
53  // *****************************************************************
54  // *****************************************************************
55  // construction / destruction
56  // *****************************************************************
58  {
60  }
61 
63  {
64  if (m_pOIFwdKinematicsInterface != NULL)
65  {
67  }
68  }
69 
70  // *****************************************************************
71  // init and update
72  // *****************************************************************
73  bool
74  CMoveMasterModel::init(std::string sFilename, float fFocalLengthY)
75  {
76  if (m_pOIFwdKinematicsInterface != NULL)
77  {
78  printf("already initialized\n");
79  return false;
80  }
81 
84  {
87  }
88 
89  // *** Extract keypoint paths initially for fast access later
90  for (int i = 0; i < NO_KEYPOINTS; i++)
91  {
92  if (!m_pOIFwdKinematicsInterface->getPath(keypoint[i], keypath[i]))
93  {
94  printf("Keypoint node %s not found in path!\n", keypoint[i].c_str());
95  }
96  }
97 
98  // *** Extract joint paths initially for fast access later
99  for (int i = 0; i < NO_JOINTS; i++)
100  {
101  if (!m_pOIFwdKinematicsInterface->getPath(jointname[i], jointpath[i]))
102  {
103  printf("joint node %s not found in path!\n", jointname[i].c_str());
104  }
105  }
106 
107 
108  // hand (David)
109  SoPath* temp_path;
110  m_pOIFwdKinematicsInterface->getPath("HandPos", temp_path);
111  hand_pos = static_cast<SoTranslation*>(temp_path->getNodeFromTail(0));
112  m_pOIFwdKinematicsInterface->getPath("HandRot", temp_path);
113  hand_rot = static_cast<SoTransform*>(temp_path->getNodeFromTail(0));
114  // object cylinder (David)
115  m_pOIFwdKinematicsInterface->getPath("ObjCylinderPos", temp_path);
116  m_pObjCylPos = static_cast<SoTranslation*>(temp_path->getNodeFromTail(0));
117  m_pOIFwdKinematicsInterface->getPath("ObjCylinderRot", temp_path);
118  m_pObjCylRot = static_cast<SoTransform*>(temp_path->getNodeFromTail(0));
119  m_pOIFwdKinematicsInterface->getPath("ObjCylinder", temp_path);
120  m_pObjectCylinder = static_cast<SoCylinder*>(temp_path->getNodeFromTail(0));
121  // test sphere (David)
122  m_pOIFwdKinematicsInterface->getPath("TestSphere", temp_path);
123  m_pTestSpherePos = static_cast<SoTranslation*>(temp_path->getNodeFromTail(0));
124 
125  return true;
126  }
127 
128  void
130  {
132  {
133  printf("call init first\n");
134  return;
135  }
136 
138  }
139 
140  // *****************************************************************
141  // kinematics
142  // *****************************************************************
143  void
144  CMoveMasterModel::setJointAngle(int nJoint, float fAngleRad)
145  {
146  if (nJoint >= NO_JOINTS)
147  {
148  printf("Illegal joint: %d\n", nJoint);
149  return;
150  }
151 
152  if (!m_pOIFwdKinematicsInterface->setJointAngle(jointpath[nJoint], fAngleRad))
153  {
154  printf("Could not set joint angle for node %s!\n", jointname[nJoint].c_str());
155  }
156  //else
157  //m_pOIFwdKinematicsInterface->update();
158  }
159 
160  Vec3d
162  {
163  Vec3d result;
164 
165  if (nKeyPoint >= NO_KEYPOINTS)
166  {
167  printf("Illegal keypoint: %d\n", nKeyPoint);
168  return result;
169  }
170 
171 
172  if (m_pOIFwdKinematicsInterface->getTranslation(iposition[nKeyPoint], keypath[nKeyPoint]))
173  {
174  float x, y, z;
175  iposition[nKeyPoint].getValue(x, y, z);
176 
177  // transform to robot coordinate system
178  result.x = -x;
179  result.y = y;
180  result.z = -z;
181  }
182  else
183  {
184  printf("Could not retrieve position of keypath %s!\n", keypoint[nKeyPoint].c_str());
185  }
186 
187  return result;
188  }
189 
190  void
191  CMoveMasterModel::setHandRotation(double alpha, double beta, double gamma) // <- added (David)
192  {
193  Mat3d tempmat;
194  Vec3d axis;
195  float angle;
196  SbRotation rot;
197  SbVec3f vec;
198 
199  Math3d::SetRotationMat(tempmat, alpha, beta, gamma);
200  Math3d::GetAxisAndAngle(tempmat, axis, angle);
201  if (Math3d::Length(axis) == 0)
202  {
203  axis.z = 1;
204  }
205  //vec.setValue(-axis.x, axis.y, -axis.z);// transform to robot coordinate system
206  vec.setValue(axis.x, axis.y, axis.z);
207 
208  //*** Keep angle in interval [-2Pi,2Pi] (required for coin!)
209  if (fabs(angle) > 2 * M_PI)
210  {
211  angle = angle - (floor(angle / (2 * M_PI)) * 2 * M_PI);
212  }
213  //*** Keep angle positive (required for coin!)
214  if (angle <= 0.0f) // This is mandatory: Coin uses quaternions internally and can thus not
215  {
216  angle =
217  2 * M_PI +
218  angle; // reflect angles of 0deg without change of axis. Therefore set to 2Pi instead.
219  }
220 
221  hand_rot->rotation.setValue(vec, angle);
222  }
223 
224  void
225  CMoveMasterModel::setHandPosition(Vec3d pos) // <- added (David)
226  {
227  SbVec3f temp;
228  temp.setValue(pos.x, pos.y, pos.z); // transform to robot coordinate system?
229  hand_pos->translation.setValue(temp);
230  }
231 
232  void
234  double alpha,
235  double beta,
236  double gamma,
237  float height,
238  float radius) // (David)
239  {
240  SbVec3f temp;
241  temp.setValue(pos.x, pos.y, pos.z);
242  m_pObjCylPos->translation.setValue(temp);
243 
244 
245  Mat3d tempmat;
246  Vec3d axis;
247  float angle;
248  SbRotation rot;
249  SbVec3f vec;
250 
251  Math3d::SetRotationMat(tempmat, alpha, beta, gamma);
252  Math3d::GetAxisAndAngle(tempmat, axis, angle);
253  if (Math3d::Length(axis) == 0)
254  {
255  axis.z = 1;
256  }
257  //vec.setValue(-axis.x, axis.y, -axis.z);// transform to robot coordinate system
258  vec.setValue(axis.x, axis.y, axis.z);
259 
260  //*** Keep angle in interval [-2Pi,2Pi] (required for coin!)
261  if (std::fabs(angle) > 2 * M_PI)
262  {
263  angle = angle - (std::floor(angle / (2 * M_PI)) * 2 * M_PI);
264  }
265  //*** Keep angle positive (required for coin!)
266  if (angle <= 0.0f) // This is mandatory: Coin uses quaternions internally and can thus not
267  {
268  angle =
269  2 * M_PI +
270  angle; // reflect angles of 0deg without change of axis. Therefore set to 2Pi instead.
271  }
272 
273  m_pObjCylRot->rotation.setValue(vec, angle);
274 
275  m_pObjectCylinder->height.setValue(height);
276  m_pObjectCylinder->radius.setValue(radius);
277  }
278 
279  void
281  {
282  SbVec3f temp;
283  temp.setValue(pos.x, pos.y, pos.z); // transform to robot coordinate system?
284  m_pTestSpherePos->translation.setValue(temp);
285  }
286 } // namespace visionx
visionx::CMoveMasterModel::m_pOIFwdKinematicsInterface
OIFwdKinematicsInterface * m_pOIFwdKinematicsInterface
Definition: MoveMasterModel.h:48
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:737
MoveMasterModel.h
visionx::CMoveMasterModel::~CMoveMasterModel
~CMoveMasterModel()
Definition: MoveMasterModel.cpp:62
visionx::OIFwdKinematicsInterface::m_fFocalLengthY
float m_fFocalLengthY
Definition: OIFwdKinematicsInterface.h:81
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CMoveMasterModel::m_pObjCylPos
SoTranslation * m_pObjCylPos
Definition: MoveMasterModel.h:59
visionx::CMoveMasterModel::setObjCylConfig
void setObjCylConfig(Vec3d pos, double alpha, double beta, double gamma, float height, float radius)
Definition: MoveMasterModel.cpp:233
visionx::OIFwdKinematicsInterface::getPath
bool getPath(std::string name, SoPath *&p, SoNode *r=NULL)
Definition: OIFwdKinematicsInterface.cpp:299
visionx::CMoveMasterModel::setHandPosition
void setHandPosition(Vec3d pos)
Definition: MoveMasterModel.cpp:225
visionx::CMoveMasterModel::CMoveMasterModel
CMoveMasterModel()
Definition: MoveMasterModel.cpp:57
visionx::OIFwdKinematicsInterface::getTranslation
bool getTranslation(SbVec3f &translation, SoPath *p)
Definition: OIFwdKinematicsInterface.cpp:327
visionx::CMoveMasterModel::m_pTestSpherePos
SoTranslation * m_pTestSpherePos
Definition: MoveMasterModel.h:69
visionx::CMoveMasterModel::hand_pos
SoTranslation * hand_pos
Definition: MoveMasterModel.h:53
M_PI
#define M_PI
Definition: MathTools.h:17
visionx::OIFwdKinematicsInterface::update
void update()
Definition: OIFwdKinematicsInterface.cpp:170
visionx::CMoveMasterModel::getPositionOfKeypoint
Vec3d getPositionOfKeypoint(int nKeyPoint)
Definition: MoveMasterModel.cpp:161
visionx::OIFwdKinematicsInterface::initviewer
void initviewer()
Definition: OIFwdKinematicsInterface.cpp:195
NO_KEYPOINTS
#define NO_KEYPOINTS
Definition: MoveMasterModel.h:23
visionx::CMoveMasterModel::update
void update()
Definition: MoveMasterModel.cpp:129
visionx::CMoveMasterModel::hand_rot
SoTransform * hand_rot
Definition: MoveMasterModel.h:52
visionx::CMoveMasterModel::init
bool init(std::string sFilename, float fFocalLengthY)
Definition: MoveMasterModel.cpp:74
angle
double angle(const Point &a, const Point &b, const Point &c)
Definition: point.hpp:109
visionx::OIFwdKinematicsInterface
Definition: OIFwdKinematicsInterface.h:60
visionx::CMoveMasterModel::setJointAngle
void setJointAngle(int nJoint, float fAngleRad)
Definition: MoveMasterModel.cpp:144
visionx::OIFwdKinematicsInterface::isInitialized
bool isInitialized()
Definition: OIFwdKinematicsInterface.cpp:540
visionx::OIFwdKinematicsInterface::setJointAngle
bool setJointAngle(SoPath *p, float angle)
Definition: OIFwdKinematicsInterface.cpp:358
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
visionx::CMoveMasterModel::setTestSpherePosition
void setTestSpherePosition(Vec3d pos)
Definition: MoveMasterModel.cpp:280
visionx::CMoveMasterModel::m_pObjCylRot
SoTransform * m_pObjCylRot
Definition: MoveMasterModel.h:58
visionx::CMoveMasterModel::setHandRotation
void setHandRotation(double alpha, double beta, double gamma)
Definition: MoveMasterModel.cpp:191
visionx::CMoveMasterModel::m_pObjectCylinder
SoCylinder * m_pObjectCylinder
Definition: MoveMasterModel.h:60
NO_JOINTS
#define NO_JOINTS
Definition: MoveMasterModel.h:24