smooth-reach.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 
11 #include <dynamic-graph/factory.h>
12 
13 #include <sot/core/debug.hh>
14 #include <sot/core/smooth-reach.hh>
15 
16 using namespace dynamicgraph;
17 using namespace dynamicgraph::sot;
18 
20 
21 SmoothReach::SmoothReach(const std::string &name)
22  : Entity(name)
23 
24  ,
25  start(0u),
26  goal(0u),
27  startTime(-1),
28  lengthTime(-1),
29  isStarted(false),
30  isParam(true)
31 
32  ,
33  smoothMode(2),
34  smoothParam(1.2)
35 
36  ,
37  startSIN(NULL, "SmoothReach(" + name + ")::input(vector)::start"),
38  goalSOUT(boost::bind(&SmoothReach::goalSOUT_function, this, _1, _2),
39  sotNOSIGNAL, "SmoothReach(" + name + ")::output(vector)::goal")
40 
41 {
42  sotDEBUGIN(5);
43 
45  initCommands();
46  goalSOUT.setNeedUpdateFromAllChildren(true);
47  sotDEBUGOUT(5);
48 }
49 
51  using namespace command;
52  addCommand("set",
54  docCommandVoid2("Set the curve.", "vector (goal)",
55  "size_type (duration)")));
57  docCommandVoid2("Set the parameter.",
58  "size_type (mode)",
59  "double (beta)")));
60 }
61 
62 double SmoothReach::smoothFunction(double x) {
63  switch (smoothMode) {
64  case 0:
65  return x;
66 
67  case 1: {
68  // const double smoothParam = 0.45;
69  return tanh(-smoothParam / x + smoothParam / (1 - x)) / 2 + 0.5;
70  }
71  case 2: {
72  // const double smoothParam = 1.5;
73  return atan(-smoothParam / x + smoothParam / (1 - x)) / M_PI + 0.5;
74  }
75  }
76  return 0;
77 }
78 
79 void SmoothReach::setSmoothing(const size_type &mode, const double &param) {
80  smoothMode = mode;
81  smoothParam = param;
82 }
83 
85  const sigtime_t &time) {
86  if (isParam) {
87  start = startSIN(time);
88  startTime = time;
89 
90  assert(start.size() == goal.size());
91  isParam = false;
92  isStarted = true;
93  }
94 
95  if (isStarted) {
96  double x = double(time - startTime) / (double)lengthTime;
97  if (x > 1) x = 1;
98  double x1 = smoothFunction(x);
99  double x0 = 1 - x1;
100  res = start * x0 + goal * x1;
101  }
102 
103  return res;
104 }
105 
107  const size_type &lengthDes) {
108  goal = goalDes;
109  lengthTime = lengthDes;
110  isParam = true;
111 }
112 
114 
116 
117 const size_type &SmoothReach::getStart(void) { return startTime; }
118 
119 void SmoothReach::display(std::ostream &os) const {
120  os << "Status: " << isStarted << isParam << std::endl
121  << "Goal: " << goal << "start: " << start << "Times: " << startTime << " "
122  << lengthTime << std::endl;
123 }
smooth-reach.hh
dynamicgraph::sot::SmoothReach::goalSOUT
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > goalSOUT
Definition: smooth-reach.hh:65
dynamicgraph::sot::SmoothReach::startTime
size_type startTime
Definition: smooth-reach.hh:52
dynamicgraph
dynamicgraph::Entity
boost
dynamicgraph::sot::SmoothReach::goal
dynamicgraph::Vector goal
Definition: smooth-reach.hh:51
dynamicgraph::sot::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeaturePosture, "FeaturePosture")
dynamicgraph::sot::SmoothReach::lengthTime
size_type lengthTime
Definition: smooth-reach.hh:52
debug.hh
res
res
sotDEBUGOUT
#define sotDEBUGOUT(level)
Definition: debug.hh:215
dynamicgraph::sot::SmoothReach::setSmoothing
void setSmoothing(const size_type &mode, const double &param)
Definition: smooth-reach.cpp:79
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::SmoothReach::getStart
const size_type & getStart(void)
Definition: smooth-reach.cpp:117
dynamicgraph::sot::SmoothReach::startSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > startSIN
Definition: smooth-reach.hh:61
sotDEBUGIN
#define sotDEBUGIN(level)
Definition: debug.hh:214
u
u
x
x
dynamicgraph::sot::SmoothReach::smoothMode
size_type smoothMode
Definition: smooth-reach.hh:54
dynamicgraph::sotNOSIGNAL
SignalArray< sigtime_t > sotNOSIGNAL(0)
dynamicgraph::size_type
Matrix::Index size_type
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::SmoothReach::isParam
bool isParam
Definition: smooth-reach.hh:53
dynamicgraph::sot::SmoothReach::set
void set(const dynamicgraph::Vector &goal, const size_type &length)
Definition: smooth-reach.cpp:106
makeCommandVoid2
CommandVoid2< E, T1, T2 > * makeCommandVoid2(E &entity, boost::function< void(const T1 &, const T2 &)> function, const std::string &docString)
dynamicgraph::sot::SmoothReach::smoothFunction
double smoothFunction(double x)
Definition: smooth-reach.cpp:62
docCommandVoid2
std::string docCommandVoid2(const std::string &doc, const std::string &type1, const std::string &type2)
dynamicgraph::sot::SmoothReach
Definition: smooth-reach.hh:45
dynamicgraph::sot::SmoothReach::display
virtual void display(std::ostream &os) const
Definition: smooth-reach.cpp:119
dynamicgraph::sot::double
double
Definition: fir-filter.cpp:49
dynamicgraph::sot::SmoothReach::goalSOUT_function
dynamicgraph::Vector & goalSOUT_function(dynamicgraph::Vector &goal, const sigtime_t &time)
Definition: smooth-reach.cpp:84
dynamicgraph::sot::SmoothReach::smoothParam
double smoothParam
Definition: smooth-reach.hh:55
M_PI
#define M_PI
dynamicgraph::sot
dynamicgraph::sot::SmoothReach::initCommands
void initCommands(void)
Definition: smooth-reach.cpp:50
x0
x0
dynamicgraph::sot::SmoothReach::start
dynamicgraph::Vector start
Definition: smooth-reach.hh:51
dynamicgraph::Entity::addCommand
void addCommand(const std::string &name, command::Command *command)
dynamicgraph::sot::SmoothReach::isStarted
bool isStarted
Definition: smooth-reach.hh:53
dynamicgraph::sot::SmoothReach::getGoal
const dynamicgraph::Vector & getGoal(void)
Definition: smooth-reach.cpp:113
all-commands.h
dynamicgraph::sot::SmoothReach::SmoothReach
SmoothReach(const std::string &name)
Definition: smooth-reach.cpp:21
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
dynamicgraph::sot::SmoothReach::getLength
const size_type & getLength(void)
Definition: smooth-reach.cpp:115
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