← Back to Pull requests

Contact system: Enable the sensor's update_rate #4099

Merged
caguero merged 4 files (301 lines) on Oct 23, 2026 10:26 UTC
View on GitHub
caguero caguero commented on Oct 22, 2026 10:20 UTC
Author

🦟 Bug fix

Summary

The Contact system ignores <update_rate> and publishes at every iteration with contacts. As an example, a wheel touching the ground with <update_rate>10</update_rate> is publishing 1000 messages per second at the default step size.

Now a sensor with a positive <update_rate> publishes at that rate on a fixed schedule of simulation time (also when the period is not a multiple of the step), with the contacts gathered since its last message; without a rate nothing changes.

Worlds that already set a rate below the physics rate will get fewer, larger messages.

ContactSystemTest.ExtraContactData looks flaky on main with or without this change.

Backport Policy


  • This is safe to backport to the following versions:

  • - [ ] Jetty
    - [ ] Ionic
    - [ ] Harmonic
    - [ ] Fortress
  • This should not be backported

  • I am not sure

  • Other (fill in yourself)
  • Note for released branches: worlds that already set a rate (e.g. examples/worlds/contact_sensor.sdf, 100 Hz) would start getting messages with several steps of contacts, which is a behavior change. That's why I'm leaning towards not backporting it.

    Checklist


  • Signed all commits for DCO

  • Added a screen capture or video to the PR description that demonstrates the fix (as needed)

  • Added tests

  • Updated documentation (as needed)

  • Updated migration guide (as needed)

  • Consider updating Python bindings (if the library has them)

  • codecheck passed (See contributing)

  • All tests passed (See test coverage)

  • Updated Bazel files (if adding new files). Created an issue otherwise.

  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

  • Was GenAI used to generate this PR? If so, make sure to add "Assisted-by" to your commits. (See this policy for more info.)
  • Assisted-by: Claude Opus 5.5

    Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

    Backports: If this is a backport, please use Rebase and Merge instead.

    Diff: 301 lines (+295 / -6) across 4 files Reviewer: iche033 Review duration: 1446m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.42) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 301 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.75 · 4 substantive comment(s)
    0.75
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    83%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.342
    Real PR Conversation Timeline
    7 items
    iche033 iche033 commented on code on Oct 22, 2026 20:08 UTC
    Code Review
    src/systems/contact/Contact.cc:1
    @@ -139,6 +152,14 @@ void ContactSensor::Load(const sdf::ElementPtr &_sdf, const std::string &_topic,
         this->topic = tmpTopic;
       }
     
    +  const double updateRate = _sdf->Get<double>("update_rate", 0.0).first;
    +  if (updateRate > 0.0)
    +  {
    +    this->updatePeriod =
    +        std::chrono::duration_cast<std::chrono::steady_clock::duration>(
    +            std::chrono::duration<double>(1.0 / updateRate));
    +  }

    warn if update_rate is negative? I think it just default to physics update rate (original behavior)?

    iche033 iche033 commented on code on Oct 22, 2026 20:15 UTC
    Code Review
    src/systems/contact/Contact.cc:1

    Regarding contact timestamps, it looks like the individual contact point's timestamp (newContact) inside the this->contactsMsg message should be correct. The this->contactsMsg message itself should probably use the timestamp of when the message is published. So move this call outside to Publish function?

    caguero caguero commented on code on Oct 22, 2026 20:46 UTC
    Code Review
    src/systems/contact/Contact.cc:1
    @@ -139,6 +152,14 @@ void ContactSensor::Load(const sdf::ElementPtr &_sdf, const std::string &_topic,
         this->topic = tmpTopic;
       }
     
    +  const double updateRate = _sdf->Get<double>("update_rate", 0.0).first;
    +  if (updateRate > 0.0)
    +  {
    +    this->updatePeriod =
    +        std::chrono::duration_cast<std::chrono::steady_clock::duration>(
    +            std::chrono::duration<double>(1.0 / updateRate));
    +  }

    Warning added in dd4758d.

    caguero caguero commented on code on Oct 22, 2026 20:46 UTC
    Code Review
    src/systems/contact/Contact.cc:1

    That makes more sense, good catch. dd4758d

    iche033 iche033 approved these changes on Oct 22, 2026 21:22 UTC
    Approved Reviewer

    Approved these changes.

    ahcorde ahcorde approved these changes on Oct 23, 2026 09:42 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    caguero caguero
    Labels
    risk: low confidence: 83% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 41.5% (MEDIUM) · Higher = larger blast radius
    41.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83% · Lower = rushed or shallow review
    83%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.1% · Safe to merge
    7.1%