This is a comprehensive Model Context Protocol (MCP) server that provides autonomous navigation capabilities for an RC car. The system integrates with a Flask server running on a QNX Pi to control physical motors and camera hardware.
The autonomous RC car system consists of:
- MCP Server (
mcp_server.py) - Provides LLM interface for autonomous navigation - Flask Server (
flask_motor_control.py) - Controls physical hardware on QNX Pi - Camera System - Takes photos and analyzes them with AI
- Motor Control - Controls forward, backward, left, and right movements
- Purpose: Move the RC car forward
- Duration: 0.1-1.0 seconds (default: 0.3s)
- Use Cases: Approaching targets, moving toward objectives
- Precision: Shorter durations (0.2-0.4s) for fine control
- Purpose: Move the RC car backward
- Duration: 0.1-1.0 seconds (default: 0.3s)
- Use Cases: Backing away from obstacles, repositioning
- Safety: Useful for avoiding collisions
- Purpose: Turn the RC car left (rotate in place)
- Duration: 0.1-1.0 seconds (default: 0.3s)
- Use Cases: Changing direction, aligning with targets
- Control: Shorter durations for fine adjustments
- Purpose: Turn the RC car right (rotate in place)
- Duration: 0.1-1.0 seconds (default: 0.3s)
- Use Cases: Changing direction, aligning with targets
- Control: Shorter durations for fine adjustments
- Purpose: Immediately stop all movement
- Use Cases: Safety, pausing movement, reassessing situation
- Response: Instant halt of all motors
- Purpose: Take a photo and analyze it for navigation
- Input: Description of what the car is trying to find
- Output: AI analysis with recommended next actions
- Analysis Codes:
GOAL_ACHIEVED: Target is centered and reachedMOVE_LEFT: Target visible on left sideMOVE_RIGHT: Target visible on right sideMOVE_FORWARD: Target visible but too farMOVE_BACKWARD: Target too closeTURN_LEFT: Target not visible, search leftTURN_RIGHT: Target not visible, search rightNOT_FOUND: Target completely absent
- Purpose: Get system health and status information
- Returns: Connection status, available tools, configuration
- Use Cases: Debugging, monitoring system health
- Continuous Assessment: Always take photos to understand current position
- Incremental Movement: Use short, controlled movements (0.2-0.4s)
- Visual Feedback: Analyze each photo to determine next action
- Goal-Oriented: Keep the objective in mind with every decision
- Safety First: Avoid obstacles and use conservative movements
- Initial Assessment: Take photo to understand current situation
- Analysis: AI analyzes photo based on goal description
- Decision: Choose appropriate movement based on analysis
- Execution: Execute movement with appropriate duration
- Reassessment: Take new photo and repeat process
- Goal Achievement: Continue until target is reached
- Forward: Use for approaching targets or moving toward objectives
- Backward: Use for backing away from obstacles or repositioning
- Left/Right Turns: Use for changing direction or aligning with targets
- Fine Adjustments: Use 0.2-0.3s durations for precise positioning
- Search Patterns: Use systematic turns when target is not visible
BASE_URL = "http://10.33.35.1:5000" # Flask server on QNX Pi
LAPTOP_IP = "10.33.49.88" # Laptop IP for processing
LAPTOP_PORT = 8000 # Laptop port for processingDEFAULT_DURATION = 0.3 # Default movement duration
MAX_DURATION = 1.0 # Maximum safe duration
MIN_DURATION = 0.1 # Minimum duration# Move forward for 0.3 seconds
move_forward(duration=0.3)
# Turn left for 0.2 seconds (fine adjustment)
turn_left(duration=0.2)
# Stop all movement
stop_car()# Take photo and analyze for goal
result = take_photo_and_analyze("Find a red ball on the ground")
# Based on analysis, execute appropriate movement
if "MOVE_LEFT" in result["analysis_result"]:
turn_left(duration=0.2)
elif "MOVE_FORWARD" in result["analysis_result"]:
move_forward(duration=0.3)goal = "Find a keychain object on the ground"
# Initial assessment
photo_result = take_photo_and_analyze(goal)
# Navigation loop
while "GOAL_ACHIEVED" not in photo_result["analysis_result"]:
# Execute movement based on analysis
if "MOVE_LEFT" in photo_result["analysis_result"]:
turn_left(duration=0.2)
elif "MOVE_RIGHT" in photo_result["analysis_result"]:
turn_right(duration=0.2)
elif "MOVE_FORWARD" in photo_result["analysis_result"]:
move_forward(duration=0.3)
elif "TURN_LEFT" in photo_result["analysis_result"]:
turn_left(duration=0.4)
elif "TURN_RIGHT" in photo_result["analysis_result"]:
turn_right(duration=0.4)
# Reassess
photo_result = take_photo_and_analyze(goal)Run the comprehensive test suite:
python test_mcp_server.py- Flask server connection
- Movement endpoints
- Photo capture and analysis
- Movement sequences
- Duration control
- Autonomous navigation simulation
- Duration Limits: Never use durations longer than 1.0 seconds
- Movement Validation: All durations are clamped to safe ranges
- Error Handling: All requests include timeout and error handling
- Stop Function: Always available for emergency stopping
- Conservative Movements: Default to shorter durations for safety
- QNX Pi with motor control hardware
- Camera system for photo capture
- Network connectivity between components
- Python 3.7+
- FastMCP library
- Requests library
- Flask server running on QNX Pi
- Flask server accessible at
http://10.33.35.1:5000 - Laptop processing available at
10.33.49.88:8000
- Frequent Photos: Take photos often to maintain situational awareness
- Short Movements: Use 0.2-0.4s durations for precise control
- Systematic Search: Use systematic patterns when target is not visible
- Goal Focus: Always keep the objective in mind
- Safety First: Prioritize safety over speed
- Error Recovery: Handle errors gracefully and retry when appropriate
- Connection Errors: Check network connectivity to Flask server
- Photo Failures: Verify camera system is working
- Movement Issues: Check motor connections and power
- Analysis Errors: Verify AI processing system is available
# Check system status
status = get_car_status()
# Test individual movements
move_forward(duration=0.1)
stop_car()
# Test photo system
photo_result = take_photo_and_analyze("Test goal")For issues or questions:
- Check the test script output
- Verify network connectivity
- Test individual components
- Review system logs
The autonomous RC car system is designed to be robust, safe, and capable of navigating to find specific objects or locations based on visual feedback and AI analysis.