Skip to content

Conversation

@clalancette
Copy link
Collaborator

@clalancette clalancette commented Aug 7, 2020

This PR does the bare minimum to implement 'use_sim_time' in rcljava. By 'bare minimum', I mean:

  1. It revamps the Time class to be more like the rclcpp/rclpy equivalents.
  2. It revamps the Clock class to be more like the rclcpp/rclpy equivalents.
  3. It implements the TimeSource class, which is responsible for setting up the 'use_sim_time' parameter and subscribing to the '/clock' topic.
  4. The current tests pass.
  5. New tests for the revamped Time class were added.
  6. No new tests for Clock or TimeSource were added.
  7. There are still a few (relatively minor) TODO comments in the code.
  8. I didn't test that this actually, you know, works.

Nevertheless, I think this is a good starting point to finish implementing 'use_sim_time'. The next steps here are to write tests, fix the TODOs, and then test that 'use_sim_time' actually works.

FYI, this builds on top of #3 , so some of those commits are in here as well. Once #3 is reviewed/merged, this one should be rebased.

@jacobperron @ivanpauno FYI.

@clalancette clalancette mentioned this pull request Aug 11, 2020
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette clalancette force-pushed the clalancette/revamp-time branch from c2c1462 to 8826dc9 Compare August 11, 2020 13:20
@clalancette
Copy link
Collaborator Author

Rebased onto the latest now that #3 has been merged.

return new Time(0, nanos, this.clockType);
}

public boolean getRosTimeIsActive() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I find isRosTimeActive() more readable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did this to be more consistent with the rest of the rcljava code, particularly the get and set methods in the generated message files. But I don't feel strongly about it either way.

return nativeRosTimeOverrideEnabled(this.handle);
}

public void setRosTimeIsActive(boolean enabled) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I find setRosTime more readable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above.

Comment on lines +100 to +102
if (!this.node.hasParameter("use_sim_time")) {
this.node.declareParameter(new ParameterVariant("use_sim_time", false));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a TOCTTOU race condition here.
The problem exists in other clients (e.g. rclcpp), so I don't care much.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this is a race. It happens early in the process of creating a node, so it is fairly unlikely to happen. I guess we could avoid the race by unconditionally calling declareParameter, and handling the exception if it fails. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we could avoid the race by unconditionally calling declareParameter, and handling the exception if it fails.

SGTM

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette
Copy link
Collaborator Author

As discussed in person, closing this PR and reopening from a branch on the osrf repository.

@clalancette clalancette mentioned this pull request Aug 11, 2020
Copy link
Collaborator

@ivanpauno ivanpauno left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +100 to +102
if (!this.node.hasParameter("use_sim_time")) {
this.node.declareParameter(new ParameterVariant("use_sim_time", false));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we could avoid the race by unconditionally calling declareParameter, and handling the exception if it fails.

SGTM

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.

2 participants