feature-visual-point.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 /* --------------------------------------------------------------------- */
11 /* --- INCLUDE --------------------------------------------------------- */
12 /* --------------------------------------------------------------------- */
13 
14 /* --- SOT --- */
15 #include <sot/core/debug.hh>
17 #include <sot/core/factory.hh>
19 using namespace std;
20 using namespace dynamicgraph::sot;
21 using namespace dynamicgraph;
22 
24 
25 /* --------------------------------------------------------------------- */
26 /* --- CLASS ----------------------------------------------------------- */
27 /* --------------------------------------------------------------------- */
28 
29 FeatureVisualPoint::FeatureVisualPoint(const string &pointName)
30  : FeatureAbstract(pointName),
31  L(),
32  xySIN(NULL, "sotFeatureVisualPoint(" + name + ")::input(vector)::xy"),
33  ZSIN(NULL, "sotFeatureVisualPoint(" + name + ")::input(double)::Z"),
34  articularJacobianSIN(
35  NULL, "sotFeatureVisualPoint(" + name + ")::input(matrix)::Jq") {
36  ZSIN = 1.;
37 
41 
44 
46 }
47 
49  assert(isReferenceSet());
51 }
52 
54  assert(isReferenceSet());
56 }
57 
58 /* --------------------------------------------------------------------- */
59 /* --------------------------------------------------------------------- */
60 /* --------------------------------------------------------------------- */
61 
63  sotDEBUG(25) << "# In {" << endl;
64 
65  const Flags &fl = selectionSIN.access(time);
66 
67  dim = 0;
68  if (fl(0)) dim++;
69  if (fl(1)) dim++;
70 
71  sotDEBUG(25) << "# Out }" << endl;
72  return dim;
73 }
74 
79  sotDEBUG(15) << "# In {" << endl;
80 
81  sotDEBUG(15) << "Get selection flags." << endl;
82  const Flags &fl = selectionSIN(time);
83 
84  const size_type dim = dimensionSOUT(time);
85  L.resize(dim, 6);
86  std::size_t cursorL = 0;
87 
88  sotDEBUG(5) << std::endl;
89 
90  const double &Z = ZSIN(time);
91  sotDEBUG(5) << xySIN(time) << std::endl;
92  const double &x = xySIN(time)(0);
93  const double &y = xySIN(time)(1);
94 
95  if (Z < 0) {
97  "VisualPoint is behind the camera", " (Z=%.1f).",
98  Z));
99  }
100 
101  if (fabs(Z) < 1e-6) {
103  "VisualPoint Z coordinates is null", " (Z=%.3f)",
104  Z));
105  }
106 
107  if (fl(0)) {
108  L(cursorL, 0) = -1 / Z;
109  L(cursorL, 1) = 0;
110  L(cursorL, 2) = x / Z;
111  L(cursorL, 3) = x * y;
112  L(cursorL, 4) = -(1 + x * x);
113  L(cursorL, 5) = y;
114 
115  cursorL++;
116  }
117 
118  if (fl(1)) {
119  L(cursorL, 0) = 0;
120  L(cursorL, 1) = -1 / Z;
121  L(cursorL, 2) = y / Z;
122  L(cursorL, 3) = 1 + y * y;
123  L(cursorL, 4) = -x * y;
124  L(cursorL, 5) = -x;
125 
126  cursorL++;
127  }
128  sotDEBUG(15) << "L:" << endl << L << endl;
129  sotDEBUG(15) << "Jq:" << endl << articularJacobianSIN(time) << endl;
130 
131  J = L * articularJacobianSIN(time);
132 
133  sotDEBUG(15) << "# Out }" << endl;
134  return J;
135 }
136 
141  const Flags &fl = selectionSIN(time);
142  sotDEBUGIN(15);
143  error.resize(dimensionSOUT(time));
144  std::size_t cursorL = 0;
145 
146  if (!isReferenceSet()) {
148  "S* is not of adequate type."));
149  }
150 
151  if (fl(0)) {
152  error(cursorL++) = xySIN(time)(0) - getReference()->xySIN(time)(0);
153  }
154  if (fl(1)) {
155  error(cursorL++) = xySIN(time)(1) - getReference()->xySIN(time)(1);
156  }
157 
158  sotDEBUGOUT(15);
159  return error;
160 }
161 
162 void FeatureVisualPoint::display(std::ostream &os) const {
163  os << "VisualPoint <" << name << ">:";
164 
165  try {
166  const Vector &xy = xySIN.accessCopy();
167  const Flags &fl = selectionSIN.accessCopy();
168  if (fl(0)) os << " x=" << xy(0);
169  if (fl(1)) os << " y=" << xy(1);
170  } catch (const ExceptionAbstract &e) {
171  os << " XY or select not set.";
172  }
173 
174  try {
175  const double &z = ZSIN.accessCopy();
176  os << " Z=" << z << " ";
177  } catch (const ExceptionAbstract &e) {
178  os << " Z not set.";
179  }
180 }
181 
182 /*
183  * Local variables:
184  * c-basic-offset: 2
185  * End:
186  */
dynamicgraph::sot::FeatureAbstract::addDependenciesFromReference
virtual void addDependenciesFromReference(void)=0
factory.hh
dynamicgraph::SignalPtr::accessCopy
virtual const T & accessCopy() const
feature-visual-point.hh
dynamicgraph::sot::FeatureAbstract::errorSOUT
SignalTimeDependent< dynamicgraph::Vector, sigtime_t > errorSOUT
This signal returns the error between the desired value and the current value : .
Definition: feature-abstract.hh:185
dynamicgraph::sot::FeatureVisualPoint::xySIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > xySIN
Definition: feature-visual-point.hh:58
dynamicgraph
y
y
dynamicgraph::sot::FeatureReferenceHelper< FeatureVisualPoint >::getReference
FeatureVisualPoint * getReference(void)
Definition: feature-abstract.hh:240
L
L
J
J
dynamicgraph::sot::FeatureAbstract::selectionSIN
SignalPtr< Flags, sigtime_t > selectionSIN
This vector specifies which dimension are used to perform the computation. For instance let us assume...
Definition: feature-abstract.hh:173
dynamicgraph::Entity::name
std::string name
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
dynamicgraph::sot::FeatureAbstract::jacobianSOUT
SignalTimeDependent< dynamicgraph::Matrix, sigtime_t > jacobianSOUT
Jacobian of the error wrt the robot state: .
Definition: feature-abstract.hh:193
dynamicgraph::sot::FeatureVisualPoint::computeError
virtual dynamicgraph::Vector & computeError(dynamicgraph::Vector &res, sigtime_t time)
Definition: feature-visual-point.cpp:140
dynamicgraph::sot::FeatureVisualPoint::L
dynamicgraph::Matrix L
Definition: feature-visual-point.hh:54
dynamicgraph::sot::FeatureAbstract
This class gives the abstract definition of a feature.
Definition: feature-abstract.hh:76
dynamicgraph::sot::FeatureVisualPoint::computeJacobian
virtual dynamicgraph::Matrix & computeJacobian(dynamicgraph::Matrix &res, sigtime_t time)
Definition: feature-visual-point.cpp:78
dynamicgraph::sot::FeatureVisualPoint::ZSIN
dynamicgraph::SignalPtr< double, sigtime_t > ZSIN
Definition: feature-visual-point.hh:61
dynamicgraph::sot::FeatureVisualPoint::display
virtual void display(std::ostream &os) const
Definition: feature-visual-point.cpp:162
debug.hh
sotDEBUGOUT
#define sotDEBUGOUT(level)
Definition: debug.hh:215
dim
int dim
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::ExceptionAbstract
dynamicgraph::SignalTimeDependent::addDependency
virtual void addDependency(const SignalBase< Time > &signal)
sotDEBUGIN
#define sotDEBUGIN(level)
Definition: debug.hh:214
x
x
dynamicgraph::SignalTimeDependent::removeDependency
virtual void removeDependency(const SignalBase< Time > &signal)
dynamicgraph::size_type
Matrix::Index size_type
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::FeatureVisualPoint
Class that defines 2D visualPoint visual feature.
Definition: feature-visual-point.hh:46
dynamicgraph::sot::FeatureAbstract::removeDependenciesFromReference
virtual void removeDependenciesFromReference(void)=0
exception-feature.hh
dynamicgraph::sot::ExceptionFeature
Definition: exception-feature.hh:29
dynamicgraph::sot::FeatureVisualPoint::articularJacobianSIN
dynamicgraph::SignalPtr< dynamicgraph::Matrix, sigtime_t > articularJacobianSIN
Definition: feature-visual-point.hh:62
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeatureVisualPoint, "FeatureVisualPoint")
dynamicgraph::sot
dynamicgraph::sot::FeatureAbstract::getDimension
size_type getDimension(void) const
Shortest method.
Definition: feature-abstract.hh:121
dynamicgraph::sot::FeatureAbstract::dimensionSOUT
SignalTimeDependent< size_type, sigtime_t > dimensionSOUT
Returns the dimension of the feature as an output signal.
Definition: feature-abstract.hh:196
dynamicgraph::sot::Flags
Definition: flags.hh:33
dynamicgraph::sot::FeatureAbstract::isReferenceSet
virtual bool isReferenceSet(void) const
Definition: feature-abstract.hh:217
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
dynamicgraph::sot::ExceptionFeature::BAD_INIT
@ BAD_INIT
Definition: exception-feature.hh:35
compile.name
name
Definition: compile.py:23
Z
Z
sotDEBUG
#define sotDEBUG(level)
Definition: debug.hh:168


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