control-pd.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 /* SOT */
11 #include <sot/core/control-pd.hh>
12 
13 /* --------------------------------------------------------------------- */
14 /* --------------------------------------------------------------------- */
15 /* --------------------------------------------------------------------- */
16 #include <dynamic-graph/factory.h>
17 
18 #include <sot/core/debug.hh>
19 
20 using namespace dynamicgraph::sot;
21 using namespace dynamicgraph;
22 
24 
25 const double ControlPD::TIME_STEP_DEFAULT = .001;
26 
27 /* --------------------------------------------------------------------- */
28 /* --------------------------------------------------------------------- */
29 /* --------------------------------------------------------------------- */
30 
31 #define __SOT_ControlPD_INIT
32 
33 ControlPD::ControlPD(const std::string &name)
34  : Entity(name),
35  TimeStep(0),
36  KpSIN(NULL, "ControlPD(" + name + ")::input(vector)::Kp"),
37  KdSIN(NULL, "ControlPD(" + name + ")::input(vector)::Kd"),
38  positionSIN(NULL, "ControlPD(" + name + ")::input(vector)::position"),
39  desiredpositionSIN(
40  NULL, "ControlPD(" + name + ")::input(vector)::desired_position"),
41  velocitySIN(NULL, "ControlPD(" + name + ")::input(vector)::velocity"),
42  desiredvelocitySIN(
43  NULL, "ControlPD(" + name + ")::input(vector)::desired_velocity"),
44  controlSOUT(boost::bind(&ControlPD::computeControl, this, _1, _2),
45  KpSIN << KdSIN << positionSIN << desiredpositionSIN
46  << velocitySIN << desiredvelocitySIN,
47  "ControlPD(" + name + ")::output(vector)::control"),
48  positionErrorSOUT(
49  boost::bind(&ControlPD::getPositionError, this, _1, _2), controlSOUT,
50  "ControlPD(" + name + ")::output(vector)::position_error"),
51  velocityErrorSOUT(
52  boost::bind(&ControlPD::getVelocityError, this, _1, _2), controlSOUT,
53  "ControlPD(" + name + ")::output(vector)::velocity_error") {
54  init(TimeStep);
59 }
60 
61 void ControlPD::init(const double &Stept) {
62  TimeStep = Stept;
63 
64  return;
65 }
66 
67 /* --------------------------------------------------------------------- */
68 /* --------------------------------------------------------------------- */
69 /* --------------------------------------------------------------------- */
70 
71 void ControlPD::display(std::ostream &os) const {
72  os << "ControlPD " << getName();
73  try {
74  os << "control = " << controlSOUT;
75  } catch (ExceptionSignal e) {
76  }
77  os << " (" << TimeStep << ") ";
78 }
79 
80 /* --------------------------------------------------------------------- */
81 /* --------------------------------------------------------------------- */
82 /* --------------------------------------------------------------------- */
83 
85  int t) {
86  sotDEBUGIN(15);
87  const dynamicgraph::Vector &Kp = KpSIN(t);
88  const dynamicgraph::Vector &Kd = KdSIN(t);
89  const dynamicgraph::Vector &position = positionSIN(t);
90  const dynamicgraph::Vector &desired_position = desiredpositionSIN(t);
91  const dynamicgraph::Vector &velocity = velocitySIN(t);
92  const dynamicgraph::Vector &desired_velocity = desiredvelocitySIN(t);
93 
95  tau.resize(size);
96  position_error_.resize(size);
97  velocity_error_.resize(size);
98 
99  position_error_.array() = desired_position.array() - position.array();
100  velocity_error_.array() = desired_velocity.array() - velocity.array();
101 
102  tau.array() = position_error_.array() * Kp.array() +
103  velocity_error_.array() * Kd.array();
104 
105  sotDEBUGOUT(15);
106  return tau;
107 }
108 
110  dynamicgraph::Vector &position_error, int t) {
111  // sotDEBUGOUT(15) ??
112  controlSOUT(t);
113  position_error = position_error_;
114  return position_error;
115 }
116 
118  dynamicgraph::Vector &velocity_error, int t) {
119  controlSOUT(t);
120  velocity_error = velocity_error_;
121  return velocity_error;
122 }
Eigen::VectorXd Vector
dynamicgraph::Vector velocity_error_
Definition: control-pd.hh:81
static const double TIME_STEP_DEFAULT
Definition: control-pd.hh:55
dynamicgraph::Vector & getVelocityError(dynamicgraph::Vector &velocity_error, int t)
Definition: control-pd.cpp:117
dynamicgraph::Vector & getPositionError(dynamicgraph::Vector &position_error, int t)
Definition: control-pd.cpp:109
SignalTimeDependent< dynamicgraph::Vector, int > velocityErrorSOUT
Definition: control-pd.hh:76
void signalRegistration(const SignalArray< int > &signals)
#define sotDEBUGOUT(level)
Definition: debug.hh:212
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeaturePosture, "FeaturePosture")
#define sotDEBUGIN(level)
Definition: debug.hh:211
dynamicgraph::Vector & computeControl(dynamicgraph::Vector &tau, int t)
Definition: control-pd.cpp:84
ControlPD(const std::string &name)
Definition: control-pd.cpp:33
SignalPtr< dynamicgraph::Vector, int > KpSIN
Definition: control-pd.hh:68
SignalPtr< dynamicgraph::Vector, int > desiredvelocitySIN
Definition: control-pd.hh:73
SignalPtr< dynamicgraph::Vector, int > desiredpositionSIN
Definition: control-pd.hh:71
virtual void display(std::ostream &os) const
Definition: control-pd.cpp:71
void init(const double &step)
Definition: control-pd.cpp:61
FCL_REAL size() const
SignalPtr< dynamicgraph::Vector, int > velocitySIN
Definition: control-pd.hh:72
const std::string & getName() const
SignalPtr< dynamicgraph::Vector, int > KdSIN
Definition: control-pd.hh:69
Transform3f t
std::size_t Index
SignalTimeDependent< dynamicgraph::Vector, int > controlSOUT
Definition: control-pd.hh:74
SignalTimeDependent< dynamicgraph::Vector, int > positionErrorSOUT
Definition: control-pd.hh:75
dynamicgraph::Vector position_error_
Definition: control-pd.hh:80
SignalPtr< dynamicgraph::Vector, int > positionSIN
Definition: control-pd.hh:70


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26