23 #include <yarp/os/Bottle.h>
24 #include <yarp/math/Math.h>
29 using namespace yarp::os;
30 using namespace yarp::sig;
31 using namespace yarp::math;
57 for (
size_t i=0; i<
F.size(); i++)
60 for (
size_t i=0; i<tappedDelays.size(); i++)
61 delete tappedDelays[i];
71 enabled=options.check(
"smith_predictor",Value(
"off")).asString()==
"on";
78 Vector Kp(chain.
getDOF(),1.0);
79 Vector Tz(chain.
getDOF(),0.0);
80 Vector Tw(chain.
getDOF(),0.0);
81 Vector Zeta(chain.
getDOF(),0.0);
82 for (
unsigned int i=0; i<chain.
getDOF(); i++)
83 tappedDelays.push_back(
new deque<double>);
85 double Ts=options.check(
"Ts",Value(0.01)).asFloat64();
87 Matrix lim(chain.
getDOF(),2);
93 for (
unsigned int j=0; j<chain.
getN(); j++)
95 if (!chain[j].isBlocked())
98 lim(i,0)=chain[j].getMin();
99 lim(i,1)=chain[j].getMax();
103 string entry_str(entry.str());
104 if (options.check(entry_str))
106 if (Bottle *params=options.find(entry_str).asList())
108 if (params->check(
"Kp"))
109 Kp[i]=params->find(
"Kp").asFloat64();
111 if (params->check(
"Tz"))
112 Tz[i]=params->find(
"Tz").asFloat64();
114 if (params->check(
"Tw"))
115 Tw[i]=params->find(
"Tw").asFloat64();
117 if (params->check(
"Zeta"))
118 Zeta[i]=params->find(
"Zeta").asFloat64();
120 if (params->check(
"Td"))
122 int depth=(int)ceil(params->find(
"Td").asFloat64()/Ts);
123 tappedDelays[i]->assign(depth,y0[i]);
143 double twoTs2=2.0*Ts2;
144 for (
unsigned int i=0; i<chain.
getDOF(); i++)
147 double _num_0=2.0*Tz[i]*Ts;
148 num[0]=Kp[i] * (Ts2 + _num_0);
149 num[1]=Kp[i] * twoTs2;
150 num[2]=Kp[i] * (Ts2 - _num_0);
152 double _den_0=4.0*Tw[i]*Tw[i];
153 double _den_1=2.0*_den_0;
154 double _den_2=4.0*Zeta[i]*Ts*Tw[i];
155 den[0]=Ts2 + _den_2 + _den_0;
156 den[1]=twoTs2 - _den_1;
157 den[2]=Ts2 - _den_2 + _den_0;
160 F.push_back(
new Filter(num,den,y01));
168 if (enabled && (tappedDelays.size()==y0.length()))
171 for (
size_t i=0; i<tappedDelays.size(); i++)
172 for (
size_t j=0; j<tappedDelays[i]->size(); j++)
173 tappedDelays[i]->at(j)=y0[i];
183 for (
size_t i=0; i<
F.size(); i++)
195 if (enabled && (tappedDelays.size()==u.length()))
198 for (
size_t i=0; i<
F.size(); i++)
200 Vector u1(1); u1[0]=u[i];
201 Vector _y=
F[i]->filt(u1);
205 Vector
y=I->integrate(_u);
206 Vector
out(
y.length());
207 for (
size_t i=0; i<
out.length(); i++)
209 tappedDelays[i]->push_back(
y[i]);
210 out[i]=
y[i]-tappedDelays[i]->front();
211 tappedDelays[i]->pop_front();
217 return zeros((
int)u.length());
void configure(const yarp::os::Property &options, iCub::iKin::iKinChain &chain)
yarp::sig::Vector computeCmd(const yarp::sig::Vector &u)
void restart(const yarp::sig::Vector &y0)
A class for defining a saturated integrator based on Tustin formula: .
A Base class for defining a Serial Link Chain.
yarp::sig::Vector getAng()
Returns the current free joint angles values.
unsigned int getN() const
Returns the number of Links belonging to the Chain.
unsigned int getDOF() const
Returns the current number of Chain's DOF.