Skip to content

Commit

Permalink
Fix crashing due to an invalid parameter in the initial value (#233)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
(cherry picked from commit a3beadb)

# Conflicts:
#	ign_ros2_control/src/ign_system.cpp
  • Loading branch information
ahcorde authored and mergify[bot] committed Feb 13, 2024
1 parent 36beb6d commit dd0d740
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ign_ros2_control/src/ign_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,33 @@ bool IgnitionSystem::initSim(

RCLCPP_INFO_STREAM(this->nh_->get_logger(), "\tState:");

auto get_initial_value = [this](const hardware_interface::InterfaceInfo & interface_info) {
auto get_initial_value =
[this, joint_name](const hardware_interface::InterfaceInfo & interface_info) {
double initial_value{0.0};
if (!interface_info.initial_value.empty()) {
<<<<<<< HEAD:ign_ros2_control/src/ign_system.cpp
double value = std::stod(interface_info.initial_value);
RCLCPP_INFO(this->nh_->get_logger(), "\t\t\t found initial value: %f", value);
return value;
} else {
return 0.0;
=======
try {
initial_value = hardware_interface::stod(interface_info.initial_value);
RCLCPP_INFO(this->nh_->get_logger(), "\t\t\t found initial value: %f", initial_value);
} catch (std::invalid_argument &) {
RCLCPP_ERROR_STREAM(
this->nh_->get_logger(),
"Failed converting initial_value string to real number for the joint "
<< joint_name
<< " and state interface " << interface_info.name
<< ". Actual value of parameter: " << interface_info.initial_value
<< ". Initial value will be set to 0.0");
throw std::invalid_argument("Failed converting initial_value string");
}
>>>>>>> a3beadb (Fix crashing due to an invalid parameter in the initial value (#233)):gz_ros2_control/src/gz_system.cpp
}
return initial_value;
};

double initial_position = std::numeric_limits<double>::quiet_NaN();
Expand Down

0 comments on commit dd0d740

Please sign in to comment.