Base StackChan : fiche matériel, firmware de test servos, outils série
- docs/hardware-reference.md : specs K151, brochage, bus servo, firmwares - firmware/ : PlatformIO + pioarduino (core Arduino 3.3.13), M5StackChan 1.1.1 ; calibration, séquence de test et commandes série bornées - tools/ : lecture et envoi de commandes série (gère le reset à l'ouverture) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4f74d89 added
.gitignore +16 -0 | new file mode 100644 | ||
| @@ -0,0 +1,16 @@ | ||
| 1 | +# PlatformIO | |
| 2 | +.pio/ | |
| 3 | +.pioenvs/ | |
| 4 | +.piolibdeps/ | |
| 5 | + | |
| 6 | +# Éditeurs | |
| 7 | +.vscode/ | |
| 8 | +.idea/ | |
| 9 | + | |
| 10 | +# Python | |
| 11 | +__pycache__/ | |
| 12 | +*.pyc | |
| 13 | +.venv/ | |
| 14 | + | |
| 15 | +# macOS | |
| 16 | +.DS_Store | |
| new file mode 100644 | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | +# PlatformIO | ||
| 2 | +.pio/ | ||
| 3 | +.pioenvs/ | ||
| 4 | +.piolibdeps/ | ||
| 5 | + | ||
| 6 | +# Éditeurs | ||
| 7 | +.vscode/ | ||
| 8 | +.idea/ | ||
| 9 | + | ||
| 10 | +# Python | ||
| 11 | +__pycache__/ | ||
| 12 | +*.pyc | ||
| 13 | +.venv/ | ||
| 14 | + | ||
| 15 | +# macOS | ||
| 16 | +.DS_Store | ||
added
docs/hardware-reference.md +146 -0 | new file mode 100644 | ||
| @@ -0,0 +1,146 @@ | ||
| 1 | +# M5Stack StackChan — fiche technique | |
| 2 | + | |
| 3 | +Collecté le 2026-11-27. Sources en bas de page. Les points marqués **⚠** sont ambigus ou contradictoires entre les sources. | |
| 4 | + | |
| 5 | +## 1. Identification | |
| 6 | + | |
| 7 | +| | | | |
| 8 | +|---|---| | |
| 9 | +| Produit | M5Stack **StackChan** « Kawaii co-created open-source AI desktop robot » | | |
| 10 | +| SKU | **K151** (robot seul) · **K151-R** (robot + télécommande) | | |
| 11 | +| Contrôleur | **M5Stack CoreS3** (amovible, fixé sur le corps) | | |
| 12 | +| Dimensions | 54.0 × 70.5 × 61.5 mm | | |
| 13 | +| Poids | 187.2 g (robot) · 37.6 g (télécommande) | | |
| 14 | + | |
| 15 | +Il existe deux mondes distincts : | |
| 16 | +- **Produit officiel M5Stack** (K151, 2026) : corps motorisé avec électronique dédiée + CoreS3, firmware usine ESP-IDF. | |
| 17 | +- **Projet communautaire Stack-chan** (Shinya Ishikawa / `stack-chan` org, Apache 2.0) : l'origine du concept, firmware Moddable JS/TS, qui supporte désormais aussi le K151 (« M5StackChan CoreS3 »). | |
| 18 | + | |
| 19 | +## 2. Contrôleur CoreS3 | |
| 20 | + | |
| 21 | +| Élément | Composant | | |
| 22 | +|---|---| | |
| 23 | +| SoC | ESP32-S3, Xtensa LX7 dual-core 240 MHz | | |
| 24 | +| Mémoire | 16 MB Flash, 8 MB PSRAM (Quad) | | |
| 25 | +| Radio | Wi-Fi 2.4 GHz 802.11 b/g/n, Bluetooth 5 LE (ESP-NOW utilisé pour la télécommande) | | |
| 26 | +| Écran | IPS 2.0", 320×240, ILI9342C → **ILI9342E depuis 2026-08-07** (⚠ M5GFX ≥ 0.2.27 requis) | | |
| 27 | +| Tactile écran | Capacitif multi-touch, FT6336U | | |
| 28 | +| Caméra | GC0308, 0.3 MP (640×480) | | |
| 29 | +| Audio entrée | 2 micros, codec ES7210 | | |
| 30 | +| Audio sortie | HP 1 W, ampli I2S AW88298 16 bits | | |
| 31 | +| Capteurs | Proximité/lumière LTR-553ALS-WA · IMU 9 axes BMI270 + BMM150 | | |
| 32 | +| Alim / RTC | PMIC AXP2101 · RTC BM8563 | | |
| 33 | +| Divers | microSD, USB-C (CDC + OTG full-speed), boutons power/reset | | |
| 34 | + | |
| 35 | +Pinmap complet du CoreS3 : https://docs.m5stack.com/en/core/CoreS3#pinmap | |
| 36 | + | |
| 37 | +## 3. Corps du robot (base) | |
| 38 | + | |
| 39 | +| Élément | Composant | Notes | | |
| 40 | +|---|---|---| | |
| 41 | +| Servo pan (X / yaw) | Feetech **SCS0009** (série TTL, avec retour position) | ID **1**, rotation 360° | | |
| 42 | +| Servo tilt (Y / pitch) | Feetech **SCS0009** | ID **2**, course 90°, **rester entre 5° et 85°** (risque de calage / casse) | | |
| 43 | +| LED | 12 × WS2812C | idx 0-5 gauche, 6-11 droite ; pilotées **via l'IO expander** | | |
| 44 | +| Tactile tête | 3 zones, Si12T (compatible TSM12) | clic, swipe avant/arrière | | |
| 45 | +| NFC | ST25R3916 | lecture + émulation | | |
| 46 | +| IR | Récepteur IRM56384 + émetteur | protocole NEC dans les exemples | | |
| 47 | +| Batterie | 550 mAh (⚠ 700 mAh annoncé par un revendeur) | mesure via INA226 (shunt 10 mΩ) | | |
| 48 | +| IO expander | PY32L020 | IO1 = VM_EN (alim servos), IO14 = data LED RGB | | |
| 49 | +| Extension | 3 × Grove, trous compatibles LEGO | | | |
| 50 | + | |
| 51 | +### Brochage (ESP32-S3) | |
| 52 | + | |
| 53 | +| GPIO | Fonction | | |
| 54 | +|---|---| | |
| 55 | +| G6 | Servo bus TX (UART1) | | |
| 56 | +| G7 | Servo bus RX (UART1) | | |
| 57 | +| G5 | IR émission | | |
| 58 | +| G10 | IR réception | | |
| 59 | +| G11 | I2C SCL (corps) | | |
| 60 | +| G12 | I2C SDA (corps) | | |
| 61 | +| G2 / G1 | Port A (Grove) | | |
| 62 | +| G9 / G8 | Port B (Grove) | | |
| 63 | +| G17 / G18 | Port C (Grove) | | |
| 64 | + | |
| 65 | +### Bus I2C du corps | |
| 66 | + | |
| 67 | +| Adresse | Composant | | |
| 68 | +|---|---| | |
| 69 | +| 0x41 | INA226 (batterie : tension / courant / puissance) | | |
| 70 | +| 0x50 | ST25R3916 (NFC) | | |
| 71 | +| 0x68 | Si12T (tactile tête) | | |
| 72 | +| 0x6F (0x71 si ADD_SEL haut) | PY32L020 (IO expander) | | |
| 73 | + | |
| 74 | +### Servos — détails confirmés dans le code BSP | |
| 75 | + | |
| 76 | +- Bus série half-duplex Feetech **SCS**, **UART1 à 1 000 000 baud**, TX=6 / RX=7 (`_scs_bus.begin(UART_NUM_1, 1000000, 6, 7)`). | |
| 77 | +- L'alimentation servos doit être activée via l'IO expander (IO VM_EN) avant usage. | |
| 78 | +- Unités logicielles : **1/10 de degré**. | |
| 79 | + - Yaw (ID 1) : limites −1280…+1280, zéro brut par défaut 460, mode PWM/rotation continue possible (`rotate(-1000…1000)`). | |
| 80 | + - Pitch (ID 2) : limites 0…900, zéro brut par défaut 620. | |
| 81 | + - Position brute servo : 0…1000. | |
| 82 | +- Calibration du zéro stockée en NVS : namespace `servo`, clés `zero_pos_1` / `zero_pos_2`. À refaire après flash d'un nouveau firmware. | |
| 83 | +- Sécurité : ne pas forcer les axes à la main quand les moteurs peuvent être alimentés. | |
| 84 | + | |
| 85 | +## 4. Firmwares et environnements | |
| 86 | + | |
| 87 | +| Option | Langage / framework | Statut | | |
| 88 | +|---|---|---| | |
| 89 | +| **Firmware usine M5Stack** — [m5stack/StackChan](https://github.com/m5stack/StackChan) `firmware/` | C/C++ **ESP-IDF v6.1** | Agent IA XiaoZhi (wake word « Hi, StackChan »), avatar, caméra, danse, App Center, OTA, ESP-NOW. App mobile « StackChan World ». Le dépôt contient aussi `app/`, `remote/`, `server/`. | | |
| 90 | +| **Arduino / PlatformIO** — lib [M5StackChan](https://github.com/m5stack/StackChan-BSP) v1.1.1 (MIT) | C++ | Carte « M5CoreS3 », board pkg ≥ 3.2.2 (≥ 3.3.7 pour tactile), M5Unified ≥ 0.2.11, M5GFX ≥ 0.2.18 (≥ 0.2.27 pour ILI9342E). Dépendances : IRremoteESP8266, M5Unit-NFC. Exemples : Servo, RGB, TouchSensor, NFC, IR, INA226. | | |
| 91 | +| **UiFlow2 / MicroPython** | Python | `from hardware.stackchan import StackChan` ; API servo, RGB, touch, batterie, NFC, caméra + détection de visage. | | |
| 92 | +| **Stack-chan communautaire** — [stack-chan/stack-chan](https://github.com/stack-chan/stack-chan) (Apache 2.0) | JS/TS sur **Moddable SDK** | Architecture host + « MODs » rechargeables sans reflasher le host. Cible de référence : « M5StackChan CoreS3 ». TTS (VOICEVOX, ElevenLabs, OpenAI…), conversation WebRTC, éditeur de visage, simulateur Wasm, Blockly. Installeur web. | | |
| 93 | +| ESPHome / Home Assistant | YAML | Fonctions de base seulement (voix, écran, touch, servos). ⚠ page doc HA en 404 au moment de la collecte. | | |
| 94 | + | |
| 95 | +### API Arduino (résumé) | |
| 96 | + | |
| 97 | +```cpp | |
| 98 | +#include <M5Unified.h> | |
| 99 | +#include <M5StackChan.h> | |
| 100 | + | |
| 101 | +void setup() { M5StackChan.begin(); } // M5.begin + touch + IO expander + servos + INA226 | |
| 102 | +void loop() { | |
| 103 | + M5StackChan.update(); // obligatoire à chaque boucle | |
| 104 | + M5StackChan.Motion.move(x, y); // ou moveX(angle, speed), moveY(...), rotateX(vel), goHome() | |
| 105 | + M5StackChan.setRgbColor(i, r, g, b); M5StackChan.refreshRgb(); | |
| 106 | + if (M5StackChan.TouchSensor.wasClicked()) { /* ... */ } | |
| 107 | + float v = M5StackChan.getBatteryVoltage(); | |
| 108 | + M5.Speaker.tone(1000, 100); // audio, écran, IMU... via M5Unified | |
| 109 | +} | |
| 110 | +``` | |
| 111 | + | |
| 112 | +### Flash / restauration | |
| 113 | + | |
| 114 | +- Mode download : maintenir RST ~3 s jusqu'à la LED verte, puis relâcher (⚠ formulation incohérente dans la doc). | |
| 115 | +- Restaurer le firmware usine : **M5Burner**, filtre « Only Official ». | |
| 116 | +- Flasher Stack-chan communautaire ou un firmware maison **écrase** le firmware usine. | |
| 117 | + | |
| 118 | +## 5. Contenu des kits | |
| 119 | + | |
| 120 | +K151 : robot (CoreS3 pré-monté), câble USB-C, rallonge 1.25-4P 100 mm, clés Allen 1.5 mm (M2) et 2.5 mm (M3), stickers expressions, manuel. | |
| 121 | +K151-R : idem + **télécommande** (StickC-Plus + Hat Mini JoyC, ESP-NOW ; ID cible 0 = broadcast). | |
| 122 | + | |
| 123 | +## 6. Ressources | |
| 124 | + | |
| 125 | +- Doc produit : https://docs.m5stack.com/en/StackChan | |
| 126 | +- Doc Arduino par périphérique : `https://docs.m5stack.com/en/arduino/stackchan/<servo|rgb|touchsensor|speaker|display|mic|camera|imu|nfc|ir_nec|battery|...>` | |
| 127 | +- MicroPython : https://uiflow-micropython.readthedocs.io/en/latest/controllers/stackchan.html | |
| 128 | +- Schémas : [CoreS3](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/490/Sch_M5_CoreS3_v1.0.pdf) · [Adapter](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCH_Adapter.pdf) · [Power](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCH_Power.pdf) · [Ring](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCH_Ring.pdf) · [Touch](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCH_Touch.pdf) | |
| 129 | +- Datasheet servo : https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCS0009.pdf | |
| 130 | +- Mécanique (STL) : https://github.com/m5stack/M5_Hardware/tree/master/Products/K151_StackChan/Structures | |
| 131 | + | |
| 132 | +## 7. Validé sur notre unité (2026-11-27) | |
| 133 | + | |
| 134 | +Avec PlatformIO + pioarduino 55.03.313 (core Arduino 3.3.13), M5StackChan 1.1.1, M5Unified/M5GFX 0.3.0 : | |
| 135 | + | |
| 136 | +- Écran, LED RGB, tactile tête, haut-parleur, INA226 (≈3.65 V lus) : OK. | |
| 137 | +- Bus servo SCS (UART1 1 Mbaud) : lecture position, calibration du zéro via `setCurrentPostionAsHome()`, mouvements X ±45° et Y jusqu'à 45° : OK. | |
| 138 | +- Port USB : `/dev/cu.usbmodem101` (USB-Serial-JTAG natif, VID:PID 303A:1001), flash sans mode download manuel. | |
| 139 | +- ⚠ L'ouverture du port série depuis macOS **resette la puce** même avec DTR/RTS bas : attendre la ligne `[boot]` avant d'envoyer des commandes (géré par `tools/serial_cmd.py`). | |
| 140 | + | |
| 141 | +## 8. Points ouverts | |
| 142 | + | |
| 143 | +- Circuit de charge batterie du corps (IC, courant, quel port USB-C) non documenté — voir schéma Power. | |
| 144 | +- Le corps a-t-il un firmware propre en dehors du PY32L020 ? (l'IO expander en est un, MCU PY32). | |
| 145 | +- Broches d'interruption NFC / tactile, fréquence porteuse IR. | |
| 146 | +- Licence exacte du firmware usine (`firmware/LICENSE` non lu). | |
| new file mode 100644 | |||
| @@ -0,0 +1,146 @@ | |||
| 1 | +# M5Stack StackChan — fiche technique | ||
| 2 | + | ||
| 3 | +Collecté le 2026-11-27. Sources en bas de page. Les points marqués **⚠** sont ambigus ou contradictoires entre les sources. | ||
| 4 | + | ||
| 5 | +## 1. Identification | ||
| 6 | + | ||
| 7 | +| | | | ||
| 8 | +|---|---| | ||
| 9 | +| Produit | M5Stack **StackChan** « Kawaii co-created open-source AI desktop robot » | | ||
| 10 | +| SKU | **K151** (robot seul) · **K151-R** (robot + télécommande) | | ||
| 11 | +| Contrôleur | **M5Stack CoreS3** (amovible, fixé sur le corps) | | ||
| 12 | +| Dimensions | 54.0 × 70.5 × 61.5 mm | | ||
| 13 | +| Poids | 187.2 g (robot) · 37.6 g (télécommande) | | ||
| 14 | + | ||
| 15 | +Il existe deux mondes distincts : | ||
| 16 | +- **Produit officiel M5Stack** (K151, 2026) : corps motorisé avec électronique dédiée + CoreS3, firmware usine ESP-IDF. | ||
| 17 | +- **Projet communautaire Stack-chan** (Shinya Ishikawa / `stack-chan` org, Apache 2.0) : l'origine du concept, firmware Moddable JS/TS, qui supporte désormais aussi le K151 (« M5StackChan CoreS3 »). | ||
| 18 | + | ||
| 19 | +## 2. Contrôleur CoreS3 | ||
| 20 | + | ||
| 21 | +| Élément | Composant | | ||
| 22 | +|---|---| | ||
| 23 | +| SoC | ESP32-S3, Xtensa LX7 dual-core 240 MHz | | ||
| 24 | +| Mémoire | 16 MB Flash, 8 MB PSRAM (Quad) | | ||
| 25 | +| Radio | Wi-Fi 2.4 GHz 802.11 b/g/n, Bluetooth 5 LE (ESP-NOW utilisé pour la télécommande) | | ||
| 26 | +| Écran | IPS 2.0", 320×240, ILI9342C → **ILI9342E depuis 2026-08-07** (⚠ M5GFX ≥ 0.2.27 requis) | | ||
| 27 | +| Tactile écran | Capacitif multi-touch, FT6336U | | ||
| 28 | +| Caméra | GC0308, 0.3 MP (640×480) | | ||
| 29 | +| Audio entrée | 2 micros, codec ES7210 | | ||
| 30 | +| Audio sortie | HP 1 W, ampli I2S AW88298 16 bits | | ||
| 31 | +| Capteurs | Proximité/lumière LTR-553ALS-WA · IMU 9 axes BMI270 + BMM150 | | ||
| 32 | +| Alim / RTC | PMIC AXP2101 · RTC BM8563 | | ||
| 33 | +| Divers | microSD, USB-C (CDC + OTG full-speed), boutons power/reset | | ||
| 34 | + | ||
| 35 | +Pinmap complet du CoreS3 : https://docs.m5stack.com/en/core/CoreS3#pinmap | ||
| 36 | + | ||
| 37 | +## 3. Corps du robot (base) | ||
| 38 | + | ||
| 39 | +| Élément | Composant | Notes | | ||
| 40 | +|---|---|---| | ||
| 41 | +| Servo pan (X / yaw) | Feetech **SCS0009** (série TTL, avec retour position) | ID **1**, rotation 360° | | ||
| 42 | +| Servo tilt (Y / pitch) | Feetech **SCS0009** | ID **2**, course 90°, **rester entre 5° et 85°** (risque de calage / casse) | | ||
| 43 | +| LED | 12 × WS2812C | idx 0-5 gauche, 6-11 droite ; pilotées **via l'IO expander** | | ||
| 44 | +| Tactile tête | 3 zones, Si12T (compatible TSM12) | clic, swipe avant/arrière | | ||
| 45 | +| NFC | ST25R3916 | lecture + émulation | | ||
| 46 | +| IR | Récepteur IRM56384 + émetteur | protocole NEC dans les exemples | | ||
| 47 | +| Batterie | 550 mAh (⚠ 700 mAh annoncé par un revendeur) | mesure via INA226 (shunt 10 mΩ) | | ||
| 48 | +| IO expander | PY32L020 | IO1 = VM_EN (alim servos), IO14 = data LED RGB | | ||
| 49 | +| Extension | 3 × Grove, trous compatibles LEGO | | | ||
| 50 | + | ||
| 51 | +### Brochage (ESP32-S3) | ||
| 52 | + | ||
| 53 | +| GPIO | Fonction | | ||
| 54 | +|---|---| | ||
| 55 | +| G6 | Servo bus TX (UART1) | | ||
| 56 | +| G7 | Servo bus RX (UART1) | | ||
| 57 | +| G5 | IR émission | | ||
| 58 | +| G10 | IR réception | | ||
| 59 | +| G11 | I2C SCL (corps) | | ||
| 60 | +| G12 | I2C SDA (corps) | | ||
| 61 | +| G2 / G1 | Port A (Grove) | | ||
| 62 | +| G9 / G8 | Port B (Grove) | | ||
| 63 | +| G17 / G18 | Port C (Grove) | | ||
| 64 | + | ||
| 65 | +### Bus I2C du corps | ||
| 66 | + | ||
| 67 | +| Adresse | Composant | | ||
| 68 | +|---|---| | ||
| 69 | +| 0x41 | INA226 (batterie : tension / courant / puissance) | | ||
| 70 | +| 0x50 | ST25R3916 (NFC) | | ||
| 71 | +| 0x68 | Si12T (tactile tête) | | ||
| 72 | +| 0x6F (0x71 si ADD_SEL haut) | PY32L020 (IO expander) | | ||
| 73 | + | ||
| 74 | +### Servos — détails confirmés dans le code BSP | ||
| 75 | + | ||
| 76 | +- Bus série half-duplex Feetech **SCS**, **UART1 à 1 000 000 baud**, TX=6 / RX=7 (`_scs_bus.begin(UART_NUM_1, 1000000, 6, 7)`). | ||
| 77 | +- L'alimentation servos doit être activée via l'IO expander (IO VM_EN) avant usage. | ||
| 78 | +- Unités logicielles : **1/10 de degré**. | ||
| 79 | + - Yaw (ID 1) : limites −1280…+1280, zéro brut par défaut 460, mode PWM/rotation continue possible (`rotate(-1000…1000)`). | ||
| 80 | + - Pitch (ID 2) : limites 0…900, zéro brut par défaut 620. | ||
| 81 | + - Position brute servo : 0…1000. | ||
| 82 | +- Calibration du zéro stockée en NVS : namespace `servo`, clés `zero_pos_1` / `zero_pos_2`. À refaire après flash d'un nouveau firmware. | ||
| 83 | +- Sécurité : ne pas forcer les axes à la main quand les moteurs peuvent être alimentés. | ||
| 84 | + | ||
| 85 | +## 4. Firmwares et environnements | ||
| 86 | + | ||
| 87 | +| Option | Langage / framework | Statut | | ||
| 88 | +|---|---|---| | ||
| 89 | +| **Firmware usine M5Stack** — [m5stack/StackChan](https://github.com/m5stack/StackChan) `firmware/` | C/C++ **ESP-IDF v6.1** | Agent IA XiaoZhi (wake word « Hi, StackChan »), avatar, caméra, danse, App Center, OTA, ESP-NOW. App mobile « StackChan World ». Le dépôt contient aussi `app/`, `remote/`, `server/`. | | ||
| 90 | +| **Arduino / PlatformIO** — lib [M5StackChan](https://github.com/m5stack/StackChan-BSP) v1.1.1 (MIT) | C++ | Carte « M5CoreS3 », board pkg ≥ 3.2.2 (≥ 3.3.7 pour tactile), M5Unified ≥ 0.2.11, M5GFX ≥ 0.2.18 (≥ 0.2.27 pour ILI9342E). Dépendances : IRremoteESP8266, M5Unit-NFC. Exemples : Servo, RGB, TouchSensor, NFC, IR, INA226. | | ||
| 91 | +| **UiFlow2 / MicroPython** | Python | `from hardware.stackchan import StackChan` ; API servo, RGB, touch, batterie, NFC, caméra + détection de visage. | | ||
| 92 | +| **Stack-chan communautaire** — [stack-chan/stack-chan](https://github.com/stack-chan/stack-chan) (Apache 2.0) | JS/TS sur **Moddable SDK** | Architecture host + « MODs » rechargeables sans reflasher le host. Cible de référence : « M5StackChan CoreS3 ». TTS (VOICEVOX, ElevenLabs, OpenAI…), conversation WebRTC, éditeur de visage, simulateur Wasm, Blockly. Installeur web. | | ||
| 93 | +| ESPHome / Home Assistant | YAML | Fonctions de base seulement (voix, écran, touch, servos). ⚠ page doc HA en 404 au moment de la collecte. | | ||
| 94 | + | ||
| 95 | +### API Arduino (résumé) | ||
| 96 | + | ||
| 97 | +```cpp | ||
| 98 | +#include <M5Unified.h> | ||
| 99 | +#include <M5StackChan.h> | ||
| 100 | + | ||
| 101 | +void setup() { M5StackChan.begin(); } // M5.begin + touch + IO expander + servos + INA226 | ||
| 102 | +void loop() { | ||
| 103 | + M5StackChan.update(); // obligatoire à chaque boucle | ||
| 104 | + M5StackChan.Motion.move(x, y); // ou moveX(angle, speed), moveY(...), rotateX(vel), goHome() | ||
| 105 | + M5StackChan.setRgbColor(i, r, g, b); M5StackChan.refreshRgb(); | ||
| 106 | + if (M5StackChan.TouchSensor.wasClicked()) { /* ... */ } | ||
| 107 | + float v = M5StackChan.getBatteryVoltage(); | ||
| 108 | + M5.Speaker.tone(1000, 100); // audio, écran, IMU... via M5Unified | ||
| 109 | +} | ||
| 110 | +``` | ||
| 111 | + | ||
| 112 | +### Flash / restauration | ||
| 113 | + | ||
| 114 | +- Mode download : maintenir RST ~3 s jusqu'à la LED verte, puis relâcher (⚠ formulation incohérente dans la doc). | ||
| 115 | +- Restaurer le firmware usine : **M5Burner**, filtre « Only Official ». | ||
| 116 | +- Flasher Stack-chan communautaire ou un firmware maison **écrase** le firmware usine. | ||
| 117 | + | ||
| 118 | +## 5. Contenu des kits | ||
| 119 | + | ||
| 120 | +K151 : robot (CoreS3 pré-monté), câble USB-C, rallonge 1.25-4P 100 mm, clés Allen 1.5 mm (M2) et 2.5 mm (M3), stickers expressions, manuel. | ||
| 121 | +K151-R : idem + **télécommande** (StickC-Plus + Hat Mini JoyC, ESP-NOW ; ID cible 0 = broadcast). | ||
| 122 | + | ||
| 123 | +## 6. Ressources | ||
| 124 | + | ||
| 125 | +- Doc produit : https://docs.m5stack.com/en/StackChan | ||
| 126 | +- Doc Arduino par périphérique : `https://docs.m5stack.com/en/arduino/stackchan/<servo|rgb|touchsensor|speaker|display|mic|camera|imu|nfc|ir_nec|battery|...>` | ||
| 127 | +- MicroPython : https://uiflow-micropython.readthedocs.io/en/latest/controllers/stackchan.html | ||
| 128 | +- Schémas : [CoreS3](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/490/Sch_M5_CoreS3_v1.0.pdf) · [Adapter](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCH_Adapter.pdf) · [Power](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCH_Power.pdf) · [Ring](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCH_Ring.pdf) · [Touch](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCH_Touch.pdf) | ||
| 129 | +- Datasheet servo : https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1205/SCS0009.pdf | ||
| 130 | +- Mécanique (STL) : https://github.com/m5stack/M5_Hardware/tree/master/Products/K151_StackChan/Structures | ||
| 131 | + | ||
| 132 | +## 7. Validé sur notre unité (2026-11-27) | ||
| 133 | + | ||
| 134 | +Avec PlatformIO + pioarduino 55.03.313 (core Arduino 3.3.13), M5StackChan 1.1.1, M5Unified/M5GFX 0.3.0 : | ||
| 135 | + | ||
| 136 | +- Écran, LED RGB, tactile tête, haut-parleur, INA226 (≈3.65 V lus) : OK. | ||
| 137 | +- Bus servo SCS (UART1 1 Mbaud) : lecture position, calibration du zéro via `setCurrentPostionAsHome()`, mouvements X ±45° et Y jusqu'à 45° : OK. | ||
| 138 | +- Port USB : `/dev/cu.usbmodem101` (USB-Serial-JTAG natif, VID:PID 303A:1001), flash sans mode download manuel. | ||
| 139 | +- ⚠ L'ouverture du port série depuis macOS **resette la puce** même avec DTR/RTS bas : attendre la ligne `[boot]` avant d'envoyer des commandes (géré par `tools/serial_cmd.py`). | ||
| 140 | + | ||
| 141 | +## 8. Points ouverts | ||
| 142 | + | ||
| 143 | +- Circuit de charge batterie du corps (IC, courant, quel port USB-C) non documenté — voir schéma Power. | ||
| 144 | +- Le corps a-t-il un firmware propre en dehors du PY32L020 ? (l'IO expander en est un, MCU PY32). | ||
| 145 | +- Broches d'interruption NFC / tactile, fréquence porteuse IR. | ||
| 146 | +- Licence exacte du firmware usine (`firmware/LICENSE` non lu). | ||
added
firmware/platformio.ini +17 -0 | new file mode 100644 | ||
| @@ -0,0 +1,17 @@ | ||
| 1 | +; StackChan (M5Stack K151) — CoreS3 + corps motorisé | |
| 2 | +; Plateforme pioarduino : core Arduino 3.3.13 (ESP-IDF 5.5.6), requis par la lib M5StackChan (>= 3.2.2) | |
| 3 | + | |
| 4 | +[env:stackchan] | |
| 5 | +platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.313/platform-espressif32.zip | |
| 6 | +board = m5stack-cores3 | |
| 7 | +framework = arduino | |
| 8 | + | |
| 9 | +monitor_speed = 115200 | |
| 10 | +monitor_filters = esp32_exception_decoder | |
| 11 | + | |
| 12 | +build_flags = | |
| 13 | + -DARDUINO_USB_CDC_ON_BOOT=1 | |
| 14 | + | |
| 15 | +lib_deps = | |
| 16 | + m5stack/M5StackChan @ ^1.1.1 | |
| 17 | + m5stack/M5GFX @ >=0.2.27 | |
| new file mode 100644 | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | +; StackChan (M5Stack K151) — CoreS3 + corps motorisé | ||
| 2 | +; Plateforme pioarduino : core Arduino 3.3.13 (ESP-IDF 5.5.6), requis par la lib M5StackChan (>= 3.2.2) | ||
| 3 | + | ||
| 4 | +[env:stackchan] | ||
| 5 | +platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.313/platform-espressif32.zip | ||
| 6 | +board = m5stack-cores3 | ||
| 7 | +framework = arduino | ||
| 8 | + | ||
| 9 | +monitor_speed = 115200 | ||
| 10 | +monitor_filters = esp32_exception_decoder | ||
| 11 | + | ||
| 12 | +build_flags = | ||
| 13 | + -DARDUINO_USB_CDC_ON_BOOT=1 | ||
| 14 | + | ||
| 15 | +lib_deps = | ||
| 16 | + m5stack/M5StackChan @ ^1.1.1 | ||
| 17 | + m5stack/M5GFX @ >=0.2.27 | ||
added
firmware/src/main.cpp +268 -0 | new file mode 100644 | ||
| @@ -0,0 +1,268 @@ | ||
| 1 | +// Firmware de test des servos StackChan. | |
| 2 | +// | |
| 3 | +// Écran tactile : | |
| 4 | +// - moitié haute : « Calibrer » -> coupe le couple, place la tête à la main, re-touche pour enregistrer le zéro | |
| 5 | +// - moitié basse : « Test » -> séquence de mouvements dans les limites sûres | |
| 6 | +// Tactile tête : arrêt immédiat (stop + retour au repos). | |
| 7 | +// | |
| 8 | +// Console série (115200, une commande par ligne) : | |
| 9 | +// pos -> angles courants (1/10 de degré) | |
| 10 | +// move <x> <y> [vit] -> déplacement borné (x: ±900, y: 50..850, vitesse 0..1000) | |
| 11 | +// rest -> position de repos (0, 50) | |
| 12 | +// torque on|off | |
| 13 | +// sethome -> la position actuelle devient le zéro (NVS) | |
| 14 | +// test -> lance la séquence de test | |
| 15 | +// stop | |
| 16 | +#include <M5Unified.h> | |
| 17 | +#include <M5StackChan.h> | |
| 18 | + | |
| 19 | +namespace { | |
| 20 | + | |
| 21 | +// Limites logicielles volontairement plus strictes que celles du BSP. | |
| 22 | +// Tilt (Y) : la doc M5Stack recommande 5°..85° pour éviter le calage du servo. | |
| 23 | +constexpr int kXMin = -900, kXMax = 900; | |
| 24 | +constexpr int kYMin = 50, kYMax = 850; | |
| 25 | +constexpr int kRestY = 50; | |
| 26 | +constexpr int kDefaultSpeed = 300; | |
| 27 | + | |
| 28 | +enum class Mode { Idle, Calibrating, Testing }; | |
| 29 | +Mode mode = Mode::Idle; | |
| 30 | + | |
| 31 | +bool abort_requested = false; | |
| 32 | +String rx_line; | |
| 33 | + | |
| 34 | +auto& motion() { return M5StackChan.Motion; } | |
| 35 | + | |
| 36 | +void log(const char* fmt, ...) | |
| 37 | +{ | |
| 38 | + char buf[160]; | |
| 39 | + va_list ap; | |
| 40 | + va_start(ap, fmt); | |
| 41 | + vsnprintf(buf, sizeof(buf), fmt, ap); | |
| 42 | + va_end(ap); | |
| 43 | + Serial.println(buf); | |
| 44 | +} | |
| 45 | + | |
| 46 | +void drawUi(const char* status) | |
| 47 | +{ | |
| 48 | + auto& d = M5.Display; | |
| 49 | + const int w = d.width(), h = d.height(), half = h / 2; | |
| 50 | + d.startWrite(); | |
| 51 | + d.fillScreen(TFT_BLACK); | |
| 52 | + d.setTextDatum(middle_center); | |
| 53 | + d.setTextSize(2); | |
| 54 | + | |
| 55 | + uint16_t top = (mode == Mode::Calibrating) ? TFT_ORANGE : 0x39C7; | |
| 56 | + d.fillRoundRect(8, 8, w - 16, half - 30, 8, top); | |
| 57 | + d.setTextColor(TFT_WHITE, top); | |
| 58 | + d.drawString(mode == Mode::Calibrating ? "Toucher = enregistrer" : "Calibrer", w / 2, 8 + (half - 30) / 2); | |
| 59 | + | |
| 60 | + uint16_t bot = (mode == Mode::Testing) ? TFT_DARKGREEN : 0x03EF; | |
| 61 | + d.fillRoundRect(8, half - 14, w - 16, half - 30, 8, bot); | |
| 62 | + d.setTextColor(TFT_WHITE, bot); | |
| 63 | + d.drawString(mode == Mode::Testing ? "Test en cours..." : "Test", w / 2, half - 14 + (half - 30) / 2); | |
| 64 | + | |
| 65 | + d.setTextColor(TFT_YELLOW, TFT_BLACK); | |
| 66 | + d.drawString(status, w / 2, h - 22); | |
| 67 | + d.endWrite(); | |
| 68 | +} | |
| 69 | + | |
| 70 | +void setLeds(uint8_t r, uint8_t g, uint8_t b) | |
| 71 | +{ | |
| 72 | + for (int i = 0; i < 12; i++) M5StackChan.setRgbColor(i, r, g, b); | |
| 73 | + M5StackChan.refreshRgb(); | |
| 74 | +} | |
| 75 | + | |
| 76 | +void safeMove(int x, int y, int speed = kDefaultSpeed) | |
| 77 | +{ | |
| 78 | + int cx = constrain(x, kXMin, kXMax); | |
| 79 | + int cy = constrain(y, kYMin, kYMax); | |
| 80 | + speed = constrain(speed, 0, 1000); | |
| 81 | + if (cx != x || cy != y) log("[warn] borne: (%d,%d) -> (%d,%d)", x, y, cx, cy); | |
| 82 | + motion().move(cx, cy, speed); | |
| 83 | + log("[move] x=%d y=%d speed=%d", cx, cy, speed); | |
| 84 | +} | |
| 85 | + | |
| 86 | +void reportPos() | |
| 87 | +{ | |
| 88 | + log("[pos] x=%d y=%d moving=%d", motion().getCurrentXAngle(), motion().getCurrentYAngle(), | |
| 89 | + motion().isMoving() ? 1 : 0); | |
| 90 | +} | |
| 91 | + | |
| 92 | +// Attente interruptible : traite le tactile tête et la commande "stop". | |
| 93 | +void pollInputs(); | |
| 94 | +bool waitMs(uint32_t ms) | |
| 95 | +{ | |
| 96 | + uint32_t start = millis(); | |
| 97 | + while (millis() - start < ms) { | |
| 98 | + pollInputs(); | |
| 99 | + if (abort_requested) return false; | |
| 100 | + delay(10); | |
| 101 | + } | |
| 102 | + return true; | |
| 103 | +} | |
| 104 | + | |
| 105 | +void startCalibration() | |
| 106 | +{ | |
| 107 | + mode = Mode::Calibrating; | |
| 108 | + motion().setTorqueEnabled(false); | |
| 109 | + setLeds(30, 15, 0); | |
| 110 | + log("[calib] couple coupé : place la tête (écran aligné avec la base, perpendiculaire), puis touche l'écran"); | |
| 111 | + drawUi("Placer la tete a la main"); | |
| 112 | +} | |
| 113 | + | |
| 114 | +void finishCalibration() | |
| 115 | +{ | |
| 116 | + motion().setCurrentPostionAsHome(); | |
| 117 | + motion().setTorqueEnabled(true); | |
| 118 | + mode = Mode::Idle; | |
| 119 | + setLeds(0, 30, 0); | |
| 120 | + log("[calib] zéro enregistré"); | |
| 121 | + reportPos(); | |
| 122 | + drawUi("Zero enregistre"); | |
| 123 | +} | |
| 124 | + | |
| 125 | +void runTest() | |
| 126 | +{ | |
| 127 | + struct Step { int x, y, speed; uint32_t hold; const char* label; }; | |
| 128 | + static const Step steps[] = { | |
| 129 | + {0, kRestY, 300, 1500, "repos"}, | |
| 130 | + {450, kRestY, 200, 2000, "gauche lent"}, | |
| 131 | + {-450, kRestY, 200, 2500, "droite lent"}, | |
| 132 | + {0, kRestY, 500, 1500, "centre"}, | |
| 133 | + {0, 450, 200, 2000, "haut lent"}, | |
| 134 | + {0, kRestY, 200, 2000, "bas lent"}, | |
| 135 | + {300, 400, 400, 1500, "haut-gauche"}, | |
| 136 | + {-300, 400, 400, 1500, "haut-droite"}, | |
| 137 | + {0, kRestY, 300, 1500, "repos"}, | |
| 138 | + }; | |
| 139 | + | |
| 140 | + mode = Mode::Testing; | |
| 141 | + abort_requested = false; | |
| 142 | + setLeds(0, 0, 30); | |
| 143 | + drawUi("Tete = arret"); | |
| 144 | + log("[test] début"); | |
| 145 | + motion().setTorqueEnabled(true); | |
| 146 | + | |
| 147 | + for (const auto& s : steps) { | |
| 148 | + log("[test] %s", s.label); | |
| 149 | + safeMove(s.x, s.y, s.speed); | |
| 150 | + if (!waitMs(s.hold)) break; | |
| 151 | + reportPos(); | |
| 152 | + } | |
| 153 | + | |
| 154 | + const bool aborted = abort_requested; | |
| 155 | + if (aborted) { | |
| 156 | + motion().stop(); | |
| 157 | + log("[test] interrompu"); | |
| 158 | + safeMove(0, kRestY, 200); | |
| 159 | + } else { | |
| 160 | + log("[test] terminé"); | |
| 161 | + } | |
| 162 | + abort_requested = false; | |
| 163 | + mode = Mode::Idle; | |
| 164 | + setLeds(0, 30, 0); | |
| 165 | + drawUi(aborted ? "Interrompu" : "Test termine"); | |
| 166 | +} | |
| 167 | + | |
| 168 | +void handleCommand(String line) | |
| 169 | +{ | |
| 170 | + line.trim(); | |
| 171 | + if (line.isEmpty()) return; | |
| 172 | + log("> %s", line.c_str()); | |
| 173 | + | |
| 174 | + if (line == "pos") { | |
| 175 | + reportPos(); | |
| 176 | + } else if (line == "stop") { | |
| 177 | + abort_requested = true; | |
| 178 | + motion().stop(); | |
| 179 | + } else if (mode == Mode::Testing) { | |
| 180 | + log("[err] test en cours (envoyer stop)"); | |
| 181 | + } else if (line == "rest") { | |
| 182 | + safeMove(0, kRestY); | |
| 183 | + } else if (line == "torque on") { | |
| 184 | + motion().setTorqueEnabled(true); | |
| 185 | + log("[torque] on"); | |
| 186 | + } else if (line == "torque off") { | |
| 187 | + motion().setTorqueEnabled(false); | |
| 188 | + log("[torque] off"); | |
| 189 | + } else if (line == "sethome") { | |
| 190 | + motion().setCurrentPostionAsHome(); | |
| 191 | + log("[calib] zéro enregistré"); | |
| 192 | + reportPos(); | |
| 193 | + } else if (line == "test") { | |
| 194 | + runTest(); | |
| 195 | + } else if (line.startsWith("move ")) { | |
| 196 | + int x = 0, y = 0, sp = kDefaultSpeed; | |
| 197 | + int n = sscanf(line.c_str() + 5, "%d %d %d", &x, &y, &sp); | |
| 198 | + if (n >= 2) safeMove(x, y, sp); | |
| 199 | + else log("[err] usage: move <x> <y> [vitesse]"); | |
| 200 | + } else { | |
| 201 | + log("[err] commande inconnue"); | |
| 202 | + } | |
| 203 | +} | |
| 204 | + | |
| 205 | +void pollInputs() | |
| 206 | +{ | |
| 207 | + M5StackChan.update(); | |
| 208 | + | |
| 209 | + if (M5StackChan.TouchSensor.wasClicked() && mode == Mode::Testing) { | |
| 210 | + log("[touch] arrêt demandé"); | |
| 211 | + abort_requested = true; | |
| 212 | + } | |
| 213 | + | |
| 214 | + while (Serial.available()) { | |
| 215 | + char c = Serial.read(); | |
| 216 | + if (c == '\n' || c == '\r') { | |
| 217 | + if (!rx_line.isEmpty()) { | |
| 218 | + String cmd = rx_line; | |
| 219 | + rx_line = ""; | |
| 220 | + if (mode == Mode::Testing && cmd != "stop" && cmd != "pos") { | |
| 221 | + log("[err] test en cours (envoyer stop)"); | |
| 222 | + } else { | |
| 223 | + handleCommand(cmd); | |
| 224 | + } | |
| 225 | + } | |
| 226 | + } else if (rx_line.length() < 64) { | |
| 227 | + rx_line += c; | |
| 228 | + } | |
| 229 | + } | |
| 230 | +} | |
| 231 | + | |
| 232 | +} // namespace | |
| 233 | + | |
| 234 | +void setup() | |
| 235 | +{ | |
| 236 | + Serial.begin(115200); | |
| 237 | + M5StackChan.begin(); | |
| 238 | + M5.Display.setTextScroll(false); | |
| 239 | + setLeds(0, 30, 0); | |
| 240 | + drawUi("Pret"); | |
| 241 | + log("[boot] test servos pret"); | |
| 242 | + reportPos(); | |
| 243 | +} | |
| 244 | + | |
| 245 | +void loop() | |
| 246 | +{ | |
| 247 | + pollInputs(); | |
| 248 | + | |
| 249 | + // Action au relâchement de l'écran, selon la zone touchée. | |
| 250 | + static bool was_touching = false; | |
| 251 | + static int16_t press_y = 0; | |
| 252 | + int16_t tx, ty; | |
| 253 | + bool touching = M5.Display.getTouch(&tx, &ty); | |
| 254 | + if (touching) press_y = ty; | |
| 255 | + if (was_touching && !touching) { | |
| 256 | + bool top = press_y < M5.Display.height() / 2; | |
| 257 | + if (mode == Mode::Calibrating) { | |
| 258 | + finishCalibration(); | |
| 259 | + } else if (top) { | |
| 260 | + startCalibration(); | |
| 261 | + } else { | |
| 262 | + runTest(); | |
| 263 | + } | |
| 264 | + } | |
| 265 | + was_touching = touching; | |
| 266 | + | |
| 267 | + delay(10); | |
| 268 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,268 @@ | |||
| 1 | +// Firmware de test des servos StackChan. | ||
| 2 | +// | ||
| 3 | +// Écran tactile : | ||
| 4 | +// - moitié haute : « Calibrer » -> coupe le couple, place la tête à la main, re-touche pour enregistrer le zéro | ||
| 5 | +// - moitié basse : « Test » -> séquence de mouvements dans les limites sûres | ||
| 6 | +// Tactile tête : arrêt immédiat (stop + retour au repos). | ||
| 7 | +// | ||
| 8 | +// Console série (115200, une commande par ligne) : | ||
| 9 | +// pos -> angles courants (1/10 de degré) | ||
| 10 | +// move <x> <y> [vit] -> déplacement borné (x: ±900, y: 50..850, vitesse 0..1000) | ||
| 11 | +// rest -> position de repos (0, 50) | ||
| 12 | +// torque on|off | ||
| 13 | +// sethome -> la position actuelle devient le zéro (NVS) | ||
| 14 | +// test -> lance la séquence de test | ||
| 15 | +// stop | ||
| 16 | +#include <M5Unified.h> | ||
| 17 | +#include <M5StackChan.h> | ||
| 18 | + | ||
| 19 | +namespace { | ||
| 20 | + | ||
| 21 | +// Limites logicielles volontairement plus strictes que celles du BSP. | ||
| 22 | +// Tilt (Y) : la doc M5Stack recommande 5°..85° pour éviter le calage du servo. | ||
| 23 | +constexpr int kXMin = -900, kXMax = 900; | ||
| 24 | +constexpr int kYMin = 50, kYMax = 850; | ||
| 25 | +constexpr int kRestY = 50; | ||
| 26 | +constexpr int kDefaultSpeed = 300; | ||
| 27 | + | ||
| 28 | +enum class Mode { Idle, Calibrating, Testing }; | ||
| 29 | +Mode mode = Mode::Idle; | ||
| 30 | + | ||
| 31 | +bool abort_requested = false; | ||
| 32 | +String rx_line; | ||
| 33 | + | ||
| 34 | +auto& motion() { return M5StackChan.Motion; } | ||
| 35 | + | ||
| 36 | +void log(const char* fmt, ...) | ||
| 37 | +{ | ||
| 38 | + char buf[160]; | ||
| 39 | + va_list ap; | ||
| 40 | + va_start(ap, fmt); | ||
| 41 | + vsnprintf(buf, sizeof(buf), fmt, ap); | ||
| 42 | + va_end(ap); | ||
| 43 | + Serial.println(buf); | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +void drawUi(const char* status) | ||
| 47 | +{ | ||
| 48 | + auto& d = M5.Display; | ||
| 49 | + const int w = d.width(), h = d.height(), half = h / 2; | ||
| 50 | + d.startWrite(); | ||
| 51 | + d.fillScreen(TFT_BLACK); | ||
| 52 | + d.setTextDatum(middle_center); | ||
| 53 | + d.setTextSize(2); | ||
| 54 | + | ||
| 55 | + uint16_t top = (mode == Mode::Calibrating) ? TFT_ORANGE : 0x39C7; | ||
| 56 | + d.fillRoundRect(8, 8, w - 16, half - 30, 8, top); | ||
| 57 | + d.setTextColor(TFT_WHITE, top); | ||
| 58 | + d.drawString(mode == Mode::Calibrating ? "Toucher = enregistrer" : "Calibrer", w / 2, 8 + (half - 30) / 2); | ||
| 59 | + | ||
| 60 | + uint16_t bot = (mode == Mode::Testing) ? TFT_DARKGREEN : 0x03EF; | ||
| 61 | + d.fillRoundRect(8, half - 14, w - 16, half - 30, 8, bot); | ||
| 62 | + d.setTextColor(TFT_WHITE, bot); | ||
| 63 | + d.drawString(mode == Mode::Testing ? "Test en cours..." : "Test", w / 2, half - 14 + (half - 30) / 2); | ||
| 64 | + | ||
| 65 | + d.setTextColor(TFT_YELLOW, TFT_BLACK); | ||
| 66 | + d.drawString(status, w / 2, h - 22); | ||
| 67 | + d.endWrite(); | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +void setLeds(uint8_t r, uint8_t g, uint8_t b) | ||
| 71 | +{ | ||
| 72 | + for (int i = 0; i < 12; i++) M5StackChan.setRgbColor(i, r, g, b); | ||
| 73 | + M5StackChan.refreshRgb(); | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +void safeMove(int x, int y, int speed = kDefaultSpeed) | ||
| 77 | +{ | ||
| 78 | + int cx = constrain(x, kXMin, kXMax); | ||
| 79 | + int cy = constrain(y, kYMin, kYMax); | ||
| 80 | + speed = constrain(speed, 0, 1000); | ||
| 81 | + if (cx != x || cy != y) log("[warn] borne: (%d,%d) -> (%d,%d)", x, y, cx, cy); | ||
| 82 | + motion().move(cx, cy, speed); | ||
| 83 | + log("[move] x=%d y=%d speed=%d", cx, cy, speed); | ||
| 84 | +} | ||
| 85 | + | ||
| 86 | +void reportPos() | ||
| 87 | +{ | ||
| 88 | + log("[pos] x=%d y=%d moving=%d", motion().getCurrentXAngle(), motion().getCurrentYAngle(), | ||
| 89 | + motion().isMoving() ? 1 : 0); | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +// Attente interruptible : traite le tactile tête et la commande "stop". | ||
| 93 | +void pollInputs(); | ||
| 94 | +bool waitMs(uint32_t ms) | ||
| 95 | +{ | ||
| 96 | + uint32_t start = millis(); | ||
| 97 | + while (millis() - start < ms) { | ||
| 98 | + pollInputs(); | ||
| 99 | + if (abort_requested) return false; | ||
| 100 | + delay(10); | ||
| 101 | + } | ||
| 102 | + return true; | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +void startCalibration() | ||
| 106 | +{ | ||
| 107 | + mode = Mode::Calibrating; | ||
| 108 | + motion().setTorqueEnabled(false); | ||
| 109 | + setLeds(30, 15, 0); | ||
| 110 | + log("[calib] couple coupé : place la tête (écran aligné avec la base, perpendiculaire), puis touche l'écran"); | ||
| 111 | + drawUi("Placer la tete a la main"); | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +void finishCalibration() | ||
| 115 | +{ | ||
| 116 | + motion().setCurrentPostionAsHome(); | ||
| 117 | + motion().setTorqueEnabled(true); | ||
| 118 | + mode = Mode::Idle; | ||
| 119 | + setLeds(0, 30, 0); | ||
| 120 | + log("[calib] zéro enregistré"); | ||
| 121 | + reportPos(); | ||
| 122 | + drawUi("Zero enregistre"); | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | +void runTest() | ||
| 126 | +{ | ||
| 127 | + struct Step { int x, y, speed; uint32_t hold; const char* label; }; | ||
| 128 | + static const Step steps[] = { | ||
| 129 | + {0, kRestY, 300, 1500, "repos"}, | ||
| 130 | + {450, kRestY, 200, 2000, "gauche lent"}, | ||
| 131 | + {-450, kRestY, 200, 2500, "droite lent"}, | ||
| 132 | + {0, kRestY, 500, 1500, "centre"}, | ||
| 133 | + {0, 450, 200, 2000, "haut lent"}, | ||
| 134 | + {0, kRestY, 200, 2000, "bas lent"}, | ||
| 135 | + {300, 400, 400, 1500, "haut-gauche"}, | ||
| 136 | + {-300, 400, 400, 1500, "haut-droite"}, | ||
| 137 | + {0, kRestY, 300, 1500, "repos"}, | ||
| 138 | + }; | ||
| 139 | + | ||
| 140 | + mode = Mode::Testing; | ||
| 141 | + abort_requested = false; | ||
| 142 | + setLeds(0, 0, 30); | ||
| 143 | + drawUi("Tete = arret"); | ||
| 144 | + log("[test] début"); | ||
| 145 | + motion().setTorqueEnabled(true); | ||
| 146 | + | ||
| 147 | + for (const auto& s : steps) { | ||
| 148 | + log("[test] %s", s.label); | ||
| 149 | + safeMove(s.x, s.y, s.speed); | ||
| 150 | + if (!waitMs(s.hold)) break; | ||
| 151 | + reportPos(); | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + const bool aborted = abort_requested; | ||
| 155 | + if (aborted) { | ||
| 156 | + motion().stop(); | ||
| 157 | + log("[test] interrompu"); | ||
| 158 | + safeMove(0, kRestY, 200); | ||
| 159 | + } else { | ||
| 160 | + log("[test] terminé"); | ||
| 161 | + } | ||
| 162 | + abort_requested = false; | ||
| 163 | + mode = Mode::Idle; | ||
| 164 | + setLeds(0, 30, 0); | ||
| 165 | + drawUi(aborted ? "Interrompu" : "Test termine"); | ||
| 166 | +} | ||
| 167 | + | ||
| 168 | +void handleCommand(String line) | ||
| 169 | +{ | ||
| 170 | + line.trim(); | ||
| 171 | + if (line.isEmpty()) return; | ||
| 172 | + log("> %s", line.c_str()); | ||
| 173 | + | ||
| 174 | + if (line == "pos") { | ||
| 175 | + reportPos(); | ||
| 176 | + } else if (line == "stop") { | ||
| 177 | + abort_requested = true; | ||
| 178 | + motion().stop(); | ||
| 179 | + } else if (mode == Mode::Testing) { | ||
| 180 | + log("[err] test en cours (envoyer stop)"); | ||
| 181 | + } else if (line == "rest") { | ||
| 182 | + safeMove(0, kRestY); | ||
| 183 | + } else if (line == "torque on") { | ||
| 184 | + motion().setTorqueEnabled(true); | ||
| 185 | + log("[torque] on"); | ||
| 186 | + } else if (line == "torque off") { | ||
| 187 | + motion().setTorqueEnabled(false); | ||
| 188 | + log("[torque] off"); | ||
| 189 | + } else if (line == "sethome") { | ||
| 190 | + motion().setCurrentPostionAsHome(); | ||
| 191 | + log("[calib] zéro enregistré"); | ||
| 192 | + reportPos(); | ||
| 193 | + } else if (line == "test") { | ||
| 194 | + runTest(); | ||
| 195 | + } else if (line.startsWith("move ")) { | ||
| 196 | + int x = 0, y = 0, sp = kDefaultSpeed; | ||
| 197 | + int n = sscanf(line.c_str() + 5, "%d %d %d", &x, &y, &sp); | ||
| 198 | + if (n >= 2) safeMove(x, y, sp); | ||
| 199 | + else log("[err] usage: move <x> <y> [vitesse]"); | ||
| 200 | + } else { | ||
| 201 | + log("[err] commande inconnue"); | ||
| 202 | + } | ||
| 203 | +} | ||
| 204 | + | ||
| 205 | +void pollInputs() | ||
| 206 | +{ | ||
| 207 | + M5StackChan.update(); | ||
| 208 | + | ||
| 209 | + if (M5StackChan.TouchSensor.wasClicked() && mode == Mode::Testing) { | ||
| 210 | + log("[touch] arrêt demandé"); | ||
| 211 | + abort_requested = true; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + while (Serial.available()) { | ||
| 215 | + char c = Serial.read(); | ||
| 216 | + if (c == '\n' || c == '\r') { | ||
| 217 | + if (!rx_line.isEmpty()) { | ||
| 218 | + String cmd = rx_line; | ||
| 219 | + rx_line = ""; | ||
| 220 | + if (mode == Mode::Testing && cmd != "stop" && cmd != "pos") { | ||
| 221 | + log("[err] test en cours (envoyer stop)"); | ||
| 222 | + } else { | ||
| 223 | + handleCommand(cmd); | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + } else if (rx_line.length() < 64) { | ||
| 227 | + rx_line += c; | ||
| 228 | + } | ||
| 229 | + } | ||
| 230 | +} | ||
| 231 | + | ||
| 232 | +} // namespace | ||
| 233 | + | ||
| 234 | +void setup() | ||
| 235 | +{ | ||
| 236 | + Serial.begin(115200); | ||
| 237 | + M5StackChan.begin(); | ||
| 238 | + M5.Display.setTextScroll(false); | ||
| 239 | + setLeds(0, 30, 0); | ||
| 240 | + drawUi("Pret"); | ||
| 241 | + log("[boot] test servos pret"); | ||
| 242 | + reportPos(); | ||
| 243 | +} | ||
| 244 | + | ||
| 245 | +void loop() | ||
| 246 | +{ | ||
| 247 | + pollInputs(); | ||
| 248 | + | ||
| 249 | + // Action au relâchement de l'écran, selon la zone touchée. | ||
| 250 | + static bool was_touching = false; | ||
| 251 | + static int16_t press_y = 0; | ||
| 252 | + int16_t tx, ty; | ||
| 253 | + bool touching = M5.Display.getTouch(&tx, &ty); | ||
| 254 | + if (touching) press_y = ty; | ||
| 255 | + if (was_touching && !touching) { | ||
| 256 | + bool top = press_y < M5.Display.height() / 2; | ||
| 257 | + if (mode == Mode::Calibrating) { | ||
| 258 | + finishCalibration(); | ||
| 259 | + } else if (top) { | ||
| 260 | + startCalibration(); | ||
| 261 | + } else { | ||
| 262 | + runTest(); | ||
| 263 | + } | ||
| 264 | + } | ||
| 265 | + was_touching = touching; | ||
| 266 | + | ||
| 267 | + delay(10); | ||
| 268 | +} | ||
added
tools/serial_cmd.py +44 -0 | new file mode 100644 | ||
| @@ -0,0 +1,44 @@ | ||
| 1 | +"""Envoie des commandes ligne par ligne au StackChan et affiche la réponse. | |
| 2 | + | |
| 3 | +Usage : python serial_cmd.py <port> <durée_lecture_s> [commande ...] | |
| 4 | +Sans commande : lecture seule. DTR/RTS restent bas pour ne pas resetter l'ESP32-S3. | |
| 5 | +""" | |
| 6 | +import sys | |
| 7 | +import time | |
| 8 | + | |
| 9 | +import serial | |
| 10 | + | |
| 11 | +port, dur, cmds = sys.argv[1], float(sys.argv[2]), sys.argv[3:] | |
| 12 | + | |
| 13 | +s = serial.Serial() | |
| 14 | +s.port, s.baudrate, s.timeout = port, 115200, 0.2 | |
| 15 | +s.dtr = False | |
| 16 | +s.rts = False | |
| 17 | +s.open() | |
| 18 | + | |
| 19 | +# Sur macOS, l'ouverture du port USB-Serial-JTAG peut quand même resetter la puce : | |
| 20 | +# on attend la ligne "[boot]" (ou 1.5 s de silence) avant d'envoyer quoi que ce soit. | |
| 21 | +deadline, last_rx = time.time() + 6, time.time() | |
| 22 | +while time.time() < deadline: | |
| 23 | + line = s.readline() | |
| 24 | + if line: | |
| 25 | + last_rx = time.time() | |
| 26 | + text = line.decode(errors="replace").rstrip() | |
| 27 | + print(text, flush=True) | |
| 28 | + if text.startswith("[boot]"): | |
| 29 | + time.sleep(0.3) | |
| 30 | + break | |
| 31 | + elif time.time() - last_rx > 1.5: | |
| 32 | + break | |
| 33 | + | |
| 34 | +for c in cmds: | |
| 35 | + s.write((c + "\n").encode()) | |
| 36 | + s.flush() | |
| 37 | + time.sleep(0.1) | |
| 38 | + | |
| 39 | +end = time.time() + dur | |
| 40 | +while time.time() < end: | |
| 41 | + line = s.readline() | |
| 42 | + if line: | |
| 43 | + print(line.decode(errors="replace").rstrip(), flush=True) | |
| 44 | +s.close() | |
| new file mode 100644 | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | +"""Envoie des commandes ligne par ligne au StackChan et affiche la réponse. | ||
| 2 | + | ||
| 3 | +Usage : python serial_cmd.py <port> <durée_lecture_s> [commande ...] | ||
| 4 | +Sans commande : lecture seule. DTR/RTS restent bas pour ne pas resetter l'ESP32-S3. | ||
| 5 | +""" | ||
| 6 | +import sys | ||
| 7 | +import time | ||
| 8 | + | ||
| 9 | +import serial | ||
| 10 | + | ||
| 11 | +port, dur, cmds = sys.argv[1], float(sys.argv[2]), sys.argv[3:] | ||
| 12 | + | ||
| 13 | +s = serial.Serial() | ||
| 14 | +s.port, s.baudrate, s.timeout = port, 115200, 0.2 | ||
| 15 | +s.dtr = False | ||
| 16 | +s.rts = False | ||
| 17 | +s.open() | ||
| 18 | + | ||
| 19 | +# Sur macOS, l'ouverture du port USB-Serial-JTAG peut quand même resetter la puce : | ||
| 20 | +# on attend la ligne "[boot]" (ou 1.5 s de silence) avant d'envoyer quoi que ce soit. | ||
| 21 | +deadline, last_rx = time.time() + 6, time.time() | ||
| 22 | +while time.time() < deadline: | ||
| 23 | + line = s.readline() | ||
| 24 | + if line: | ||
| 25 | + last_rx = time.time() | ||
| 26 | + text = line.decode(errors="replace").rstrip() | ||
| 27 | + print(text, flush=True) | ||
| 28 | + if text.startswith("[boot]"): | ||
| 29 | + time.sleep(0.3) | ||
| 30 | + break | ||
| 31 | + elif time.time() - last_rx > 1.5: | ||
| 32 | + break | ||
| 33 | + | ||
| 34 | +for c in cmds: | ||
| 35 | + s.write((c + "\n").encode()) | ||
| 36 | + s.flush() | ||
| 37 | + time.sleep(0.1) | ||
| 38 | + | ||
| 39 | +end = time.time() + dur | ||
| 40 | +while time.time() < end: | ||
| 41 | + line = s.readline() | ||
| 42 | + if line: | ||
| 43 | + print(line.decode(errors="replace").rstrip(), flush=True) | ||
| 44 | +s.close() | ||
added
tools/serial_read.py +11 -0 | new file mode 100644 | ||
| @@ -0,0 +1,11 @@ | ||
| 1 | +import sys, time, serial | |
| 2 | +port, dur = sys.argv[1], float(sys.argv[2]) | |
| 3 | +end = time.time() + dur | |
| 4 | +s = None | |
| 5 | +while time.time() < end and s is None: | |
| 6 | + try: s = serial.Serial(port, 115200, timeout=0.5) | |
| 7 | + except Exception: time.sleep(0.3) | |
| 8 | +if s is None: sys.exit("port indisponible") | |
| 9 | +while time.time() < end: | |
| 10 | + d = s.readline() | |
| 11 | + if d: print(d.decode(errors="replace").rstrip(), flush=True) | |
| new file mode 100644 | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | +import sys, time, serial | ||
| 2 | +port, dur = sys.argv[1], float(sys.argv[2]) | ||
| 3 | +end = time.time() + dur | ||
| 4 | +s = None | ||
| 5 | +while time.time() < end and s is None: | ||
| 6 | + try: s = serial.Serial(port, 115200, timeout=0.5) | ||
| 7 | + except Exception: time.sleep(0.3) | ||
| 8 | +if s is None: sys.exit("port indisponible") | ||
| 9 | +while time.time() < end: | ||
| 10 | + d = s.readline() | ||
| 11 | + if d: print(d.decode(errors="replace").rstrip(), flush=True) | ||