Skip to content

Conversation

amlansahoo07
Copy link

The check_touch_down_condition() method in SwingTrajectoryController had incorrect logic that detected lift-off events instead of touchdown events. This caused step frequency optimization to fail with slow gaits, particularly crawl patterns at 0.5 Hz step frequency.

Implemented a robust three-stage touchdown detection algorithm:

  • Fixed core logic to detect touchdown instead of lift-off
  • Added proper state management with automatic reset
  • Implemented stability delay to prevent premature optimization triggers

This fix enables proper step frequency optimization for crawl gaits and improves the reliability of gait adaptation across all locomotion patterns.

@Danfoa Danfoa requested a review from Copilot July 15, 2025 11:44
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR corrects the touchdown detection in SwingTrajectoryController by switching from lift-off to touchdown logic, adding stateful timing, and enforcing a short stability delay before triggering optimization.

  • Corrected core event detection from swing-to-stance (touchdown) rather than stance-to-swing
  • Introduced internal state tracking for full-stance timing and recent touchdown flags
  • Added a stability delay (based on simulation dt) to prevent premature optimization triggers
Comments suppressed due to low confidence (2)

quadruped_pympc/helpers/swing_trajectory_controller.py:147

  • [nitpick] New multi-stage touchdown timing logic is complex and critical for gait optimization. Please add unit tests (e.g., mocking contact transitions and varying dt) to verify correct behavior across edge cases.
    def check_touch_down_condition(self, current_contact, previous_contact):

quadruped_pympc/helpers/swing_trajectory_controller.py:200

  • The indentation for touch_down = 1 appears misaligned with its conditional block. Ensure it is nested under if self._recent_touchdown: so it only executes when intended and avoid a syntax error.
                        touch_down = 1

self._full_stance_start_time = current_time
else:
# Check if we've been in full stance long enough (e.g., 50ms for stability)
stability_delay = 25 * dt
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

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

[nitpick] The hardcoded multiplier 25 is a magic number. Consider extracting it into a named constant or configuration parameter (e.g., min_stability_steps) to improve clarity and make it easier to adjust.

Suggested change
stability_delay = 25 * dt
stability_delay = self.MIN_STABILITY_STEPS * dt

Copilot uses AI. Check for mistakes.

@giulioturrisi
Copy link
Collaborator

Thanks Amlan. I'm planning to review this PR this week.

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