task-conti.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 */
16 
17 #include <sot/core/debug.hh>
18 #include <sot/core/factory.hh>
19 #include <sot/core/task-conti.hh>
20 
21 using namespace std;
22 using namespace dynamicgraph::sot;
23 using namespace dynamicgraph;
24 
26 
27 /* --------------------------------------------------------------------- */
28 /* --- CLASS ----------------------------------------------------------- */
29 /* --------------------------------------------------------------------- */
30 
31 TaskConti::TaskConti(const std::string &n)
32  : Task(n),
33  timeRef(TIME_REF_UNSIGNIFICANT),
34  mu(0),
35  controlPrevSIN(NULL, "sotTaskConti(" + n + ")::input(double)::q0") {
36  taskSOUT.setFunction(
37  boost::bind(&TaskConti::computeContiDesiredVelocity, this, _1, _2));
39 }
40 
42  VectorMultiBound &desvel2b, const sigtime_t &timecurr) {
43  sotDEBUG(15) << "# In {" << endl;
44 
45  dynamicgraph::Vector desvel = errorSOUT(timecurr);
46  const double &lambda = controlGainSIN(timecurr);
47 
48  try {
49  const dynamicgraph::Matrix &J = jacobianSOUT(timecurr);
50 
51  dynamicgraph::Vector deref(J.rows());
52  sotDEBUG(15) << "q0 = " << q0 << std::endl;
53  sotDEBUG(25) << "J = " << J << std::endl;
54  if (q0.size() != (J.cols() - 6)) throw; // TODO
55  for (size_type i = 0; i < J.rows(); ++i) {
56  deref(i) = 0;
57  for (size_type j = 6; j < J.cols(); ++j) deref(i) += J(i, j) * q0(j - 6);
58  }
59 
60  if (timeRef == TIME_REF_TO_BE_SET) {
61  timeRef = timecurr;
62  }
63  if (timeRef < 0) {
64  sotDEBUG(10) << "Time not used. " << std::endl;
65  throw 1;
66  }
67 
68  double dt = (double)(timeRef - timecurr);
69  dt *= mu / 200.0;
70  double contiGain = exp(dt);
71  double gain = (contiGain - 1) * lambda;
72 
73  sotDEBUG(25) << "T: ref=" << timeRef << ", cur=" << timecurr << std::endl;
74  sotDEBUG(25) << "Gains: l=" << lambda << ", expmu=" << contiGain
75  << std::endl;
76  sotDEBUG(25) << "e = " << deref << std::endl;
77 
78  desvel *= gain;
79  sotDEBUG(25) << "dedes: " << desvel << std::endl;
80  deref *= contiGain;
81  desvel += deref;
82  sotDEBUG(25) << "task: " << desvel << std::endl;
83 
84  desvel2b.resize(desvel.size());
85  for (size_type i = 0; i < desvel.size(); ++i) desvel2b[i] = desvel(i);
86 
87  sotDEBUG(15) << "# Out }" << endl;
88  return desvel2b;
89  } catch (...) {
90  const dynamicgraph::Vector &desvel = errorSOUT(timecurr);
91  const double &gain = controlGainSIN(timecurr);
92  desvel2b.resize(desvel.size());
93  for (size_type i = 0; i < desvel.size(); ++i)
94  desvel2b[i] = -gain * desvel(i);
95  return desvel2b;
96  }
97 }
98 
99 /* --- COMPUTATION ---------------------------------------------------------- */
100 /* --- COMPUTATION ---------------------------------------------------------- */
101 /* --- COMPUTATION ---------------------------------------------------------- */
102 
103 /* --- DISPLAY ------------------------------------------------------------ */
104 /* --- DISPLAY ------------------------------------------------------------ */
105 /* --- DISPLAY ------------------------------------------------------------ */
106 
107 void TaskConti::display(std::ostream &os) const {
108  os << "TaskConti " << name << " [t=" << timeRef << "] "
109  << ": " << endl;
110  os << "--- LIST --- " << std::endl;
111 
112  for (FeatureList_t::const_iterator iter = featureList.begin();
113  iter != featureList.end(); ++iter) {
114  os << "-> " << (*iter)->getName() << endl;
115  }
116 }
factory.hh
dynamicgraph::sot::Task::controlGainSIN
dynamicgraph::SignalPtr< double, sigtime_t > controlGainSIN
Definition: task.hh:110
dynamicgraph
exp
def exp(x)
J
J
dynamicgraph::sot::VectorMultiBound
std::vector< MultiBound > VectorMultiBound
Definition: multi-bound.hh:72
i
int i
dynamicgraph::sot::TaskConti::q0
dynamicgraph::Vector q0
Definition: task-conti.hh:56
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(TaskConti, "TaskConti")
dynamicgraph::Entity::name
std::string name
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
dynamicgraph::sot::Task::featureList
FeatureList_t featureList
Definition: task.hh:77
debug.hh
dynamicgraph::sot::TaskConti::computeContiDesiredVelocity
VectorMultiBound & computeContiDesiredVelocity(VectorMultiBound &task, const sigtime_t &time)
Definition: task-conti.cpp:41
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::TaskConti::TIME_REF_TO_BE_SET
@ TIME_REF_TO_BE_SET
Definition: task-conti.hh:52
dynamicgraph::sot::TaskAbstract::jacobianSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Matrix, sigtime_t > jacobianSOUT
Definition: task-abstract.hh:80
dynamicgraph::size_type
Matrix::Index size_type
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::Task::errorSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > errorSOUT
Definition: task.hh:113
dynamicgraph::sot::TaskConti
Definition: task-conti.hh:50
linear-algebra.h
dynamicgraph::sot::TaskConti::display
void display(std::ostream &os) const
Definition: task-conti.cpp:107
dynamicgraph::sot::double
double
Definition: fir-filter.cpp:49
dynamicgraph::sot::TaskAbstract::taskSOUT
dynamicgraph::SignalTimeDependent< VectorMultiBound, sigtime_t > taskSOUT
Definition: task-abstract.hh:78
dynamicgraph::sot::Task
Class that defines the basic elements of a task.
Definition: task.hh:72
dynamicgraph::sot
test-parameter-server.dt
float dt
Definition: test-parameter-server.py:14
dynamicgraph::sot::TaskConti::mu
double mu
Definition: task-conti.hh:55
task-conti.hh
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
dynamicgraph::sot::TaskConti::controlPrevSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > controlPrevSIN
Definition: task-conti.hh:74
n
Vec3f n
dynamicgraph::sot::TaskConti::timeRef
sigtime_t timeRef
Definition: task-conti.hh:54
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