Coding
PromptBeginner5 minmarkdown
Markdown Converter
Agent skill for markdown-converter
22
This is a **hospital rehabilitation system** with three integrated components:
Sign in to like and favorite skills
This is a hospital rehabilitation system with three integrated components:
BipedRobot/) - 10-servo walking robot for patient rehabilitation assistanceCarry_robot/) - ESP32 transport robot with Mecanum wheels for medication delivery & biped transportHospital Dashboard/) - Full-stack web app (Express.js + React/Vite) for management[Dashboard Frontend:5173] <--> [Backend API:3000] <--> [MongoDB] ^ | HTTP REST +--------------+---------------+ v v [Carry Robot ESP32] [Biped Robot ESP32s] ^ (Walking + User Auth) | ESP-NOW | v | RFID checkpoint [ESP32-CAM Module] v [Location to Dashboard]
BipedRobot/)BipedUserManager/)| Index | Joint | Pin | Function |
|---|---|---|---|
| 0 | HIP_PITCH_L | 0 | Left leg swing forward/backward |
| 1 | HIP_ROLL_L | 1 | Left leg lateral movement |
| 2 | KNEE_PITCH_L | 2 | Left knee bend |
| 3 | ANKLE_PITCH_L | 3 | Left foot tilt front/back |
| 4 | ANKLE_ROLL_L | 4 | Left foot tilt left/right |
| 5 | HIP_PITCH_R | 5 | Right leg swing (inverted) |
| 6 | HIP_ROLL_R | 6 | Right leg lateral |
| 7 | KNEE_PITCH_R | 7 | Right knee (inverted) |
| 8 | ANKLE_PITCH_R | 8 | Right foot pitch (inverted) |
| 9 | ANKLE_ROLL_R | 9 | Right foot roll |
FSR402 Foot Sensor Layout (per foot):
[TOE] ← Front sensor (toe contact) | [L]-------[R] ← Left/Right edge sensors (lateral balance) | [HEEL] ← Rear sensor (heel contact)
| Position | Left Foot | Right Foot | Purpose |
|---|---|---|---|
| Toe | FSR_L_TOE | FSR_R_TOE | Detect forward tilt, toe-off phase |
| Left Edge | FSR_L_LEFT | FSR_R_LEFT | Detect lateral roll to left |
| Right Edge | FSR_L_RIGHT | FSR_R_RIGHT | Detect lateral roll to right |
| Heel | FSR_L_HEEL | FSR_R_HEEL | Detect heel strike, backward tilt |
BipedRobot/BipedRobot.ino - Walking Controller: servo control, balance, UART receiveBipedRobot/ServoController.h - PCA9685 servo abstractionBipedRobot/Kinematics.h - Leg inverse kinematicsBipedRobot/config.h - Servo limits, PID gains, pin definitionsBipedUserManager/ - User Manager: RFID, OLED, WiFi, buttons (source files in src/)The balance system runs at 50Hz and uses sensor fusion:
Kalman Filter for MPU6050:
1. Predict: angle += gyroRate * dt 2. Update: fuse with accelerometer angle 3. Output: filtered pitch & roll angles
Control Loop:
output = KP*error + KD*gyroRateSafety Features:
Movement patterns are predefined keyframe sequences, but balance is calculated in real-time:
Gait Phases (per step cycle):
PHASE_DOUBLE_SUPPORT → Both feet on ground (stable) PHASE_RIGHT_SWING → Right foot lifting, left foot supporting PHASE_DOUBLE_SUPPORT → Transfer weight PHASE_LEFT_SWING → Left foot lifting, right foot supporting
Predefined Movement Patterns:
| Command | Pattern Description |
|---|---|
| FORWARD | Hip pitch sequence + knee lift + weight shift |
| BACKWARD | Reverse hip pitch + backward step |
| TURN_LEFT | Left hip roll out + right step forward + rotate |
| TURN_RIGHT | Right hip roll out + left step forward + rotate |
Balance During Movement:
Walking → User: "STEP:123\n" # Step count update Walking → User: "BALANCE:OK\n" # Balance status User → Walking: "CMD:FWD\n" # Forward command User → Walking: "CMD:BACK\n" # Backward command User → Walking: "CMD:LEFT\n" # Turn left User → Walking: "CMD:RIGHT\n" # Turn right User → Walking: "SPEED:75\n" # Speed (0-100) User → Walking: "STOP\n" # Emergency stop
BipedUserManager/)Hardware Components:
Pin Configuration:
| Component | Pins |
|---|---|
| RFID RC522 | SS=5, RST=4, SCK=18, MISO=19, MOSI=23 |
| OLED I2C | SDA=21, SCL=22 |
| Buttons | FWD=32, BACK=33, LEFT=25, RIGHT=26, STOP=27 |
| Encoder | CLK=34, DT=35, SW=39 |
| UART | TX=17, RX=16 |
Key Features:
BipedRobot-Setup / biped123)/api/patients/by-card/:cardNumber → Start sessionOLED Display States:
[IDLE] [SESSION] +------------------+ +------------------+ | BIPED ROBOT | | Nguyen Van A | <- Patient name |------------------| |------------------| | San sang su dung | | 12345 | <- Steps (large) | Quet the bat dau | | buoc | +------------------+ +------------------+
API Endpoints Used:
GET /api/patients/by-card/:cardNumber # Lookup patient by RFID POST /api/biped/session/start # Start rehabilitation session PUT /api/biped/session/:id/step # Update step count POST /api/biped/session/:id/end # End session POST /api/biped/location # Report checkpoint location
Carry_robot/)STATE_IDLE_AT_MED → STATE_WAIT_CARGO → STATE_RUN_OUTBOUND → STATE_WAIT_AT_DEST → STATE_RUN_RETURNMecanumDrive, GyroTurn, NFCReader, ObstacleDetector, FollowMode)MODE_AUTO (NFC navigation), MODE_MANUAL (RF remote), MODE_FOLLOW (AprilTag tracking via ESP32-CAM)UIDs are hard-coded in
CHECKPOINT_TABLE[] in config.h. Node naming: MED, H_MED, H_BOT, H_TOP, J4, R{1-4}M{1-3}, R{1-4}O{1-3}, R{1-4}D{1-2}
cd Carry_robot pio run # Build pio run -t upload # Flash pio device monitor # Serial monitor (115200 baud)
| Endpoint | Purpose |
|---|---|
| Robot heartbeat (PUT) |
| Poll for pending mission |
| Update mission progress |
| Patient CRUD with photo uploads |
| Biped rehabilitation sessions |
| Biped checkpoint location report |
{ sessionId: String, // Unique session ID robotId: String, // Biped robot ID userId: String, // RFID user ID userName: String, // Display name patientId: String, // Linked patient startTime: Date, // Session start endTime: Date, // Session end totalSteps: Number, // Step count from Walking ESP32 duration: Number, // Minutes status: 'active' | 'completed' | 'interrupted', telemetry: { avgHeartRate, maxHeartRate, minHeartRate, caloriesBurned, distanceWalked } }
Robot - tracks status, battery, location (type: carry or biped)TransportMission - full route with outboundRoute[] and returnRoute[]BipedSession - rehabilitation session (user, steps, duration)MapGraph - nodes/edges for pathfindingcarry, bipedidle, busy, charging, maintenance, offline, low_battery, follow, manual, waitingR{room}{M|O}{1-3} (e.g., R1M2 = Room 1, M-side, bed 2)src/app/api/ - API service layer (mirrors backend routes)src/app/components/ - Feature components (PatientDashboard, RobotManagement, BedMap)src/app/types/ - TypeScript interfaces (robot.ts, patient.ts)cd "Hospital Dashboard" # Option 1: Use batch script start-servers.bat # Option 2: Manual cd Backend && npm run dev # Port 3000 cd Frontend && npm run dev # Port 5173 (proxies /api to backend)
CHECKPOINT_TABLE[] in config.h (Carry_robot/src/config.h)MapGraph in MongoDB via seed script or APIFeatureName.h/cpp in Carry_robot/src/main.cpp, add timing variable if neededStateMachine if affects mission flowBipedRobot/config.hBipedRobot/Kinematics.h for leg position calculationsconfig.h for balanceRoutes are computed in
missions.js (Hospital Dashboard/Backend/src/routes/missions.js) using buildAdj() for graph traversal. Hard-coded routes exist for the 4-room hospital layout.
LEFT_GAIN/RIGHT_GAIN in config.h for straight-line correction