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 (const ExceptionSignal &e) {
76  }
77  os << " (" << TimeStep << ") ";
78 }
79 
80 /* --------------------------------------------------------------------- */
81 /* --------------------------------------------------------------------- */
82 /* --------------------------------------------------------------------- */
83 
85  sigtime_t 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, sigtime_t t) {
111  // sotDEBUGOUT(15) ??
112  controlSOUT(t);
113  position_error = position_error_;
114  return position_error;
115 }
116 
118  dynamicgraph::Vector &velocity_error, sigtime_t t) {
119  controlSOUT(t);
120  velocity_error = velocity_error_;
121  return velocity_error;
122 }
control-pd.hh
dynamicgraph::sot::ControlPD::positionSIN
SignalPtr< dynamicgraph::Vector, sigtime_t > positionSIN
Definition: control-pd.hh:70
dynamicgraph::sot::ControlPD::ControlPD
ControlPD(const std::string &name)
Definition: control-pd.cpp:33
dynamicgraph::sot::ControlPD::velocitySIN
SignalPtr< dynamicgraph::Vector, sigtime_t > velocitySIN
Definition: control-pd.hh:72
dynamicgraph::sot::ControlPD::KdSIN
SignalPtr< dynamicgraph::Vector, sigtime_t > KdSIN
Definition: control-pd.hh:69
dynamicgraph
dynamicgraph::sot::ControlPD::controlSOUT
SignalTimeDependent< dynamicgraph::Vector, sigtime_t > controlSOUT
Definition: control-pd.hh:74
dynamicgraph::Entity
dynamicgraph::sot::ControlPD::desiredpositionSIN
SignalPtr< dynamicgraph::Vector, sigtime_t > desiredpositionSIN
Definition: control-pd.hh:71
boost
dynamicgraph::sot::ControlPD::position_error_
dynamicgraph::Vector position_error_
Definition: control-pd.hh:80
dynamicgraph::sot::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeaturePosture, "FeaturePosture")
dynamicgraph::Entity::getName
const std::string & getName() const
debug.hh
tau
tau
dynamicgraph::sot::ControlPD::TimeStep
double TimeStep
Definition: control-pd.hh:65
sotDEBUGOUT
#define sotDEBUGOUT(level)
Definition: debug.hh:215
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::sot::ControlPD::init
void init(const double &step)
Definition: control-pd.cpp:61
dynamicgraph::sot::ControlPD::velocityErrorSOUT
SignalTimeDependent< dynamicgraph::Vector, sigtime_t > velocityErrorSOUT
Definition: control-pd.hh:76
dynamicgraph::sot::ControlPD::TIME_STEP_DEFAULT
static const double TIME_STEP_DEFAULT
Definition: control-pd.hh:55
sotDEBUGIN
#define sotDEBUGIN(level)
Definition: debug.hh:214
size
FCL_REAL size() const
Index
std::size_t Index
dynamicgraph::sot::ControlPD::getVelocityError
dynamicgraph::Vector & getVelocityError(dynamicgraph::Vector &velocity_error, sigtime_t t)
Definition: control-pd.cpp:117
dynamicgraph::sot::ControlPD::getPositionError
dynamicgraph::Vector & getPositionError(dynamicgraph::Vector &position_error, sigtime_t t)
Definition: control-pd.cpp:109
dynamicgraph::sot::ControlPD
Definition: control-pd.hh:46
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::ExceptionSignal
dynamicgraph::sot::ControlPD::velocity_error_
dynamicgraph::Vector velocity_error_
Definition: control-pd.hh:81
dynamicgraph::sot::ControlPD::desiredvelocitySIN
SignalPtr< dynamicgraph::Vector, sigtime_t > desiredvelocitySIN
Definition: control-pd.hh:73
dynamicgraph::sot
dynamicgraph::sot::ControlPD::display
virtual void display(std::ostream &os) const
Definition: control-pd.cpp:71
t
Transform3f t
dynamicgraph::sot::ControlPD::KpSIN
SignalPtr< dynamicgraph::Vector, sigtime_t > KpSIN
Definition: control-pd.hh:68
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
dynamicgraph::sot::ControlPD::computeControl
dynamicgraph::Vector & computeControl(dynamicgraph::Vector &tau, sigtime_t t)
Definition: control-pd.cpp:84
compile.name
name
Definition: compile.py:23
dynamicgraph::sot::ControlPD::positionErrorSOUT
SignalTimeDependent< dynamicgraph::Vector, sigtime_t > positionErrorSOUT
Definition: control-pd.hh:75


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