Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 4, 2025

This PR implements a comprehensive Python WebSocket client that connects to the VEX Extension's WebSocket server to receive real-time telemetry data from VEX robots, including motor temperatures, RPM, battery voltage, and gyro data.

Key Features

🔌 WebSocket Client (websocket_client.py)

  • Connects to VEX Extension server at ws://localhost:7071/vexrobotics.vexcode/device
  • Real-time parsing of motor telemetry data from robot's printf() output
  • Automatic reconnection with robust error handling
  • Optional CSV data logging with timestamps
  • Comprehensive command-line interface with configurable host/port

📊 Enhanced Motor Monitoring

Enhanced the C++ motorMonitor() function to output detailed motor data:

  • Motor RPM: Both commanded and actual speeds
  • Motor Position: Encoder positions in revolutions
  • Motor Current: Current draw in amperes
  • Temperature Monitoring: All four drive motors
  • Battery Voltage: Real-time voltage monitoring
  • Inertial Data: Gyro pitch, roll, yaw axes

🎯 Data Processing

  • Intelligent parsing of log messages with regex patterns
  • Structured data extraction from raw WebSocket messages
  • Real-time display with status indicators and alerts
  • Statistical analysis and session summaries

Usage Examples

# Basic connection
python3 websocket_client.py

# Save telemetry to CSV file
python3 websocket_client.py --save-to-file

# Connect to remote robot
python3 websocket_client.py --host 192.168.1.100

# Advanced analysis with custom alerts
python3 example_usage.py

Sample Output

==================================================
MOTOR TELEMETRY - Time: 15.234s
==================================================
Motor Temperatures:
  LEFT: 45°C ✅ OK
  RIGHT: 48°C ✅ OK
Battery: 12.5V ✅ OK
Motor Details:
  FLM:
    RPM: 150 cmd / 145 actual
    Position: 2.75 rev
    Current: 1.20A
==================================================

Files Added

  • websocket_client.py: Main WebSocket client with full feature set
  • example_usage.py: Advanced usage example with real-time analysis
  • test_websocket_client.py: Comprehensive test suite
  • requirements.txt: Python dependencies
  • WEBSOCKET_README.md: Complete documentation and usage guide

Testing

All functionality is thoroughly tested without requiring live VEX hardware:

python3 test_websocket_client.py
# ✅ All tests passed!

The implementation follows the exact WebSocket URL format specified in the issue (ws://localhost:7071/vexrobotics.vexcode/device) and provides the requested RPM data along with comprehensive motor telemetry monitoring.

Fixes #32.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 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] Websocket from vscode vex extention Implement Python WebSocket client for VEX Extension telemetry monitoring Jun 4, 2025
@Copilot Copilot AI requested a review from Voidless7125 June 4, 2025 03:53
Copilot finished work on behalf of Voidless7125 June 4, 2025 03:53
@Voidless7125 Voidless7125 marked this pull request as ready for review June 17, 2025 19:32
@Copilot Copilot AI review requested due to automatic review settings June 17, 2025 19:32
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 introduces a comprehensive Python WebSocket client to monitor VEX robot telemetry while enhancing motor data logging in the robot’s C++ code.

  • Implements a Python WebSocket client with real-time telemetry parsing, CSV logging, and a command-line interface.
  • Adds advanced motor data analysis via an extended client and includes a full test suite and documentation updates.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
websocket_client.py Implements the WebSocket client with real-time telemetry parsing, data logging, and error handling.
test_websocket_client.py Provides tests simulating telemetry messages to validate parsing functionality.
src/functions.cpp Enhances the motorMonitor() function to log detailed motor data using modern C++ formatting.
example_usage.py Demonstrates advanced analysis by extending the WebSocket client for custom telemetry processing.
WEBSOCKET_README.md Updates documentation covering installation, usage, data formats, and troubleshooting guidance.

Comment on lines +286 to +296
# Run forever with reconnection logic
while True:
try:
self.ws.run_forever()
except KeyboardInterrupt:
logger.info("Interrupted by user")
break
except Exception as e:
logger.error(f"Connection error: {e}")
logger.info("Attempting to reconnect in 5 seconds...")
time.sleep(5)
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

Consider adding a maximum retry limit or exponential backoff for reconnection attempts to avoid potential endless loops in case of persistent connection failures.

Suggested change
# Run forever with reconnection logic
while True:
try:
self.ws.run_forever()
except KeyboardInterrupt:
logger.info("Interrupted by user")
break
except Exception as e:
logger.error(f"Connection error: {e}")
logger.info("Attempting to reconnect in 5 seconds...")
time.sleep(5)
# Run with reconnection logic, including retry limit and exponential backoff
max_retries = 10 # Maximum number of reconnection attempts
retry_count = 0
backoff = 5 # Initial backoff in seconds
max_backoff = 60 # Maximum backoff in seconds
while retry_count < max_retries:
try:
self.ws.run_forever()
retry_count = 0 # Reset retry count on successful connection
except KeyboardInterrupt:
logger.info("Interrupted by user")
break
except Exception as e:
retry_count += 1
logger.error(f"Connection error: {e}")
if retry_count >= max_retries:
logger.error("Maximum retry limit reached. Exiting.")
break
logger.info(f"Attempting to reconnect in {backoff} seconds (Retry {retry_count}/{max_retries})...")
time.sleep(backoff)
backoff = min(backoff * 2, max_backoff) # Exponential backoff with cap

Copilot uses AI. Check for mistakes.

logHandler("motorMonitor", motorTempsStr, Log::Level::Info);

// Log detailed motor data including RPM, current, and position
std::array motors = {&frontLeftMotor, &frontRightMotor, &rearLeftMotor, &rearRightMotor};
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

[nitpick] Explicitly specify the type for std::array (e.g., std::array<Motor*, 4>) for improved clarity and compatibility, even if type deduction is available in newer C++ standards.

Suggested change
std::array motors = {&frontLeftMotor, &frontRightMotor, &rearLeftMotor, &rearRightMotor};
std::array<Motor*, 4> motors = {&frontLeftMotor, &frontRightMotor, &rearLeftMotor, &rearRightMotor};

Copilot uses AI. Check for mistakes.

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.

Websocket from vscode vex extention
2 participants