Skip to content

Commit

Permalink
Fix logic for feedforward_mode with single reference interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Juliaj committed Feb 4, 2025
1 parent 694d6f1 commit dbfa74a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

/.vscode
diff_drive_controller/.vscode/settings.json
23 changes: 16 additions & 7 deletions pid_controller/src/pid_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,29 @@ controller_interface::return_type PidController::update_and_write_commands(

for (size_t i = 0; i < dof_; ++i)
{
double tmp_command = std::numeric_limits<double>::quiet_NaN();
double tmp_command = 0.0;

// Using feedforward
if (!std::isnan(reference_interfaces_[i]) && !std::isnan(measured_state_values_[i]))
{
// calculate feed-forward
if (*(control_mode_.readFromRT()) == feedforward_mode_type::ON)
{
tmp_command = reference_interfaces_[dof_ + i] *
params_.gains.dof_names_map[params_.dof_names[i]].feedforward_gain;
}
else
{
tmp_command = 0.0;
// two interfaces
if (reference_interfaces_.size() == 2 * dof_ && measured_state_values_.size() == 2 * dof_)
{
if (!std::isnan(reference_interfaces_[dof_ + i]) &&
!std::isnan(measured_state_values_[dof_ + i]))
{
tmp_command = reference_interfaces_[dof_ + i] *
params_.gains.dof_names_map[params_.dof_names[i]].feedforward_gain;
}
}
else // one interface
{
tmp_command = reference_interfaces_[i] *
params_.gains.dof_names_map[params_.dof_names[i]].feedforward_gain;
}
}

double error = reference_interfaces_[i] - measured_state_values_[i];
Expand Down

0 comments on commit dbfa74a

Please sign in to comment.