Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 4, 2025

This PR completely rewrites the traction control, stability control, and ABS systems to implement proper functionality using motor velocity feedback and inertial sensor data as specified in the requirements.

🔧 What was broken

The existing implementations were fundamentally flawed:

// Old traction control - just set voltage to minimum motor speed
void applyTractionControl(double &forwardVolts) {
    double minSpeed = std::min({motor speeds...});
    forwardVolts = minSpeed;  // Makes no sense
}

// Old stability control - directly overrode motor commands
void applyStabilityControl(const double &forwardVolts) {
    double minSpeed = std::min(leftRPM, rightRPM);
    LeftDriveSmart.spin(fwd, minSpeed, volt);   // Bypassed normal control
    RightDriveSmart.spin(fwd, minSpeed, volt);
}

✨ What's implemented now

Traction Control

  • Slip Detection: Compares commanded velocity vs actual motor velocity to detect wheel slip
  • Power Reduction: Reduces motor power when slip threshold (50 RPM difference) is exceeded
  • Heading Correction: Uses inertial sensor during slip events to maintain direction
  • Debug Output: Prints slip values and corrections when enabled

Stability Control

  • Heading Maintenance: Uses InertialGyro.heading() for proportional correction during straight driving
  • Anti-tip Protection: Monitors pitch() and roll() to detect excessive tilt (15° threshold)
  • Yaw Rate Limiting: Prevents instability by limiting turn rate to 180°/sec maximum
  • Dynamic Target Updates: Adjusts target heading during intentional turns

ABS (Anti-lock Braking System)

  • Braking Detection: Identifies when robot is decelerating or commanded to brake
  • Lockup Prevention: Monitors for velocity drops >300 RPM indicating wheel lockup
  • Power Modulation: Reduces braking force by 50% when lockup detected
  • Momentum Preservation: Maintains minimum forward power during ABS activation

🎮 User Controls Added

  • Down Button: Toggle debug output on/off
  • L1: Toggle traction control
  • L2: Toggle stability control
  • R1: Toggle ABS
  • Brain Display: Shows current system states including debug status

🧪 Testing

Created comprehensive logic tests validating:

  • Slip detection algorithms work correctly
  • Heading correction applies appropriate voltage adjustments
  • ABS activates only when both braking and lockup conditions are met
  • All mathematical calculations produce expected results

📊 Impact

  • Minimal Changes: Only modified the three control functions and added toggle functionality
  • Backward Compatible: Existing drive modes and user control flow unchanged
  • Hardware Ready: Uses proper VEX APIs (motor.velocity(), inertial.heading(), etc.)
  • Configurable: All thresholds defined as constants for easy tuning

The implementation now provides real traction control, stability control, and ABS functionality instead of placeholder code that didn't actually work.

Fixes #37.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Rewrite traction and stability control and abs Rewrite traction control, stability control, and ABS with proper sensor-based implementations Jun 4, 2025
@Copilot Copilot AI requested a review from Voidless7125 June 4, 2025 03:36
Copilot finished work on behalf of Voidless7125 June 4, 2025 03:36
@Voidless7125 Voidless7125 marked this pull request as ready for review June 17, 2025 19:18
@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 19:18
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 rewrites the traction, stability, and ABS control systems to provide sensor-based adjustments for improved drive behavior and safety.

  • Implements advanced traction control using motor velocity feedback and inertial sensor data.
  • Updates stability control with proportional heading corrections, anti-tip protection, and yaw rate limiting.
  • Redesigns ABS logic to prevent wheel lockup and modulate braking power, and adds user toggles for these systems.
Comments suppressed due to low confidence (1)

src/comptition/comptition.cpp:239

  • The threshold for detecting a reverse or braking command is hard-coded. Consider defining a named constant (e.g. REVERSE_COMMAND_THRESHOLD) to improve clarity and ease future adjustments.
    if (forwardVolts < -1.0) { // Reverse/braking command

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Dominic Troy <[email protected]>
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.

Rewrite traction and stability control and abs
2 participants