Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ __declare_parameter_common(
initial_value = &overrides_it->second;
}

// If there is no initial value, then skip initialization
if (initial_value->get_type() == rclcpp::PARAMETER_NOT_SET) {
// descriptor type should be set
assert(parameter_descriptor.type != rclcpp::PARAMETER_NOT_SET);
Comment thread
jacobperron marked this conversation as resolved.
Outdated
// Add declared parameters to storage (without a value)
parameter_infos[name].descriptor.name = name;
parameter_infos[name].descriptor.type = parameter_descriptor.type;
Comment thread
jacobperron marked this conversation as resolved.
Outdated
parameters_out[name] = parameter_infos.at(name);
rcl_interfaces::msg::SetParametersResult result;
result.successful = true;
return result;
}

// Check with the user's callback to see if the initial value can be set.
std::vector<rclcpp::Parameter> parameter_wrappers {rclcpp::Parameter(name, *initial_value)};
// This function also takes care of default vs initial value.
Expand Down Expand Up @@ -413,14 +426,6 @@ declare_parameter_helper(
parameter_descriptor.type = static_cast<uint8_t>(type);
}

if (
rclcpp::PARAMETER_NOT_SET == default_value.get_type() &&
overrides.find(name) == overrides.end() &&
parameter_descriptor.dynamic_typing == false)
{
throw rclcpp::exceptions::NoParameterOverrideProvided(name);
}

rcl_interfaces::msg::ParameterEvent parameter_event;
auto result = __declare_parameter_common(
name,
Expand Down
13 changes: 9 additions & 4 deletions rclcpp/test/rclcpp/test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,17 @@ TEST_F(TestNode, declare_parameter_with_no_initial_values) {
{
rcl_interfaces::msg::ParameterDescriptor descriptor;
descriptor.dynamic_typing = true;
// no default, no initial
// no default, no initial, dynamic typing
rclcpp::ParameterValue value = node->declare_parameter(
"parameter"_unq, rclcpp::ParameterValue{}, descriptor);
Comment thread
jacobperron marked this conversation as resolved.
Outdated
EXPECT_EQ(value.get_type(), rclcpp::PARAMETER_NOT_SET);
}
{
// no default, no initial, static typing
rclcpp::ParameterValue value = node->declare_parameter(
"parameter"_unq, rclcpp::ParameterType::PARAMETER_INTEGER);
EXPECT_EQ(value.get_type(), rclcpp::PARAMETER_NOT_SET);
}
Comment thread
ivanpauno marked this conversation as resolved.
{
// int default, no initial
rclcpp::ParameterValue default_value(42);
Expand Down Expand Up @@ -2798,9 +2804,8 @@ TEST_F(TestNode, static_and_dynamic_typing) {
EXPECT_EQ("hello!", param);
}
{
EXPECT_THROW(
node->declare_parameter("integer_override_not_given", rclcpp::PARAMETER_INTEGER),
rclcpp::exceptions::NoParameterOverrideProvided);
auto param = node->declare_parameter("integer_override_not_given", rclcpp::PARAMETER_INTEGER);
EXPECT_EQ(rclcpp::PARAMETER_NOT_SET, param.get_type());
Comment thread
jacobperron marked this conversation as resolved.
}
{
EXPECT_THROW(
Expand Down