Skip to content

Commit

Permalink
Avoid crash when the type of the parameter doesn't match
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde authored and bmagyar committed Jun 14, 2020
1 parent 3907e9d commit d227091
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/pid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,26 @@ void Pid::setParameterEventCallback()

for (auto & parameter : parameters) {
const std::string param_name = parameter.get_name();
if (param_name == "p") {
gains.p_gain_ = parameter.get_value<double>();
} else if (param_name == "i") {
gains.i_gain_ = parameter.get_value<double>();
} else if (param_name == "d") {
gains.d_gain_ = parameter.get_value<double>();
} else if (param_name == "i_clamp_max") {
gains.i_max_ = parameter.get_value<double>();
} else if (param_name == "i_clamp_min") {
gains.i_min_ = parameter.get_value<double>();
} else if (param_name == "antiwindup") {
gains.antiwindup_ = parameter.get_value<bool>();
} else {
result.successful = false;
result.reason = "Invalid parameter";
try {
if (param_name == "p") {
gains.p_gain_ = parameter.get_value<double>();
} else if (param_name == "i") {
gains.i_gain_ = parameter.get_value<double>();
} else if (param_name == "d") {
gains.d_gain_ = parameter.get_value<double>();
} else if (param_name == "i_clamp_max") {
gains.i_max_ = parameter.get_value<double>();
} else if (param_name == "i_clamp_min") {
gains.i_min_ = parameter.get_value<double>();
} else if (param_name == "antiwindup") {
gains.antiwindup_ = parameter.get_value<bool>();
} else {
result.successful = false;
result.reason = "Invalid parameter";
}
} catch (const rclcpp::exceptions::InvalidParameterTypeException & e) {
RCLCPP_INFO_STREAM(
rclcpp::get_logger("control_toolbox::pid"), "Please use the right type: " << e.what());
}
}

Expand Down

0 comments on commit d227091

Please sign in to comment.