Skip to content

Commit 2a5feb5

Browse files
authored
Add string() methods to get the printable information (#547) (#584)
1 parent 9520ce0 commit 2a5feb5

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
@@ -139,11 +139,13 @@ struct AntiWindupStrategy
139139
}
140140
}
141141

142-
void print() const
142+
void print() const { std::cout << string() << std::endl; }
143+
144+
std::string string() const
143145
{
144-
std::cout << "antiwindup_strat: " << to_string() << "\ti_max: " << i_max << ", i_min: " << i_min
145-
<< "\ttracking_time_constant: " << tracking_time_constant
146-
<< "\terror_deadband: " << error_deadband << std::endl;
146+
return fmt::format(
147+
"antiwindup_strat: {}\ti_max: {}\ti_min: {}\ttracking_time_constant: {}\terror_deadband: {}",
148+
to_string(), i_max, i_min, tracking_time_constant, error_deadband);
147149
}
148150

149151
operator std::string() const { return to_string(); }
@@ -321,11 +323,13 @@ class Pid
321323
return true;
322324
}
323325

324-
void print() const
326+
void print() const { std::cout << string() << std::endl; }
327+
328+
std::string string() const
325329
{
326-
std::cout << "Gains: p: " << p_gain_ << ", i: " << i_gain_ << ", d: " << d_gain_
327-
<< ", u_max: " << u_max_ << ", u_min: " << u_min_ << std::endl;
328-
antiwindup_strat_.print();
330+
return fmt::format(
331+
"Gains(p: {}, i: {}, d: {}, u_max: {}, u_min: {}, antiwindup_strat: '{}')", p_gain_,
332+
i_gain_, d_gain_, u_max_, u_min_, antiwindup_strat_.string());
329333
}
330334

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

0 commit comments

Comments
 (0)