clamp-workspace.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #include <cmath>
12 
13 using namespace std;
14 
15 #include <dynamic-graph/factory.h>
16 
17 using namespace dynamicgraph::sot;
18 using namespace dynamicgraph;
19 
21 
22 ClampWorkspace::ClampWorkspace(const string &fName)
23  : Entity(fName),
24  positionrefSIN(
25  NULL, "ClampWorkspace(" + name + ")::input(double)::positionref"),
26  positionSIN(NULL, "ClampWorkspace(" + name + ")::input(double)::position")
27 
28  ,
29  alphaSOUT(boost::bind(&ClampWorkspace::computeOutput, this, _1, _2),
30  positionrefSIN << positionSIN,
31  "ClampWorkspace(" + name + ")::output(vector)::alpha")
32 
33  ,
34  alphabarSOUT(boost::bind(&ClampWorkspace::computeOutputBar, this, _1, _2),
35  positionrefSIN << positionSIN,
36  "ClampWorkspace(" + name + ")::output(vector)::alphabar")
37 
38  ,
39  handrefSOUT(boost::bind(&ClampWorkspace::computeRef, this, _1, _2),
40  positionrefSIN << positionSIN,
41  "ClampWorkspace(" + name + ")::output(vector)::ref")
42 
43  ,
44  timeUpdate(0)
45 
46  ,
47  alpha(6, 6),
48  alphabar(6, 6)
49 
50  ,
51  pd(3)
52 
53  ,
54  beta(1),
55  scale(0),
56  dm_min(0.019),
57  dm_max(0.025),
58  dm_min_yaw(0.019),
59  dm_max_yaw(0.119),
60  theta_min(-30. * 3.14159 / 180.),
61  theta_max(5. * 3.14159 / 180.),
62  mode(1),
63  frame(FRAME_POINT)
64 
65 {
66  alpha.setZero();
67  alphabar.fill(1.);
68  bounds[0] = std::make_pair(0.15, 0.5);
69  bounds[1] = std::make_pair(-0.4, -0.25);
70  bounds[2] = std::make_pair(0.15, 0.55);
71 
73  << handrefSOUT);
74 }
75 
77  if (time <= timeUpdate) {
78  return;
79  }
80 
81  alpha.setZero();
82  alphabar.setIdentity();
83 
84  const MatrixHomogeneous &posref = positionrefSIN.access(time);
85  const MatrixHomogeneous &pos = positionSIN.access(time);
86 
87  MatrixHomogeneous prefMw = posref.inverse(Eigen::Affine);
88  prefMp = prefMw * pos;
89  Vector x(prefMp.translation());
90 
91  for (size_type i = 0; i < 3; ++i) {
92  double check_min = std::max(x(i) - bounds[i].first, 0.);
93  double check_max = std::max(bounds[i].second - x(i), 0.);
94  double dm = std::min(check_min, check_max);
95 
96  double Y = (dm - dm_min) / (dm_max - dm_min);
97  if (Y < 0) {
98  Y = 0;
99  }
100  if (Y > 1) {
101  Y = 1;
102  }
103 
104  switch (mode) {
105  case 0:
106  alpha(i, i) = 0;
107  alphabar(i, i) = 1;
108  break;
109  case 1:
110  alpha(i, i) = 1;
111  alphabar(i, i) = 0;
112  break;
113  case 2:
114  default:
115  alpha(i, i) = 0.5 * (1 + tanh(1 / Y - 1 / (1 - Y)));
116  alphabar(i, i) = 1 - alpha(i);
117  }
118 
119  if (i == 2) {
120  Y = (dm - dm_min_yaw) / (dm_max_yaw - dm_min_yaw);
121  if (Y < 0) {
122  Y = 0;
123  }
124  if (Y > 1) {
125  Y = 1;
126  }
127  if (mode == 2) {
128  alpha(i + 3, i + 3) = 0.5 * (1 + tanh(1 / Y - 1 / (1 - Y)));
129  alphabar(i + 3, i + 3) = 1 - alpha(i + 3);
130  }
131  }
132  }
133 
134  if (frame == FRAME_POINT) {
135  MatrixHomogeneous prefMp_tmp = prefMp;
136  MatrixHomogeneous pMpref = prefMp.inverse(Eigen::Affine);
137  for (size_type i = 0; i < 3; ++i) {
138  pMpref(i, 3) = 0;
139  prefMp_tmp(i, 3) = 0;
140  }
141 
142  MatrixTwist pTpref;
143  buildFrom(pMpref, pTpref);
144  MatrixTwist prefTp;
145  buildFrom(prefMp_tmp, prefTp);
146 
147  Matrix tmp;
148  tmp = alpha * prefTp;
149  alpha = pTpref * tmp;
150 
151  tmp = alphabar * prefTp;
152  alphabar = pTpref * tmp;
153  }
154 
155  for (size_type i = 0; i < 3; ++i) {
156  pd(i) = 0.5 * (bounds[i].first + bounds[i].second);
157  }
158 
160  rpy(0) = 0;
161  rpy(1) = -3.14159256 / 2;
162  rpy(2) = theta_min + (theta_max - theta_min) * (x(1) - bounds[1].first) /
163  (bounds[1].second - bounds[1].first);
164 
165  Eigen::Affine3d _Rd(Eigen::AngleAxisd(rpy(2), Eigen::Vector3d::UnitZ()) *
166  Eigen::AngleAxisd(rpy(1), Eigen::Vector3d::UnitY()) *
167  Eigen::AngleAxisd(rpy(0), Eigen::Vector3d::UnitX()));
168  Rd = _Rd.linear();
169 
170  Eigen::Affine3d _tmpaffine;
171  _tmpaffine = Eigen::Translation3d(pd);
172 
173  handref = (_tmpaffine * _Rd);
174  timeUpdate = time;
175 }
176 
178  update(time);
179  res = alpha;
180  return res;
181 }
182 
184  update(time);
185  res = alphabar;
186  return res;
187 }
188 
190  sigtime_t time) {
191  update(time);
192  res = handref;
193  return res;
194 }
195 
196 void ClampWorkspace::display(std::ostream &os) const {
197  os << "ClampWorkspace<" << name << ">" << endl << endl;
198  os << "alpha: " << alpha << endl;
199  os << "pos in ws: " << prefMp << endl;
200  os << "bounds: " << bounds[0].first << " " << bounds[0].second << " "
201  << bounds[1].first << " " << bounds[1].second << " " << bounds[2].first
202  << " " << bounds[2].second << endl;
203 }
dynamicgraph::sot::ClampWorkspace::computeRef
virtual MatrixHomogeneous & computeRef(MatrixHomogeneous &res, sigtime_t time)
Definition: clamp-workspace.cpp:189
rpy
dynamicgraph::sot::ClampWorkspace::positionrefSIN
dynamicgraph::SignalPtr< MatrixHomogeneous, sigtime_t > positionrefSIN
Definition: clamp-workspace.hh:54
dynamicgraph::sot::ClampWorkspace::alphabarSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Matrix, sigtime_t > alphabarSOUT
Definition: clamp-workspace.hh:58
dynamicgraph::sot::ClampWorkspace::bounds
std::pair< double, double > bounds[3]
Definition: clamp-workspace.hh:97
dynamicgraph::sot::MatrixHomogeneous
Eigen::Transform< double, 3, Eigen::Affine > SOT_CORE_EXPORT MatrixHomogeneous
Definition: matrix-geometry.hh:75
dynamicgraph::sot::ClampWorkspace::timeUpdate
sigtime_t timeUpdate
Definition: clamp-workspace.hh:76
dynamicgraph
dynamicgraph::sot::ClampWorkspace::display
virtual void display(std::ostream &) const
Definition: clamp-workspace.cpp:196
i
int i
dynamicgraph::sot::ClampWorkspace::theta_min
double theta_min
Definition: clamp-workspace.hh:91
dynamicgraph::Entity
dynamicgraph::sot::ClampWorkspace::alphaSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Matrix, sigtime_t > alphaSOUT
Definition: clamp-workspace.hh:56
boost
dynamicgraph::sot::ClampWorkspace::update
void update(sigtime_t time)
Definition: clamp-workspace.cpp:76
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(ClampWorkspace, "ClampWorkspace")
dynamicgraph::sot::ClampWorkspace::dm_min
double dm_min
Definition: clamp-workspace.hh:87
dynamicgraph::Entity::name
std::string name
dynamicgraph::sot::ClampWorkspace::mode
size_type mode
Definition: clamp-workspace.hh:93
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
dynamicgraph::sot::ClampWorkspace::positionSIN
dynamicgraph::SignalPtr< MatrixHomogeneous, sigtime_t > positionSIN
Definition: clamp-workspace.hh:55
dynamicgraph::sot::ClampWorkspace::alpha
dynamicgraph::Matrix alpha
Definition: clamp-workspace.hh:78
dynamicgraph::sot::ClampWorkspace::handref
MatrixHomogeneous handref
Definition: clamp-workspace.hh:83
dynamicgraph::sot::ClampWorkspace
Definition: clamp-workspace.hh:47
dynamicgraph::sot::ClampWorkspace::dm_min_yaw
double dm_min_yaw
Definition: clamp-workspace.hh:89
clamp-workspace.hh
dynamicgraph::sot::buildFrom
void buildFrom(const MatrixHomogeneous &MH, MatrixTwist &MT)
Definition: matrix-geometry.hh:88
res
res
dynamicgraph::SignalPtr::access
virtual const T & access(const Time &t)
dynamicgraph::sot::ClampWorkspace::alphabar
dynamicgraph::Matrix alphabar
Definition: clamp-workspace.hh:79
dynamicgraph::sot::VectorRollPitchYaw
Eigen::Vector3d SOT_CORE_EXPORT VectorRollPitchYaw
Definition: matrix-geometry.hh:80
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::ClampWorkspace::pd
dynamicgraph::Vector pd
Definition: clamp-workspace.hh:81
dynamicgraph::sot::ClampWorkspace::FRAME_POINT
@ FRAME_POINT
Definition: clamp-workspace.hh:95
dynamicgraph::sot::ClampWorkspace::dm_max_yaw
double dm_max_yaw
Definition: clamp-workspace.hh:90
x
x
dynamicgraph::sot::ClampWorkspace::Rd
MatrixRotation Rd
Definition: clamp-workspace.hh:82
pos
pos
dynamicgraph::size_type
Matrix::Index size_type
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::ClampWorkspace::frame
enum dynamicgraph::sot::ClampWorkspace::@0 frame
dynamicgraph::sot::ClampWorkspace::prefMp
MatrixHomogeneous prefMp
Definition: clamp-workspace.hh:80
dynamicgraph::sot::ClampWorkspace::computeOutputBar
virtual dynamicgraph::Matrix & computeOutputBar(dynamicgraph::Matrix &res, sigtime_t time)
Definition: clamp-workspace.cpp:183
dynamicgraph::sot::MatrixTwist
Eigen::Matrix< double, 6, 6 > SOT_CORE_EXPORT MatrixTwist
Definition: matrix-geometry.hh:82
Y
Y
dynamicgraph::sot::ClampWorkspace::dm_max
double dm_max
Definition: clamp-workspace.hh:88
dynamicgraph::sot::ClampWorkspace::theta_max
double theta_max
Definition: clamp-workspace.hh:92
dynamicgraph::sot
dynamicgraph::sot::ClampWorkspace::handrefSOUT
dynamicgraph::SignalTimeDependent< MatrixHomogeneous, sigtime_t > handrefSOUT
Definition: clamp-workspace.hh:59
dynamicgraph::sot::ClampWorkspace::computeOutput
virtual dynamicgraph::Matrix & computeOutput(dynamicgraph::Matrix &res, sigtime_t time)
Definition: clamp-workspace.cpp:177
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
compile.name
name
Definition: compile.py:23


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31