Skip to content

Fix sinusoidal_force_sensor build and runtime, set wave to 25 Hz - #4

Merged
mmmarinho merged 1 commit into
jazzyfrom
fix/sinusoidal-force-sensor-build
Aug 17, 2026
Merged

Fix sinusoidal_force_sensor build and runtime, set wave to 25 Hz#4
mmmarinho merged 1 commit into
jazzyfrom
fix/sinusoidal-force-sensor-build

Conversation

@mmmarinho

Copy link
Copy Markdown
Contributor

Summary

Fixes the compilation error and the startup crash in the sinusoidal_force_sensor example, and sets the sinusoidal wave frequency to 25 Hz while keeping the 100 Hz publish rate.

Changes

All in src/examples/sinusoidal_force_sensor.cpp:

  1. Compilation errorDQ force({value, 0.0, 0.0}) failed with static assertion failed: THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE. The initializer list built a dynamic-size VectorXd, and Eigen's 3-scalar constructor requires a fixed-size vector. Now constructs from an explicit Vector3d:

    DQ force(Vector3d(value, 0.0, 0.0));
    DQ torque(Vector3d(0.0, value, 0.0));
  2. std::bad_weak_ptr crash at startup — the constructor called shared_from_this() before the owning shared_ptr existed. main now builds the node first and then calls attach_server() (which creates the ForceSensorServer and timer), so shared_from_this() is valid.

  3. 25 Hz wave at 100 Hz publish rate — separated the previously-conflated constants:

    const double frequency_hz  = 25.0;   // sine wave frequency
    const double tick_rate_hz  = 100.0;  // timer / publish rate

    The timer period and phase advance use tick_rate_hz; the sine uses frequency_hz/angular_frequency. Previously a 100 Hz wave sampled at 100 Hz aliased to ~0.

Verification

Verified in the repo's Docker environment (murilomarinho/sas:jazzy, same as CI):

  • colcon build finishes cleanly (exit 0)
  • Node starts without aborting; publishes on /sinusoidal_force_sensor/get/wrench
  • Captured WrenchStamped samples show one full sine period every 4 ticks (40 ms → 25 Hz) with amplitude 2.0

This PR was created by an AI agent (OpenHands) on behalf of the user.

- Fix compilation error: construct DQ from Vector3d instead of an
  initializer list (Eigen 3-scalar ctor requires fixed-size vector)
- Fix std::bad_weak_ptr crash at startup: build the node in main first,
  then attach the ForceSensorServer via attach_server() so that
  shared_from_this() is valid
- Set the sinusoidal wave frequency to 25 Hz while keeping the
  100 Hz publish tick rate (separate frequency_hz from tick_rate_hz)

Co-authored-by: openhands <openhands@all-hands.dev>
@mmmarinho
mmmarinho marked this pull request as ready for review August 17, 2026 21:35

@mmmarinho mmmarinho left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

@mmmarinho
mmmarinho merged commit fe5e166 into jazzy Aug 17, 2026
6 checks passed
@mmmarinho
mmmarinho deleted the fix/sinusoidal-force-sensor-build branch August 17, 2026 21:37
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