Skip to content

Commit e19eb0d

Browse files
authored
Add string() methods to get the printable information (#547)
1 parent 1953bd1 commit e19eb0d

File tree

1 file changed

+12
-8
lines changed
  • control_toolbox/include/control_toolbox

1 file changed

+12
-8
lines changed

control_toolbox/include/control_toolbox/pid.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,13 @@ struct AntiWindupStrategy
135135
}
136136
}
137137

138-
void print() const
138+
void print() const { std::cout << string() << std::endl; }
139+
140+
std::string string() const
139141
{
140-
std::cout << "antiwindup_strat: " << to_string() << "\ti_max: " << i_max << ", i_min: " << i_min
141-
<< "\ttracking_time_constant: " << tracking_time_constant
142-
<< "\terror_deadband: " << error_deadband << std::endl;
142+
return fmt::format(
143+
"antiwindup_strat: {}\ti_max: {}\ti_min: {}\ttracking_time_constant: {}\terror_deadband: {}",
144+
to_string(), i_max, i_min, tracking_time_constant, error_deadband);
143145
}
144146

145147
operator std::string() const { return to_string(); }
@@ -315,11 +317,13 @@ class Pid
315317
return true;
316318
}
317319

318-
void print() const
320+
void print() const { std::cout << string() << std::endl; }
321+
322+
std::string string() const
319323
{
320-
std::cout << "Gains: p: " << p_gain_ << ", i: " << i_gain_ << ", d: " << d_gain_
321-
<< ", u_max: " << u_max_ << ", u_min: " << u_min_ << std::endl;
322-
antiwindup_strat_.print();
324+
return fmt::format(
325+
"Gains(p: {}, i: {}, d: {}, u_max: {}, u_min: {}, antiwindup_strat: '{}')", p_gain_,
326+
i_gain_, d_gain_, u_max_, u_min_, antiwindup_strat_.string());
323327
}
324328

325329
double p_gain_ = 0.0; /**< Proportional gain. */

0 commit comments

Comments
 (0)