Skip to content

Commit

Permalink
Patch failing demo_nodes_cpp launch tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic committed Apr 29, 2019
1 parent 4efe6a0 commit 38eb873
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 10 additions & 7 deletions demo_nodes_cpp/src/parameters/parameter_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ int main(int argc, char ** argv)

auto node = rclcpp::Node::make_shared("parameter_events");

// Declare parameters that may be set on this node
node->declare_parameter("foo");
node->declare_parameter("bar");
node->declare_parameter("baz");
node->declare_parameter("foobar");

auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(node);
while (!parameters_client->wait_for_service(1s)) {
if (!rclcpp::ok()) {
Expand All @@ -72,6 +66,12 @@ int main(int argc, char ** argv)
on_parameter_event(event, node->get_logger());
});

// Declare parameters that may be set on this node
node->declare_parameter("foo");
node->declare_parameter("bar");
node->declare_parameter("baz");
node->declare_parameter("foobar");

// Set several different types of parameters.
auto set_parameters_results = parameters_client->set_parameters({
rclcpp::Parameter("foo", 2),
Expand All @@ -88,7 +88,10 @@ int main(int argc, char ** argv)

// TODO(wjwwood): Create and use delete_parameter

rclcpp::sleep_for(100ms);
// TODO(hidmic): Fast-RTPS takes a significant amount of time to deliver
// requests and response, thus the rather long sleep. Reduce
// once that's resolved.
rclcpp::sleep_for(3s);

rclcpp::spin_some(node);

Expand Down
14 changes: 7 additions & 7 deletions demo_nodes_cpp/src/parameters/parameter_events_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ class ParameterEventsAsyncNode : public rclcpp::Node
ParameterEventsAsyncNode()
: Node("parameter_events")
{
// Declare parameters that may be set on this node
this->declare_parameter("foo");
this->declare_parameter("bar");
this->declare_parameter("baz");
this->declare_parameter("foobar");

// Typically a parameter client is created for a remote node by passing the name of the remote
// node in the constructor; in this example we create a parameter client for this node itself.
parameters_client_ = std::make_shared<rclcpp::AsyncParametersClient>(this);
Expand Down Expand Up @@ -63,9 +57,15 @@ class ParameterEventsAsyncNode : public rclcpp::Node
// Setup callback for changes to parameters.
parameter_event_sub_ = parameters_client_->on_parameter_event(on_parameter_event_callback);

// Declare parameters that may be set on this node
this->declare_parameter("foo");
this->declare_parameter("bar");
this->declare_parameter("baz");
this->declare_parameter("foobar");

// Queue a `set_parameters` request as soon as `spin` is called on this node.
// TODO(dhood): consider adding a "call soon" notion to Node to not require a timer for this.
timer_ = create_wall_timer(0s,
timer_ = create_wall_timer(200ms,
[this]() {
this->queue_first_set_parameter_request();
});
Expand Down

0 comments on commit 38eb873

Please sign in to comment.