Skip to content

Commit fcdd0df

Browse files
jmirabelolivier-stasse
authored andcommitted
Code cleaning
1 parent ac1a34e commit fcdd0df

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/tools/device.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ void Device::integrate( const double & dt )
378378
if (controlInputType_==CONTROL_INPUT_NO_INTEGRATION)
379379
{
380380
assert(state_.size()==controlIN.size()+6);
381-
for( int i=0;i<controlIN.size();++i )
382-
state_(i+6) = controlIN(i);
381+
state_.tail(controlIN.size()) = controlIN;
383382
return;
384383
}
385384

@@ -389,29 +388,25 @@ void Device::integrate( const double & dt )
389388
// If control size is state size - 6, integrate joint angles,
390389
// if control and state are of same size, integrate 6 first degrees of
391390
// freedom as a translation and roll pitch yaw.
392-
unsigned int offset = 6;
393391

394392
if (controlInputType_==CONTROL_INPUT_TWO_INTEGRATION)
395393
{
396-
if(controlIN.size() == velocity_.size()) offset = 0;
397-
for( int i=0;i<controlIN.size();++i )
398-
{
399-
vel_control_(i) = velocity_(i+offset) + controlIN(i)*dt*0.5;
400-
velocity_(i+offset) = velocity_(i+offset) + controlIN(i)*dt;
401-
}
394+
// Position increment
395+
vel_control_ = velocity_.tail(controlIN.size()) + (0.5*dt)*controlIN;
396+
// Velocity integration.
397+
velocity_.tail(controlIN.size()) += controlIN*dt;
402398
}
403399
else
404400
{
405401
vel_control_ = controlIN;
406402
}
407403

408404
if (vel_control_.size() == state_.size()) {
409-
offset = 0;
410405
integrateRollPitchYaw(state_, vel_control_, dt);
411406
}
412407

413-
for( int i=6;i<state_.size();++i )
414-
{ state_(i) += (vel_control_(i-offset)*dt); }
408+
// Position integration
409+
state_.tail(controlIN.size()) += vel_control_ * dt;
415410
}
416411

417412
/* --- DISPLAY ------------------------------------------------------------ */

0 commit comments

Comments
 (0)