Skip to content

Conversation

@Bharath4444
Copy link

Description

This PR addresses issue #2035 by moving the initialization of previous_publish_timestamp_ into the on_configure() lifecycle method.

Previously, this variable was initialized inside a catch block within the update loop, effectively using exception handling for normal control flow. Moving it to on_configure aligns it with how previous_update_timestamp_ is handled and ensures the timestamp is valid before the update loop begins.

Related Issues

Closes #2035

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

tf2::Quaternion orientation;
orientation.setRPY(0.0, 0.0, odometry_.getHeading());

bool should_publish = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this variable can/should be removed now.

Copy link
Member

Choose a reason for hiding this comment

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

I guess it is still needed to be able to control the frequency of publishing the message

Copy link
Member

Choose a reason for hiding this comment

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

You are right, we can combine the logic and we can remove it

Copy link
Member

@saikishor saikishor left a comment

Choose a reason for hiding this comment

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

Combine the logic and remove should_publish variable

…e try-catch also removing should_publish variable
@Bharath4444 Bharath4444 requested a review from Amronos December 27, 2025 17:21
Copy link
Member

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

This just removes the logic introduced with #585

Are we sure that this is not needed anymore?

previous_publish_timestamp_ = time;
should_publish = true;
}
previous_publish_timestamp_ += publish_period_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
previous_publish_timestamp_ += publish_period_;
previous_publish_timestamp_ = time;

@christophfroehlich I think this should fix #585 and also be better overall.

Copy link
Member

Choose a reason for hiding this comment

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

no because the comparison above fails if the time source changed.


bool should_publish = false;
try
if (previous_publish_timestamp_ + publish_period_ <= time)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (previous_publish_timestamp_ + publish_period_ <= time)
if (previous_publish_timestamp_ + publish_period_ > time)

I was misunderstanding the logic here. I think with this change and the earlier one everything should work. This should cause this if statement to pass as true the first time in simulation and from there on work correctly.

@christophfroehlich

Copy link
Member

Choose a reason for hiding this comment

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

still: This comparison will throw an exception if the timesource changes

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.

[diff-drive-controller] Move previous_publish_timestamp_ initialization out of exception block

4 participants