Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clock type to node_options #1982

Conversation

jefferyyjhsu
Copy link
Contributor

Signed-off-by: Jeffery Hsu jefferyyjhsu@gmail.com
This PR adds the option for selecting clock source in Node/LifecycleNode thru NodeOptions.
A similar option is already present in rclcpp::Timer but it is currently missing in Nodes/LifecycleNode. There's currently no way to set Node::now() and all other time-related functions to use clock sources other than ROS_TIME.

@jefferyyjhsu jefferyyjhsu force-pushed the Add-options-for-different-clock-type-in-ROS-2-node branch 2 times, most recently from 7eb5651 to d22dfac Compare August 8, 2022 22:14
@alsora
Copy link
Collaborator

alsora commented Aug 15, 2022

CI

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@alsora
Copy link
Collaborator

alsora commented Aug 15, 2022

NOTE: this PR is from iRobot.
It looks good to me, but I would like also feedbacks from other reviewers

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with test for NodeOption

rclcpp/src/rclcpp/node_interfaces/node_clock.cpp Outdated Show resolved Hide resolved
rclcpp/include/rclcpp/node_options.hpp Show resolved Hide resolved
@jefferyyjhsu jefferyyjhsu force-pushed the Add-options-for-different-clock-type-in-ROS-2-node branch 3 times, most recently from 53af9d5 to bca2d75 Compare August 18, 2022 17:29
@asymingt
Copy link
Contributor

asymingt commented Aug 20, 2022

Forgive me if I misunderstand this PR, but I think being able to have Node::now() driven by sim time is currently possible with setting use_sim_time=true parameter on the node. After this PR lands you should be able to create both sim and wall timers with Node::create_timer() and Node::create_wall_timer(). Is there a use case beyond these that I'm missing?

@alsora
Copy link
Collaborator

alsora commented Aug 20, 2022

@asymingt the purpose of this PR is to allow to set the node clock type.
There are 3 types of clocks in ros: real time, monotonic and "ros".

Currently, you must use a clock of type "ros" for a node.
A clock of this type uses a real time clock and also the clock topic if available (and if use_sim_time is set to true).

There are a lot of applications where a real time clock is not suitable and it is required to use a monotonic clock (and as said before, the "ros" clock is not monotoni)

@asymingt
Copy link
Contributor

@asymingt the purpose of this PR is to allow to set the node clock type. There are 3 types of clocks in ros: real time, monotonic and "ros".

Currently, you must use a clock of type "ros" for a node. A clock of this type uses a real time clock and also the clock topic if available (and if use_sim_time is set to true).

There are a lot of applications where a real time clock is not suitable and it is required to use a monotonic clock (and as said before, the "ros" clock is not monotoni)

Understood. Thank you, and sorry for the distraction.

@alsora
Copy link
Collaborator

alsora commented Aug 30, 2022

New CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@alsora
Copy link
Collaborator

alsora commented Aug 30, 2022

@fujitatomoya I think that comments have been addressed.
Anything else to do?

@fujitatomoya
Copy link
Collaborator

either @iuhilnehc-ynos or @Barry-Xu-2018 , could you help us review on this?

I was thinking that, i may be missing something.

  • TimeSource and ClockState are dedicated to manage the ROS simulation time. User must be able to switch on/off simulation time afterward.
  • Having Node::Option::clock_type can be used to default clock type creating timer and so on.

CC: @alsora @jefferyyjhsu

Copy link
Collaborator

@iuhilnehc-ynos iuhilnehc-ynos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nitpick

rclcpp/src/rclcpp/node_options.cpp Outdated Show resolved Hide resolved
@alsora
Copy link
Collaborator

alsora commented Aug 31, 2022

@fujitatomoya I agree on having the clock type to be used as the default clock type for timers... I was assuming that it was already the case.

About simulated time: users should be able to turn it on/off UNLESS they manually set the node clock to monotonic... In that case simulated time is not currently expected to work and it should throw an exception/error somewhere.

@jefferyyjhsu jefferyyjhsu force-pushed the Add-options-for-different-clock-type-in-ROS-2-node branch 2 times, most recently from 87e1e0b to bd57012 Compare August 31, 2022 23:55
@alsora
Copy link
Collaborator

alsora commented Sep 1, 2022

EDIT: ignore this CI! I made a mistake when configuring it!

CI

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@alsora
Copy link
Collaborator

alsora commented Sep 2, 2022

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@alsora
Copy link
Collaborator

alsora commented Sep 23, 2022

Hi, are there any more changes that we should address before proceeding with this PR?
I see that there are some failures in windows tests, are these known problems?

@fujitatomoya
Copy link
Collaborator

@alsora @jefferyyjhsu sorry to be late, just left couple of comments.

@jefferyyjhsu jefferyyjhsu force-pushed the Add-options-for-different-clock-type-in-ROS-2-node branch 3 times, most recently from 906bbf2 to bee7cf3 Compare September 24, 2022 00:42
@fujitatomoya
Copy link
Collaborator

@ivanpauno can you also take a look at this, this changes behavior a bit.

CC: @clalancette

@fujitatomoya
Copy link
Collaborator

@jefferyyjhsu can you address DCO issue?

@jefferyyjhsu jefferyyjhsu force-pushed the Add-options-for-different-clock-type-in-ROS-2-node branch from 755638a to f369888 Compare November 8, 2022 22:37
@jefferyyjhsu
Copy link
Contributor Author

@fujitatomoya , yeah. Sorry, I did remember to fix it by rebasing it locally but forgot to finish it before pushing.

@alsora
Copy link
Collaborator

alsora commented Nov 22, 2022

New CI

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@alsora
Copy link
Collaborator

alsora commented Nov 24, 2022

The windows failure happens also in a completely unrelated PR #1979

@ivanpauno
Copy link
Member

See #1979 (comment)

…ctor accordingly

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
…. Add test cases.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
ros_time_active_ in ClocksState::attachClock()

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
Following the reasoning in c54a6f1, on_set_parameters doesn't try to enforce use_sim_time to be of boolean type explicitly.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
@jefferyyjhsu jefferyyjhsu force-pushed the Add-options-for-different-clock-type-in-ROS-2-node branch from f369888 to 49eeb45 Compare November 28, 2022 21:25
@fujitatomoya
Copy link
Collaborator

  • Windows Build Status

@alsora
Copy link
Collaborator

alsora commented Dec 5, 2022

Running full CI.
The github check reports failures on rclcpp tests but they seem unrelated.

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@alsora
Copy link
Collaborator

alsora commented Dec 13, 2022

Ping; can we merge this PR?

@fujitatomoya fujitatomoya merged commit 432bf21 into ros2:rolling Dec 13, 2022
@methylDragon
Copy link
Contributor

methylDragon commented Dec 15, 2022

Erm.. I'm getting the same issue locally as the Rpr job
https://build.ros2.org/job/Rpr__rclcpp__ubuntu_jammy_amd64/469/testReport/junit/rclcpp/TestTimeSource/callbacks/

Something is causing the callback test to fail, though it happens sporadically
When the test is run standalone there are no issues, but when it's run together something breaks. (It could just be a flaky test though)

@methylDragon
Copy link
Contributor

Pinging @jefferyyjhsu

@jefferyyjhsu
Copy link
Contributor Author

@methylDragon, sorry for the delay. I tried reproducing the error with colcon test --packages-select rclcpp but failed. How are you running the tests?
In rclcpp/test/rclcpp/test_time_source.cpp, I only added 2 isolated test cases.

TEST(TimeSource, valid_clock_type_for_sim_time)
{
rclcpp::init(0, nullptr);

rclcpp::NodeOptions options;
auto node = std::make_sharedrclcpp::Node("my_node", options);
EXPECT_TRUE(
node->set_parameter(
rclcpp::Parameter(
"use_sim_time", rclcpp::ParameterValue(
true))).successful);
rclcpp::shutdown();
}

TEST(TimeSource, invalid_clock_type_for_sim_time)
{
rclcpp::init(0, nullptr);

rclcpp::NodeOptions options;
options.clock_type(RCL_STEADY_TIME);
auto node = std::make_sharedrclcpp::Node("my_node", options);
EXPECT_FALSE(
node->set_parameter(
rclcpp::Parameter(
"use_sim_time", rclcpp::ParameterValue(
true))).successful);
rclcpp::shutdown();
}

@methylDragon
Copy link
Contributor

methylDragon commented Dec 19, 2022

@methylDragon, sorry for the delay. I tried reproducing the error with colcon test --packages-select rclcpp but failed. How are you running the tests? In rclcpp/test/rclcpp/test_time_source.cpp, I only added 2 isolated test cases.

TEST(TimeSource, valid_clock_type_for_sim_time)
{
rclcpp::init(0, nullptr);
rclcpp::NodeOptions options;
auto node = std::make_sharedrclcpp::Node("my_node", options);
EXPECT_TRUE(
node->set_parameter(
rclcpp::Parameter(
"use_sim_time", rclcpp::ParameterValue(
true))).successful);
rclcpp::shutdown();
}
TEST(TimeSource, invalid_clock_type_for_sim_time)
{
rclcpp::init(0, nullptr);
rclcpp::NodeOptions options;
options.clock_type(RCL_STEADY_TIME);
auto node = std::make_sharedrclcpp::Node("my_node", options);
EXPECT_FALSE(
node->set_parameter(
rclcpp::Parameter(
"use_sim_time", rclcpp::ParameterValue(
true))).successful);
rclcpp::shutdown();
}

Hey there! I am also running it with colcon test --packages-select rclcpp. It seems like this issue only happens randomly though, so I suspect it's a flaky test or a previously existing flaky test that's excacerbated by a change here? Or I could be wrong and its completely unrelated to this PR :o

It definitely shows up on the buildfarm though; though sporadically

@ivanpauno
Copy link
Member

Erm.. I'm getting the same issue locally as the Rpr job
https://build.ros2.org/job/Rpr__rclcpp__ubuntu_jammy_amd64/469/testReport/junit/rclcpp/TestTimeSource/callbacks/

Something is causing the callback test to fail, though it happens sporadically

I think that test has been flaky for a long time (before this PR was merged), I don't think the failure is related to these changes.

@methylDragon
Copy link
Contributor

Ah, okay, disregard my comment then! Sorry for the noise 🙇

alsora pushed a commit to irobot-ros/rclcpp that referenced this pull request Apr 29, 2023
* add clock type to node_options and change node/lifecycle_node constructor accordingly

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Modify TimeSource::NodeState class to work with different clock types. Add test cases.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Change on_parameter_event to output RCLCPP_ERROR and check
ros_time_active_ in ClocksState::attachClock()

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Remove a redundant include

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Disallow setting use_sim_time to true if a clock_type can't support it.
Following the reasoning in c54a6f1, on_set_parameters doesn't try to enforce use_sim_time to be of boolean type explicitly.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* minior style change

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* remove reason string for successful result

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
alsora pushed a commit to irobot-ros/rclcpp that referenced this pull request Jul 28, 2023
* add clock type to node_options and change node/lifecycle_node constructor accordingly

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Modify TimeSource::NodeState class to work with different clock types. Add test cases.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Change on_parameter_event to output RCLCPP_ERROR and check
ros_time_active_ in ClocksState::attachClock()

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Remove a redundant include

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Disallow setting use_sim_time to true if a clock_type can't support it.
Following the reasoning in c54a6f1, on_set_parameters doesn't try to enforce use_sim_time to be of boolean type explicitly.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* minior style change

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* remove reason string for successful result

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
alsora pushed a commit to irobot-ros/rclcpp that referenced this pull request Jul 28, 2023
* add clock type to node_options and change node/lifecycle_node constructor accordingly

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Modify TimeSource::NodeState class to work with different clock types. Add test cases.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Change on_parameter_event to output RCLCPP_ERROR and check
ros_time_active_ in ClocksState::attachClock()

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Remove a redundant include

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Disallow setting use_sim_time to true if a clock_type can't support it.
Following the reasoning in c54a6f1, on_set_parameters doesn't try to enforce use_sim_time to be of boolean type explicitly.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* minior style change

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* remove reason string for successful result

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
alsora pushed a commit to irobot-ros/rclcpp that referenced this pull request Jan 30, 2024
* add clock type to node_options and change node/lifecycle_node constructor accordingly

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Modify TimeSource::NodeState class to work with different clock types. Add test cases.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Change on_parameter_event to output RCLCPP_ERROR and check
ros_time_active_ in ClocksState::attachClock()

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Remove a redundant include

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Disallow setting use_sim_time to true if a clock_type can't support it.
Following the reasoning in c54a6f1, on_set_parameters doesn't try to enforce use_sim_time to be of boolean type explicitly.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* minior style change

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* remove reason string for successful result

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
apojomovsky pushed a commit to apojomovsky/rclcpp that referenced this pull request Jun 6, 2024
* add clock type to node_options and change node/lifecycle_node constructor accordingly

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Modify TimeSource::NodeState class to work with different clock types. Add test cases.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Change on_parameter_event to output RCLCPP_ERROR and check
ros_time_active_ in ClocksState::attachClock()

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Remove a redundant include

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* Disallow setting use_sim_time to true if a clock_type can't support it.
Following the reasoning in c54a6f1, on_set_parameters doesn't try to enforce use_sim_time to be of boolean type explicitly.

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* minior style change

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

* remove reason string for successful result

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>

Signed-off-by: Jeffery Hsu <jefferyyjhsu@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants