Skip to content

Commit

Permalink
Merge pull request #5 from nzantopp/bugfix/default-parameter-python
Browse files Browse the repository at this point in the history
Fix: Ensure parameters are initialized with default values if undefined in `params.yml`
  • Loading branch information
lreiher authored Nov 20, 2024
2 parents a003f1c + 9d219be commit c7b3afc
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions samples/ros2_cpp_all_pkg/src/ros2_cpp_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void Ros2CppNode::declareAndLoadParameter(const std::string& name,
ss << param;
}
RCLCPP_WARN_STREAM(this->get_logger(), ss.str());
this->set_parameters({rclcpp::Parameter(name, rclcpp::ParameterValue(param))});
}
}

Expand Down
1 change: 1 addition & 0 deletions samples/ros2_cpp_component_pkg/src/ros2_cpp_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void Ros2CppNode::declareAndLoadParameter(const std::string& name,
ss << param;
}
RCLCPP_WARN_STREAM(this->get_logger(), ss.str());
this->set_parameters({rclcpp::Parameter(name, rclcpp::ParameterValue(param))});
}
}

Expand Down
1 change: 1 addition & 0 deletions samples/ros2_cpp_lifecycle_pkg/src/ros2_cpp_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void Ros2CppNode::declareAndLoadParameter(const std::string& name,
ss << param;
}
RCLCPP_WARN_STREAM(this->get_logger(), ss.str());
this->set_parameters({rclcpp::Parameter(name, rclcpp::ParameterValue(param))});
}
}

Expand Down
1 change: 1 addition & 0 deletions samples/ros2_cpp_pkg/src/ros2_cpp_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void Ros2CppNode::declareAndLoadParameter(const std::string& name,
ss << param;
}
RCLCPP_WARN_STREAM(this->get_logger(), ss.str());
this->set_parameters({rclcpp::Parameter(name, rclcpp::ParameterValue(param))});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def declareAndLoadParameter(self,
else:
self.get_logger().warn(f"Missing parameter '{name}', using default value: {default}")
param = default
self.set_parameters([rclpy.Parameter(name=name, value=param)])

# add parameter to auto-reconfigurable parameters
if add_to_auto_reconfigurable_params:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def declareAndLoadParameter(self,
else:
self.get_logger().warn(f"Missing parameter '{name}', using default value: {default}")
param = default
self.set_parameters([rclpy.Parameter(name=name, value=param)])

# add parameter to auto-reconfigurable parameters
if add_to_auto_reconfigurable_params:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void {{ node_class_name }}::declareAndLoadParameter(const std::string& name,
ss << param;
}
RCLCPP_WARN_STREAM(this->get_logger(), ss.str());
this->set_parameters({rclcpp::Parameter(name, rclcpp::ParameterValue(param))});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class {{ node_class_name }}(Node):
else:
self.get_logger().warn(f"Missing parameter '{name}', using default value: {default}")
param = default
self.set_parameters([rclpy.Parameter(name=name, value=param)])

# add parameter to auto-reconfigurable parameters
if add_to_auto_reconfigurable_params:
Expand Down

0 comments on commit c7b3afc

Please sign in to comment.