Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright 2010, |
3 |
|
|
* François Bleibel, |
4 |
|
|
* Olivier Stasse, |
5 |
|
|
* |
6 |
|
|
* CNRS/AIST |
7 |
|
|
* |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include <dynamic-graph/factory.h> |
11 |
|
|
|
12 |
|
|
#include <sot/core/com-freezer.hh> |
13 |
|
|
#include <sot/core/debug.hh> |
14 |
|
|
|
15 |
|
|
using namespace dynamicgraph; |
16 |
|
|
using namespace dynamicgraph::sot; |
17 |
|
|
|
18 |
|
✗ |
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CoMFreezer, "CoMFreezer"); |
19 |
|
|
|
20 |
|
✗ |
CoMFreezer::CoMFreezer(const std::string &name) |
21 |
|
|
: Entity(name), |
22 |
|
✗ |
m_lastCoM(3), |
23 |
|
✗ |
m_previousPGInProcess(false), |
24 |
|
✗ |
m_lastStopTime(-1) |
25 |
|
|
|
26 |
|
|
, |
27 |
|
✗ |
CoMRefSIN(NULL, "CoMFreezer(" + name + ")::input(vector)::CoMRef"), |
28 |
|
✗ |
PGInProcessSIN(NULL, |
29 |
|
✗ |
"CoMFreezer(" + name + ")::input(bool)::PGInProcess"), |
30 |
|
✗ |
freezedCoMSOUT(boost::bind(&CoMFreezer::computeFreezedCoM, this, _1, _2), |
31 |
|
✗ |
CoMRefSIN << PGInProcessSIN, |
32 |
|
✗ |
"CoMFreezer(" + name + ")::output(vector)::freezedCoM") { |
33 |
|
|
sotDEBUGIN(5); |
34 |
|
|
|
35 |
|
✗ |
signalRegistration(CoMRefSIN << PGInProcessSIN << freezedCoMSOUT); |
36 |
|
|
|
37 |
|
|
sotDEBUGOUT(5); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
✗ |
CoMFreezer::~CoMFreezer(void) { |
41 |
|
|
sotDEBUGIN(5); |
42 |
|
|
sotDEBUGOUT(5); |
43 |
|
✗ |
return; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
✗ |
dynamicgraph::Vector &CoMFreezer::computeFreezedCoM( |
47 |
|
|
dynamicgraph::Vector &freezedCoM, const int &time) { |
48 |
|
|
sotDEBUGIN(15); |
49 |
|
|
|
50 |
|
✗ |
unsigned PGInProcess = PGInProcessSIN(time); |
51 |
|
✗ |
if (PGInProcess) /* CoM unfreezed */ |
52 |
|
|
{ |
53 |
|
✗ |
m_lastCoM = CoMRefSIN(time); |
54 |
|
✗ |
m_previousPGInProcess = (PGInProcess == 0); |
55 |
|
|
} else { |
56 |
|
✗ |
if (m_previousPGInProcess) /* pg.inprocess switch from 1 to 0 */ |
57 |
|
|
{ |
58 |
|
✗ |
m_lastStopTime = time; |
59 |
|
✗ |
m_lastCoM = CoMRefSIN(time); |
60 |
|
✗ |
m_previousPGInProcess = (PGInProcess == 0); |
61 |
|
✗ |
} else if (time < m_lastStopTime + 200) /* keep updating for 1s */ |
62 |
|
|
{ |
63 |
|
✗ |
m_lastCoM = CoMRefSIN(time); |
64 |
|
|
} |
65 |
|
|
} |
66 |
|
|
|
67 |
|
✗ |
freezedCoM = m_lastCoM; |
68 |
|
|
|
69 |
|
|
sotDEBUGOUT(15); |
70 |
|
|
|
71 |
|
✗ |
if (m_lastStopTime < 0) { |
72 |
|
✗ |
m_lastCoM = CoMRefSIN(time); |
73 |
|
✗ |
m_lastStopTime = time; |
74 |
|
✗ |
freezedCoM = m_lastCoM; |
75 |
|
✗ |
return freezedCoM; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
✗ |
return m_lastCoM; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
✗ |
void CoMFreezer::display(std::ostream &os) const { |
82 |
|
✗ |
os << "CoMFreezer " << getName() << "." << std::endl; |
83 |
|
|
} |
84 |
|
|
|