Skip to content

Commit 6832a1b

Browse files
author
earlaud
committed
Propper use of tail and head for static size slices
1 parent 33a1cdd commit 6832a1b

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

include/simple-mpc/inverse-dynamics.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ namespace simple_mpc
157157
const pinocchio::SE3 base_pose(
158158
pinocchio::SE3::Quaternion(q_target[6], q_target[3], q_target[4], q_target[5]), q_target.head<3>());
159159
tsid::math::SE3ToVector(base_pose, sampleBase_.pos);
160-
sampleBase_.setDerivative(v_target.head(6));
161-
sampleBase_.setSecondDerivative(a_target.head(6));
160+
sampleBase_.setDerivative(v_target.head<6>());
161+
sampleBase_.setSecondDerivative(a_target.head<6>());
162162
baseTask_->setReference(sampleBase_);
163163

164164
// Foot contacts

src/centroidal-dynamics.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ namespace simple_mpc
219219
QuadraticResidualCost * qca = cs->getComponent<QuadraticResidualCost>("angular_mom_cost");
220220
AngularMomentumResidual * cfa = qca->getResidual<AngularMomentumResidual>();
221221

222-
v.head(3) = cfm->getReference() / model_handler_.getMass();
223-
v.tail(3) = cfa->getReference() / model_handler_.getMass();
222+
v.head<3>() = cfm->getReference() / model_handler_.getMass();
223+
v.tail<3>() = cfa->getReference() / model_handler_.getMass();
224224
return v;
225225
}
226226

@@ -234,8 +234,8 @@ namespace simple_mpc
234234
QuadraticResidualCost * qca = cs->getComponent<QuadraticResidualCost>("angular_mom_cost");
235235
AngularMomentumResidual * cfa = qca->getResidual<AngularMomentumResidual>();
236236

237-
cfm->setReference(velocity_base.head(3) * model_handler_.getMass());
238-
cfa->setReference(velocity_base.tail(3) * model_handler_.getMass());
237+
cfm->setReference(velocity_base.head<3>() * model_handler_.getMass());
238+
cfa->setReference(velocity_base.tail<3>() * model_handler_.getMass());
239239
}
240240

241241
const Eigen::VectorXd CentroidalOCP::getPoseBase(const std::size_t t)
@@ -252,7 +252,7 @@ namespace simple_mpc
252252
CostStack * cs = getCostStack(t);
253253
QuadraticResidualCost * qrc = cs->getComponent<QuadraticResidualCost>("com_cost");
254254
CentroidalCoMResidual * cfr = qrc->getResidual<CentroidalCoMResidual>();
255-
com_ref_ = pose_base.head(3);
255+
com_ref_ = pose_base.head<3>();
256256
cfr->setReference(com_ref_);
257257
}
258258

@@ -292,14 +292,14 @@ namespace simple_mpc
292292
void CentroidalOCP::setReferenceState(const std::size_t t, const ConstVectorRef & x_ref)
293293
{
294294
assert(x_ref.size() == 9 && "x_ref not of the right size");
295-
setPoseBase(t, x_ref.head(3));
296-
setVelocityBase(t, x_ref.tail(6));
295+
setPoseBase(t, x_ref.head<3>());
296+
setVelocityBase(t, x_ref.tail<6>());
297297
}
298298

299299
const ConstVectorRef CentroidalOCP::getReferenceState(const std::size_t t)
300300
{
301-
x0_.head(3) = getPoseBase(t);
302-
x0_.tail(6) = getVelocityBase(t);
301+
x0_.head<3>() = getPoseBase(t);
302+
x0_.tail<6>() = getVelocityBase(t);
303303
return x0_;
304304
}
305305

src/fulldynamics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ namespace simple_mpc
343343
{
344344
CostStack * cs = getCostStack(t);
345345
QuadraticStateCost * qc = cs->getComponent<QuadraticStateCost>("state_cost");
346-
return qc->getTarget().head(7);
346+
return qc->getTarget().head<7>();
347347
};
348348

349349
void FullDynamicsOCP::setPoseBase(const std::size_t t, const ConstVectorRef & pose_base)
@@ -355,7 +355,7 @@ namespace simple_mpc
355355
CostStack * cs = getCostStack(t);
356356
QuadraticStateCost * qc = cs->getComponent<QuadraticStateCost>("state_cost");
357357
x0_ = getReferenceState(t);
358-
x0_.head(7) = pose_base;
358+
x0_.head<7>() = pose_base;
359359
qc->setTarget(x0_);
360360
}
361361

src/kinodynamics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ namespace simple_mpc
287287
{
288288
CostStack * cs = getCostStack(t);
289289
QuadraticStateCost * qc = cs->getComponent<QuadraticStateCost>("state_cost");
290-
return qc->getTarget().head(7);
290+
return qc->getTarget().head<7>();
291291
};
292292

293293
void KinodynamicsOCP::setPoseBase(const std::size_t t, const ConstVectorRef & pose_base)
@@ -299,7 +299,7 @@ namespace simple_mpc
299299
CostStack * cs = getCostStack(t);
300300
QuadraticStateCost * qc = cs->getComponent<QuadraticStateCost>("state_cost");
301301
x0_ = getReferenceState(t);
302-
x0_.head(7) = pose_base;
302+
x0_.head<7>() = pose_base;
303303
qc->setTarget(x0_);
304304
}
305305

src/mpc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ namespace simple_mpc
288288
-(data_handler_->getRefFootPose(name).translation()[1] - data_handler_->getBaseFramePose().translation()[1]);
289289
twist_vect_[1] =
290290
data_handler_->getRefFootPose(name).translation()[0] - data_handler_->getBaseFramePose().translation()[0];
291-
next_pose_.head(2) = data_handler_->getRefFootPose(name).translation().head(2);
292-
next_pose_.head(2) += (velocity_base_.head(2) + velocity_base_[5] * twist_vect_)
293-
* (settings_.T_fly + settings_.T_contact) * settings_.timestep;
291+
next_pose_.head<2>() = data_handler_->getRefFootPose(name).translation().head<2>();
292+
next_pose_.head<2>() += (velocity_base_.head<2>() + velocity_base_[5] * twist_vect_)
293+
* (settings_.T_fly + settings_.T_contact) * settings_.timestep;
294294
next_pose_[2] = data_handler_->getFootPose(name).translation()[2];
295295

296296
foot_trajectories_.updateTrajectory(

src/ocp-handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ namespace simple_mpc
132132

133133
if (terminal_constraint)
134134
{
135-
createTerminalConstraint(x0.head(3));
135+
createTerminalConstraint(x0.head<3>());
136136
}
137137
}
138138
} // namespace simple_mpc

src/robot-handler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ namespace simple_mpc
121121
RobotDataHandler::CentroidalStateVector RobotDataHandler::getCentroidalState() const
122122
{
123123
RobotDataHandler::CentroidalStateVector x_centroidal;
124-
x_centroidal.head(3) = data_.com[0];
125-
x_centroidal.segment(3, 3) = data_.hg.linear();
126-
x_centroidal.tail(3) = data_.hg.angular();
124+
x_centroidal.head<3>() = data_.com[0];
125+
x_centroidal.segment<3>(3) = data_.hg.linear();
126+
x_centroidal.tail<3>() = data_.hg.angular();
127127
return x_centroidal;
128128
}
129129

0 commit comments

Comments
 (0)