Skip to content

Conversation

@wexler
Copy link

@wexler wexler commented Jan 26, 2026

Summary

This PR fixes crashes when using QDriverStation with WPILib 2026 simulation.

Problem

When connecting QDriverStation to WPILib 2026's simulation, the robot code would crash with a SIGSEGV in DecodeUDP due to protocol encoding mismatches.

Root Cause

Two issues in the joystick packet encoding:

  1. Joystick size calculation bug: get_joystick_size() was including the length byte itself in the count. WPILib expects the length byte to represent the size of data after the length byte.

  2. Button encoding bug: The code always sent 2 bytes for button data, but WPILib expects (numButtons + 7) / 8 bytes (variable length based on button count).

Changes

  • Fix get_joystick_size() to correctly calculate joystick data size (excluding length byte)
  • Add get_button_bytes() helper function for proper button byte count calculation
  • Fix button encoding to use variable-length bytes instead of fixed 2 bytes
  • Add WPILib HAL limits (12 axes, 32 buttons, 12 POVs) to prevent protocol errors with controllers that exceed these limits
  • Expand button support from 16 to 32 buttons

Testing

Tested with:

  • WPILib 2026.2.1 simulation on macOS (Apple Silicon)
  • PS2 controller via USB
  • QDriverStation Qt6 port

Robot simulation now runs stably without crashes when QDriverStation connects.

Test plan

  • Build LibDS and QDriverStation
  • Run WPILib 2026 robot simulation with DS socket enabled
  • Connect QDriverStation to simulation
  • Verify no crash occurs
  • Verify joystick input is received by the robot

🤖 Generated with Claude Code

wexler and others added 2 commits November 11, 2025 00:22
Replace qMakePair<T1,T2>() calls with QPair<T1,T2>() constructor
Qt 6 requires rvalue references for qMakePair arguments
This fixes crashes when using QDriverStation with WPILib 2026 simulation.

Changes:
- Fix joystick size calculation to not include length byte in the count
- Fix button encoding to use variable-length bytes ((numButtons+7)/8)
  instead of always sending 2 bytes
- Add WPILib HAL limits (12 axes, 32 buttons, 12 POVs) to prevent
  protocol errors with controllers that exceed these limits
- Support up to 32 buttons (was limited to 16)

The crash was caused by WPILib's DecodeUDP receiving incorrect packet
sizes, leading to invalid memory access.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant