Year 2 Project: Host Computer Development

Juntong20XX 于 2025-02-12 发布

Link to Chinese Version.

上位机项目 IDLE 截图

In embedded system development, the host computer refers to the device that interacts with the slave computer, typically acting as the controller.

In this project, the host computer uses a Raspberry Pi 5, and the salve computer is an Arduino Uno, connected via USB.

connected via USB

Code Design

The workflow of the host computer can be simplified as: responding to salve computer requests.

Host Computer Code SD

stateDiagram
    [*] --> WaitForRequest

    WaitForRequest --> HandlePing : Receive ping command
    HandlePing --> WaitForRequest : Send connection response

    WaitForRequest --> HandleWaitCommand : Receive WaitCommand
    HandleWaitCommand --> WaitForRequest : Send next instruction

    WaitForRequest --> HandleFailure : Receive failure report
    HandleFailure --> WaitForRequest : Requeue instruction

    state HandlePing {
        Send_connection_response
    }

    state HandleWaitCommand {
        Check_command_queue
        Send_next_instruction
    }

    state HandleFailure {
        Log_error
        Rollback_command_to_queue
    }

Additionally, to package the host computer as an SDK, we configured pyproject.toml for easy distribution as a Python module.

Issues & Solutions

Parameter Parsing Exception

Analysis: salve computer packets only use first 8 bytes as valid data, causing parsing issues in Python’s strong typing system which requires handling all 16 bytes.

Solution: Modify salve computer to write zeros in unused bytes.

Serial Port Not Found

Analysis: Development environment used Linux (Raspberry Pi OS) via VS Code Remote, while debugging used Windows (laptop).

Solution: Add serial port parameter configuration in test code.

Testing

Created test programs in /test directory that:

  1. Prompt for serial port address
  2. Create command queue using Python built-in list
  3. Pass queue and port address to communication function
  4. Run as separate thread
  5. Enter main loop accepting servo rotation degree inputs

host and salve computer testing is synchronized. Refer to the salve computer development blog for more details.

Below is a screenshot from testing video:

舵机在上位机操控下旋转