fk.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * The University of Tokyo
8  */
9 /*
10  * fk.cpp
11  * Create: Katsu Yamane, Univ. of Tokyo, 03.06.19
12  */
13 
14 #include "chain.h"
15 
17 {
19 }
20 
22 {
23  if(parent)
24  {
25 #if 0
26  // readable, but slower version
29 #else
30  // faster version
34 #endif
35 // cout << name << ": " << abs_pos << endl;
36  }
39 }
40 
42 {
44 }
45 
47 {
48  if(parent)
49  {
50  static fMat33 t_rel_att;
51  static fVec3 v1, v2;
52  t_rel_att.tran(rel_att);
53  // compute loc_lin_vel
55  v2.mul(t_rel_att, parent->loc_lin_vel);
56  loc_lin_vel.mul(t_rel_att, v1);
57  loc_lin_vel += v2;
59  // compute loc_ang_vel
60  loc_ang_vel.mul(t_rel_att, parent->loc_ang_vel);
62  // compute loc_com_vel
65  }
66  else
67  {
68  loc_lin_vel.zero();
69  loc_ang_vel.zero();
70  }
73 }
74 
76 {
78 }
79 
81 {
82  if(parent)
83  {
84  static fMat33 t_rel_att;
85  static fVec3 v1, v2, v3, v4;
86  t_rel_att.tran(rel_att);
87  // Éð»Ê±ñ1¡¦x
88  v1.mul(t_rel_att, parent->loc_ang_vel);
89 // v1 += loc_ang_vel;
90  v1 *= 2.0;
91  v2.cross(v1, rel_lin_vel);
94  v1.add(parent->loc_lin_acc, v2);
96  v3.cross(parent->loc_ang_vel, v2);
97  v1 += v3;
98  v4.mul(t_rel_att, v1);
99  loc_lin_acc += v4;
100  // ³Ñ±ñ1¡¦x
101 // v1.cross(loc_ang_vel, parent->rel_ang_vel);
104  v1.mul(t_rel_att, parent->loc_ang_acc);
105  loc_ang_acc += v1;
106  // ½Å¿´£öÅð»Ê±ñ1¡¦x
110  v2.cross(loc_ang_vel, v1);
111  loc_com_acc += v2;
112 
113 // cerr << name << ": loc_lin_acc = " << loc_lin_acc << endl;
114 // cerr << name << ": loc_ang_acc = " << loc_ang_acc << endl;
115 // if(real)
116 // cerr << name << ": acc = " << abs_att*loc_lin_acc << abs_att*loc_ang_acc << endl;
117  }
118  else
119  {
120  // ¥ë¡¼¥È¥ê¥ó¥¯
121  // loc_lin_acc£õ"¡¦dÍ÷)¡¦¡¦x£åÂð€¡¦Ãà¡à¡¦Ëࡦ±êù硦¡¦Çà
122  loc_ang_acc.zero();
123  loc_com_acc.zero();
124  }
127 }
128 
129 double Chain::TotalCOM(fVec3& com, const char* chname)
130 {
131  com.zero();
132  double m = root->total_com(com, chname);
133  com /= m;
134  return m;
135 }
136 
137 double Joint::total_com(fVec3& com, const char* chname)
138 {
139  int is_target = false;
140  if(!chname)
141  {
142  is_target = true;
143  }
144  else
145  {
146  char* my_chname = CharName();
147  if(my_chname && !strcmp(my_chname, chname))
148  {
149  is_target = true;
150  }
151  }
152  fVec3 b_com, c_com;
153  b_com.zero();
154  c_com.zero();
155  double ret = brother->total_com(b_com, chname) + child->total_com(c_com, chname);
156 
157  com.add(b_com, c_com);
158  if(is_target)
159  {
160  static fVec3 abs_com_pos, my_com;
161  ret += mass;
162  abs_com_pos.mul(abs_att, loc_com);
163  abs_com_pos += abs_pos;
164  my_com.mul(abs_com_pos, mass);
165  com += my_com;
166  }
167  return ret;
168 }
169 
Joint::parent
Joint * parent
pointer to the parent joint
Definition: chain.h:683
Joint::abs_pos
fVec3 abs_pos
absolute position
Definition: chain.h:741
fVec3::add
void add(const fVec3 &vec1, const fVec3 &vec2)
Definition: fMatrix3.cpp:888
Chain::root
Joint * root
Chain information.
Definition: chain.h:466
fVec3
3-element vector class.
Definition: fMatrix3.h:206
Chain::CalcVelocity
void CalcVelocity()
Definition: fk.cpp:41
fVec3::cross
void cross(const fVec3 &vec1, const fVec3 &vec2)
Cross product.
Definition: fMatrix3.cpp:944
Joint::rel_lin_acc
fVec3 rel_lin_acc
Definition: chain.h:730
fMat33::mul
void mul(const fMat33 &mat1, const fMat33 &mat2)
Definition: fMatrix3.cpp:694
Joint::rel_pos
fVec3 rel_pos
(initial) position in parent joint's frame (for 0/3/6 DOF joints)
Definition: chain.h:700
Joint::calc_position
void calc_position()
Definition: fk.cpp:21
Joint::child
Joint * child
pointer to the child joint
Definition: chain.h:685
fMat33
3x3 matrix class.
Definition: fMatrix3.h:29
Joint::rel_ang_vel
fVec3 rel_ang_vel
Definition: chain.h:729
Joint::total_com
double total_com(fVec3 &com, const char *chname)
Definition: fk.cpp:137
Chain::CalcPosition
void CalcPosition()
Forward kinematics.
Definition: fk.cpp:16
Joint::loc_com_vel
fVec3 loc_com_vel
com velocity in local frame
Definition: chain.h:745
Joint::loc_com
fVec3 loc_com
center of mass in local frame
Definition: chain.h:706
Joint::rel_att
fMat33 rel_att
(initial) orientation in parent joint's frame (for 0/3/6 DOF joints)
Definition: chain.h:701
Joint::CharName
char * CharName() const
Returns the character name.
Definition: chain.h:648
Joint::rel_ang_acc
fVec3 rel_ang_acc
Definition: chain.h:731
chain.h
Classes for defining open/closed kinematic chains.
Joint::calc_velocity
void calc_velocity()
Definition: fk.cpp:46
Joint::abs_att
fMat33 abs_att
absolute orientation
Definition: chain.h:742
fMat33::tran
friend fMat33 tran(const fMat33 &m)
Returns the transpose.
Definition: fMatrix3.cpp:607
Joint::loc_ang_acc
fVec3 loc_ang_acc
angular acceleration in local frame
Definition: chain.h:747
Joint::loc_lin_vel
fVec3 loc_lin_vel
linear velocity in local frame
Definition: chain.h:743
com
Chain::CalcAcceleration
void CalcAcceleration()
Definition: fk.cpp:75
Joint::brother
Joint * brother
pointer to the brother joint
Definition: chain.h:684
Joint::mass
double mass
mass
Definition: chain.h:704
Joint::loc_com_acc
fVec3 loc_com_acc
com acceleration in local frame
Definition: chain.h:748
Joint::calc_acceleration
void calc_acceleration()
Definition: fk.cpp:80
Joint::rel_lin_vel
fVec3 rel_lin_vel
Definition: chain.h:728
Joint::loc_ang_vel
fVec3 loc_ang_vel
angular velocity in local frame
Definition: chain.h:744
fVec3::zero
void zero()
Creates a zero vector.
Definition: fMatrix3.h:283
Joint::loc_lin_acc
fVec3 loc_lin_acc
linear acceleration in local frame
Definition: chain.h:746
fVec3::mul
void mul(const fVec3 &vec, double d)
Definition: fMatrix3.cpp:916
Chain::TotalCOM
double TotalCOM(fVec3 &com, const char *chname=0)
Center of mass of the chain.
Definition: fk.cpp:129


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:02