sot-talos-balance  2.0.5
Collection of dynamic-graph entities aimed at implementing balance control on talos.
delay.hh
Go to the documentation of this file.
1 // Copyright 2018 CNRS - Airbus SAS
2 // Author: Joseph Mirabel
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 
8 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 
11 // 2. Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifndef __sot_talos_balance_delay_H__
28 #define __sot_talos_balance_delay_H__
29 
30 #include <dynamic-graph/command-bind.h>
31 #include <dynamic-graph/entity.h>
32 #include <dynamic-graph/factory.h>
33 #include <dynamic-graph/signal-ptr.h>
34 #include <dynamic-graph/signal.h>
35 
36 #if defined(WIN32)
37 #if defined(delay_EXPORTS)
38 #define DELAY_EXPORT __declspec(dllexport)
39 #else
40 #define DELAY_EXPORT __declspec(dllimport)
41 #endif
42 #else
43 #define DELAY_EXPORT
44 #endif
45 
46 namespace dynamicgraph {
47 namespace sot {
48 namespace talos_balance {
50 template <typename Value, typename Time = int>
51 class DELAY_EXPORT Delay : public dynamicgraph::Entity {
52  DYNAMIC_GRAPH_ENTITY_DECL();
53 
54  Delay(const std::string& name)
55  : Entity(name),
56  sin(NULL, "Delay(" + name + ")::input(unspecified)::sin"),
57  currentOUT("Delay(" + name + ")::output(unspecified)::current"),
58  previousOUT("Delay(" + name + ")::output(unspecified)::previous") {
59  currentOUT.setFunction(boost::bind(&Delay::current, this, _1, _2));
60  previousOUT.setFunction(boost::bind(&Delay::previous, this, _1, _2));
61  signalRegistration(sin << currentOUT << previousOUT);
62 
63  using command::makeCommandVoid1;
64  std::string docstring =
65  "\n"
66  " Set current value in memory\n";
67  addCommand("setMemory",
68  makeCommandVoid1(*this, &Delay::setMemory, docstring));
69  }
70 
71  ~Delay() {}
72 
74  virtual std::string getDocString() const {
75  return "Enable delayed signal in SoT.\n"
76  "Signal previous at time t+1 will return the value of signal "
77  "current "
78  " at time <= t (the last time signal current was called).";
79  }
80 
81  void setMemory(const Value& val) { mem = val; }
82 
83  private:
84  Value& current(Value& res, const Time& time) {
85  previousOUT.access(time);
86  res = sin.access(time);
87  mem = res;
88  return res;
89  }
90 
91  Value& previous(Value& res, const Time&) {
92  res = mem;
93  return res;
94  }
95 
96  Value mem;
97  SignalPtr<Value, Time> sin;
98  Signal<Value, Time> currentOUT, previousOUT;
99 };
100 
102 } // namespace talos_balance
103 } // namespace sot
104 } // namespace dynamicgraph
105 
106 #endif // #ifndef __sot_talos_balance_simple_pid_H__
sot_talos_balance.test.appli_admittance_end_effector.sot
sot
Definition: appli_admittance_end_effector.py:117
dynamicgraph
Definition: treeview.dox:24
dynamicgraph::sot::talos_balance::DelayVector
Delay< Vector, int > DelayVector
Definition: delay.hh:101
dynamicgraph::sot::talos_balance::Delay
Delay.
Definition: delay.hh:51
sot_talos_balance.test.appli_dcm_zmp_control.name
name
Definition: appli_dcm_zmp_control.py:298
DELAY_EXPORT
#define DELAY_EXPORT
Definition: delay.hh:43