Skip to content

Commit ccd1b90

Browse files
committed
fixed ik controller
1 parent eead98b commit ccd1b90

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

whole_body_controllers/src/ik_controller.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ auto IKController::update_system_state_values() -> controller_interface::return_
297297
// the states first, then save them.
298298
if (params_.use_external_measured_vehicle_states) {
299299
const auto * state_msg = vehicle_state_.readFromRT();
300-
const auto state = common::messages::to_vector(*state_msg);
300+
const std::vector<double> state = common::messages::to_vector(*state_msg);
301301
std::ranges::copy(state.begin(), state.begin() + free_flyer_pos_dofs_.size(), position_state_values_.begin());
302302
std::ranges::copy(state.begin() + free_flyer_pos_dofs_.size(), state.end(), velocity_state_values_.begin());
303303
} else {
@@ -336,21 +336,25 @@ auto IKController::update_system_state_values() -> controller_interface::return_
336336

337337
auto find_interface = [](const auto & interfaces, const std::string & name, const std::string & type) {
338338
return std::ranges::find_if(interfaces, [&name, &type](const auto & interface) {
339-
return interface.get_interface_name() == std::format("{}/{}", name, type);
339+
return interface.get_name() == std::format("{}/{}", name, type);
340340
});
341341
};
342342

343343
// save the manipulator states
344-
for (const auto & [i, joint_name] : std::views::enumerate(params_.controlled_joints)) {
344+
for (const auto & joint_name : params_.controlled_joints) {
345345
const pinocchio::JointModel joint = model_->joints[model_->getJointId(joint_name)];
346346

347347
const auto pos_it = find_interface(state_interfaces_, joint_name, hardware_interface::HW_IF_POSITION);
348-
const double pos = pos_it->get_optional().value_or(std::numeric_limits<double>::quiet_NaN());
349-
position_state_values_[free_flyer_pos_dofs_.size() + i] = pos;
348+
if (pos_it != state_interfaces_.end()) {
349+
const double pos = pos_it->get_optional().value_or(std::numeric_limits<double>::quiet_NaN());
350+
position_state_values_[joint.idx_q()] = pos;
351+
}
350352

351353
const auto vel_it = find_interface(state_interfaces_, joint_name, hardware_interface::HW_IF_VELOCITY);
352-
const double vel = vel_it->get_optional().value_or(std::numeric_limits<double>::quiet_NaN());
353-
velocity_state_values_[free_flyer_vel_dofs_.size() + i] = vel;
354+
if (vel_it != state_interfaces_.end()) {
355+
const double vel = vel_it->get_optional().value_or(std::numeric_limits<double>::quiet_NaN());
356+
velocity_state_values_[joint.idx_v()] = vel;
357+
}
354358
}
355359

356360
if (std::ranges::any_of(position_state_values_, [](double x) { return std::isnan(x); })) {

0 commit comments

Comments
 (0)