Skip to content

Latest commit

 

History

History
167 lines (128 loc) · 5.79 KB

File metadata and controls

167 lines (128 loc) · 5.79 KB

Pan-Tilt Base v0.9 — Workspace Summary

1) What this project is

This is an ESP32 firmware for a mobile base that can run in multiple hardware modes:

  • UGV base only
  • UGV + RoArm-M2 manipulator
  • UGV + Pan/Tilt gimbal

Core runtime is in loop and command dispatch is in jsonCmdReceiveHandler.


2) High-level architecture

Main app

  • pan_tilt_base_v0.9.ino
    • Includes all modules
    • Initializes peripherals and subsystems in setup()
    • Runs periodic behavior in loop()

Hardware control modules

Communication & UI

System services

Configuration/state


3) Runtime flow

setup()

From setup:

  1. Serial + I2C init
  2. Power/battery + OLED init
  3. IMU init
  4. LED + filesystem init
  5. Motor pin/PWM init via movtionPinInit
  6. Servo UART init + servo checks
  7. Wi-Fi init + HTTP server + ESP-NOW
  8. Encoder init + PID init
  9. Creates/plays boot mission (boot)

loop()

From loop:

  1. Serial command input
  2. Web server client handling
  3. Module-specific update:
    • arm mode: constant control + arm feedback
    • gimbal mode: gimbal feedback + steady processing
  4. ESP-NOW deferred command handling
  5. Left/right speed read + PID compute (split compute)
  6. OLED update
  7. IMU update
  8. Base feedback flow via baseInfoFeedback
  9. Heartbeat timeout stop via heartBeatCtrl

4) Control model

Mode selection

  • mainType (vehicle kinematics preset)
  • moduleType (0 none, 1 arm, 2 gimbal) Defined in ugv_config.h, set by mm_settings.

Motion

Gimbal

  • Direct commands: gimbalCtrlSimple, gimbalCtrlMove, gimbalCtrlStop
  • User-shell mapping: gimbalUserCtrlShell maps differential speeds to pan/tilt directional commands

Arm

  • Kinematics + path smoothing (besselCtrl, IK/FK helpers)
  • Absolute/relative axis and joint control
  • Mission integration through command queue/file steps

5) JSON command protocol

Notable command groups:

  • Mobility: T=1,11,13,138..140
  • Gimbal: T=133..137,141
  • Arm: T=101..123,+
  • File/Mission: T=200..231,241+
  • System: T=600..605,900

6) Important implementation notes (read before edits)

  1. Global shared state is heavy
    Most modules mutate globals from ugv_config.h. Keep side effects explicit.

  2. Command contract stability matters
    Avoid changing existing T IDs in json_cmd.h; UI and external tools depend on them.

  3. Safety behavior exists but is distributed

    • Heartbeat timeout stop in motion module
    • Servo torque release controls in arm/gimbal paths
    • Mission abort on serial activity
  4. Web endpoint behavior

  5. Potential defects to verify

    • Typo family: movtion naming is intentional in current codebase
    • In gimbal shell conditionals, comparisons like abs(lSpd) == abs(lSpd) look suspicious (likely intended right-side variable)
    • HTTP response content type uses "text/plane" (likely should be "text/plain")

7) Fast orientation for a new contributor

  1. Read:

  2. Then follow your feature path:

  3. Validate on hardware:

    • No-motion boot
    • Heartbeat stop
    • Base feedback JSON shape
    • Emergency stop path

8) Suggested next cleanup tasks

  • Normalize typo naming (movtion -> motion) only behind compatibility wrappers
  • Fix suspicious gimbal conditional comparisons
  • Correct HTTP content-type typo
  • Add lightweight command schema validation at dispatch
  • Separate hardware abstraction from command parser for easier testing