Repository navigation
Comparing changes
Open a pull request
base repository: m5stack/StackChan
base: main
head repository: burrsutter/StackChan
compare: main
- 17 commits
- 36 files changed
- 2 contributors
Commits on Sep 15, 2026
-
Add quiet Companion app with pet chirp and wave detection
A desktop-companion mode with the AI agent's liveliness but no voice stack: no microphone, no wake word, no cloud calls. Voice stays opt-in via the AI.AGENT app. - app_companion: avatar + Breath/Blink/IdleExpression/IdleMotion modifiers; auto-opened by the launcher on cold boot only (warm reboots restore the launcher as before) - chirp: synthesized happy chirp through the audio codec on petting (no audio assets, no dependency on the Xiaozhi audio service) - lean_pet: directional pet response - the head rises into a front-to-back stroke and dips on a back-to-front stroke, replacing the random pet motion in this app - wave_attention: camera-based hand-wave detection via frame differencing on a low-res luma grid; reacts with a yellow happy face and a head turn toward the motion, scaled to the camera FOV - StackChanCamera::SampleLumaGrid: silent, copy-free low-res luma sampling for continuous motion detection Co-Authored-By: Claude Fable 5 <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 551563a - Browse repository at this point
Copy the full SHA 551563aView commit details -
Color the face per mode so the active mode is obvious at a glance
Companion is purple, Dance magenta, ESP-NOW remote yellow. Setting the avatar's secondaryColor rather than repainting the panel also recolors the eyelids, so blinking stays invisible against the new background. The Companion wave reaction now returns to purple instead of black. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for f958c31 - Browse repository at this point
Copy the full SHA f958c31View commit details
Commits on Sep 16, 2026
-
Stop capacitive noise from firing phantom head-pet gestures
The robot spontaneously showed hearts and chirped while untouched. Logging the raw Si12T zones found the middle channel idles at intensity 1 rather than 0, and is_touched() hardcoded a threshold of 1 (ignoring the touch_threshold config field entirely), so the sensor believed it was being touched continuously. Position compounds it: it is a ratio, so at 1-2 total counts a single count of noise swings it 50-100 units, far past the 40-unit swipe threshold. One noisy sample was enough to fabricate a full stroke. Three defenses, none of which a real pet trips -- a genuine stroke holds 2-3 counts across several zones for dozens of consecutive frames: - touch threshold raised to 2, above the measured noise floor, and now actually read from the config field - position is distrusted below a minimum total intensity, so weak frames cannot produce a swipe and the stroke's start point is only latched from a trustworthy frame - a swipe must persist two consecutive same-direction frames, so a single-frame spike is discarded Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for ceaa713 - Browse repository at this point
Copy the full SHA ceaa713View commit details -
Stop the wave task from hanging app shutdown, and capture core dumps
The camera read blocks in VIDIOC_DQBUF until a frame arrives, and this device is configured with a single buffer, so a stalled sensor blocks that task indefinitely. WaveAttention::stop() then busy-waited on it with no timeout, which would hang the robot permanently on leaving Companion mode. The read now waits with a 200ms select() and stop() gives up after 2s, leaving the task to exit on its own -- safe because the object outlives the app's close. Separately, enable core dumps to flash. The partition already existed but capture was set to NONE, so a panic left nothing behind to inspect. These were found while investigating a freeze that turned out to have an external cause: a script probing USB serial ports had dropped the robot into ROM download mode. The bugs above are real but latent, and were not what froze it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for fa39124 - Browse repository at this point
Copy the full SHA fa39124View commit details
Commits on Sep 18, 2026
-
Don't let a failed servo bus read stop the head animating
ReadMove returns -1 when a servo does not answer, and is_moving_impl passed that straight through as "moving" since -1 != 0. Anything waiting for the head to be still then waits forever: idle motion checks isMoving() before each move, so a failing bus silently froze the head with no error and no recovery. getCurrentAngle() already validates this same failure and falls back, so the moving check was simply missing the check its neighbour had. A failed read is not evidence of movement -- report "not moving" and let callers proceed. Logged once on transition rather than every poll. This unblocks the animation, but a bus that cannot be read is still a fault worth chasing on its own. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 92c279a - Browse repository at this point
Copy the full SHA 92c279aView commit details -
Stop a servo bus race and add self-healing for silent bus episodes
WaveAttention polled motion().isMoving() every 80ms from its own task, which reads the shared half-duplex servo UART -- while the main loop's motion update is reading/writing the same bus. The overlap produced intermittent "no reply" dropouts and at least one crossed reply (servo 2 answering a request addressed to servo 1). Fixed by adding a bus-free Servo::isAnimating()/Motion::isAnimating() (checks only the spring-animation state) and switching WaveAttention to it; the actual wave reaction already ran on the main loop via fetchWave(), so this only touches the polling check. Separately, verified on hardware that the bus can go fully silent on both servos at once -- not explained by the race above, since it still happens with the race fixed -- and that pulsing the servo power rail (VM EN via the PY32 IO expander) for 300ms reliably revives it. Added ServoBusWatchdog to hal_servo.cpp: logs the driver's actual error (no reply / bad checksum / wrong id / bad length) on the first failed read so the failure mode is visible in the log, and after 3s of continued silence pulses the rail with exponential backoff (3s, 6s, 12s... capped at 60s) so a genuinely dead bus isn't hammered. The watchdog is ticked from both the read and write paths so it can't be left mid-pulse across a whole animation. This unblocks the previous "don't let a failed read stop the head animating" fix by giving the bus a chance to recover instead of running degraded forever; the underlying cause of the power sag (battery state vs. rail current limit under torque) is still open. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 5ec93a6 - Browse repository at this point
Copy the full SHA 5ec93a6View commit details -
Log battery level in periodic diagnostics and servo bus events
Battery % and charging/discharging state were only ever visible on the setup screen -- nothing logged it to serial, which made it impossible to correlate the servo bus lock-ups with battery state after the fact. Add it to the existing 10s heap-status log, and to every ServoBusWatchdog log line (bus reads failing / pulsing / power back on / recovered) so a future freeze's log shows battery level and charge state at that exact moment, not just after the fact from the screen. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for a2f9a5c - Browse repository at this point
Copy the full SHA a2f9a5cView commit details
Commits on Sep 21, 2026
-
Don't let Companion mode auto-shutdown on battery mid-interaction
The board's idle sleep/shutdown timer only gets reset via WakeUp(), which is only ever called from the Xiaozhi voice path (SetPowerSaveLevel). Companion mode never goes through that path, so on battery -- where the timer is enabled -- it silently powers itself off after the configured idle timeout (default 10 min) no matter how active it looks on screen: idle motion, blink/breath, camera wave detection, and head-pet all run right up until the AXP2101 cuts power. Confirmed on hardware: the robot went fully dark after being unplugged and left alone, well before anyone would call that "idle" by any interactive measure. Add Hal::notifyUserInteraction() (board -> hal_bridge -> a new NotifyUserInteraction() on the board class that just calls the existing PowerSaveTimer::WakeUp(), without SetPowerSaveLevel's side effect of reconfiguring WiFi power-save state) and call it on the two genuine engagement signals Companion has: a detected wave (app_companion.cpp) and a confirmed head-pet swipe (head_pet.h, shared by any app using the modifier). Idle motion alone still does not count as activity -- the point is to distinguish "someone is here" from "the head is animating itself," matching the intent of the original idle-shutdown design. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 1e16ca1 - Browse repository at this point
Copy the full SHA 1e16ca1View commit details
Commits on Sep 23, 2026
-
Log the state that triggers an idle shutdown power-off
pmic_->PowerOff() left no trace in the log -- the board just silently goes dark, making a real shutdown indistinguishable after the fact from a crash or a power-supply brownout. Log battery level, charging/ discharging, and external-power state right before the power-off so a future "it died" has an answer in the last log lines instead of nothing. Motivated by a suspicion that a USB hub not delivering power the AXP2101 recognizes as reliable "external power" could let IsDischarging() read true even while plugged in, arming the idle-shutdown timer despite being on wired power the whole time -- this makes that theory checkable. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 6dc4ae7 - Browse repository at this point
Copy the full SHA 6dc4ae7View commit details -
Make DANCE listen to the room: nod to the beat, look around otherwise
DANCE was purely a BLE puppeteering target with no behaviour of its own. It now uses the microphone: it nods hard on the beat when music is playing, and falls back to Companion-style inquisitive looking around when it only hears voices or a quiet room. BLE choreography still wins outright whenever a client is streaming motion. Beat detection (beat_detector.cpp) runs its own task and only listens -- it never touches the servos. The servo bus is half-duplex and owned by the motion update loop; a second task issuing commands on it corrupts transactions, which is the race that was fixed in Companion earlier. The app polls fetchBeat() from its own loop and does the moving there. Detection listens to the BASS BAND only (~30-160 Hz), not the full spectrum. Broadband energy responds to vocals, cymbals and room noise about as much as the kick, and lands everywhere except the beat; the kick and bass line carry the pulse people actually hear. Energy is compared against its own rolling one-second average, with a rising-energy requirement so a sustained bass note triggers once on its attack rather than repeatedly. Telling music from a voice turned out to need more than a level threshold. Measured in a real room, the bass band reads ~8-14k for quiet typing, ~21-28k while actively typing or talking with bursts past 40k, and ~60k upward once music is on -- the bands nearly touch, and a single keystroke is exactly the sharp low-frequency transient a kick-drum detector is built to fire on. So beats are gated on the SUSTAINED average rather than any one window clearing the floor, that average has to hold above the floor for 1.2s before nodding starts, and hysteresis keeps a level sitting near the threshold from chattering the head between tiers. Speech and keystrokes are bursty; music is continuous. All the movement and detection tunables live in one commented block in dance_params.h, since the ranges want experimenting with on real hardware. Every computed target is clamped to a safety window on top of the servo limits, so raising an amplitude there cannot overextend the head -- the pitch axis holds the head against gravity and the gears are plastic. Pitch polarity is undocumented in this firmware, so which way dips the chin is a named sign constant, as the head-pet and camera-wave code already do; -1 is verified on hardware. Also adds a continuous mic capture API to the audio HAL (the existing calls are one-shot), and makes DANCE the cold-boot default app, since it now covers what COMPANION did and adds to it. Known limitation: the nod lands roughly 100 ms behind the beat. The servo runs a spring animation that takes time to reach the bottom of the dip, and driving it harder only halves that. Landing on the beat properly means predicting the next one from the tempo and starting the dip early. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 9d19736 - Browse repository at this point
Copy the full SHA 9d19736View commit details
Commits on Sep 26, 2026
-
Stop the robot putting itself to sleep while plugged in
The board blanked its screen after 5 minutes and powered itself off after 10, on USB power, however active it was on screen. Four separate defects stacked up to cause it: 1. GetBatteryLevel() called power_save_timer_->SetEnabled(discharging) directly, ignoring external power and fighting PollPowerSaveState() over the same timer -- whichever ran last won. The AXP2101 flickers between charging and discharging second to second while plugged in (observed: "100% charging" then "100% discharging" 3s later), and a full battery reports discharging once its charger idles, so a single flickered read armed the idle shutdown while sitting on USB power. Anything polling the battery reached this, the diagnostics log included. 2. ShouldEnablePowerSave() trusted that same flicker (is_discharging || ...). External power now decides: plugged in, the idle timer only runs if allowShutdownWhenCharging is set. 3. DANCE, the cold-boot default app since it replaced Companion, never called notifyUserInteraction(), so nothing reset the timer however hard it was dancing. It now resets on BLE commands and on detected music, throttled to once a second. Idle look-around still does not count, by design: an unattended robot in a quiet room should still be allowed to shut down. 4. The head-pet wake-up landed in HeadPetModifier, but Companion installs LeanPetModifier, so petting the robot never reset the timer either. Moved to the gesture source in hal_head_touch.cpp, where it covers every app and modifier rather than relying on each one to remember. Also: touching the screen now resets the timer. It never did, so once the display entered power save there was no way back -- WakeUp() is the only exit and nothing on the touch path called it. A blanked screen stayed blank until the shutdown timer finished the job. External power is now decided by the AXP2101's own VBUS-good bit (STATUS1 bit 5, verified on hardware) rather than inferred from which way current happens to be flowing, with the old current-direction heuristic kept as a fallback. Verified on hardware across several 30-minute runs on both a USB hub and a native port: "Power save timer enabled" never appears while plugged in, and the board no longer powers itself off. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 4b7ed6f - Browse repository at this point
Copy the full SHA 4b7ed6fView commit details -
Stop the servo watchdog killing the board, and smooth the motion
Two faults that fed each other. The board had been powering itself off at random intervals -- 117s, 327s, ~431s, 511s observed -- abruptly, with healthy rails and no software trace, and it never re-enumerated on USB, so power was being removed and latched off rather than dipping. The trigger was this file's own watchdog. On a silent bus it cut VM EN and restored it 300ms later; switching that rail back on into two servos draws an inrush spike that takes the whole board down. The decisive evidence: it died SOONER on a 5V/3A supply than on a 500mA port, which is the opposite of a supply shortage and exactly what a larger available inrush would do. A build with the pulse suppressed then logged 7488 bus read failures -- an order of magnitude more than any previous run -- and survived 1239s without dying, where every run that pulsed died. So: only a genuinely dead bus should earn a pulse. Silence tolerated before the first one goes 3s -> 15s (transient errors recover in 13-60ms), attempts are capped at 3, and after that the watchdog stands down and leaves the rail on rather than retrying an operation that can kill the robot. A still head beats a dead one. The upstream cause was the motion itself. Servo::update() advanced its spring animation by a fixed 0.02s per call: _angle_anim.updateWithDelta(0.02f); // Fixed delta time for consistency but it is driven from the app loop, which also runs LVGL, the camera and the mic, so the real interval varies. A fixed delta is only consistent if the caller is isochronous, and this one is not -- the head moved at whatever rate the loop happened to run, slower under load and uneven whenever the loop hitched. That unevenness is what made the motion read as jerky, and sharp acceleration is what spikes servo current, produces bus read errors, and ends in a watchdog pulse. It now advances by real elapsed time, capped at 100ms so a stalled frame cannot teleport the head across its travel in one write. Measured on hardware: battery sag under dancing load fell from ~880mV (4244 -> 3361) to ~60mV (4135 -> 4073). The pack was never weak; the load was brutal. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>Configuration menu - View commit details
-
Copy full SHA for 09323f6 - Browse repository at this point
Copy the full SHA 09323f6View commit details -
Give DANCE a calm resting posture, beat-synced LEDs and a softer nod
The head now has a defined rest. It parks centred with the chin up at pitchCenter when the app opens and squares up there again the moment music starts, so a nod always reads against the same pose rather than from wherever the idle drift left it. Commanded once per transition, not per frame, so holding still costs no servo bus traffic. While waiting for music it drifts gently instead of standing frozen. IdleMotionModifier's bounds are now configurable through IdleMotionLimits_t, defaulting to the existing behaviour so Companion is untouched; DANCE passes a deliberately modest profile -- yaw +-250 instead of +-800, pitch held near the neutral 330, speed capped at 200, and no wide look-arounds or "quick glances". That last action swung the yaw +-500 at speed 400 and was by far the harshest thing the idle loop did, which is the category of movement that loads the servo rail hard enough to upset the bus. nodDownSpeed drops 900 -> 650, taking spring stiffness from 528 to ~280. The parameter's own documentation said to lower it if the head sounded harsh, and it did; this also stays off the >800 branch that widened the rest threshold to mask discretisation jitter. Head LEDs pulse with the beat: dark in a quiet room, a dim glow while music plays, flashing to full on each beat and fading back over 220ms so the light tracks the nod rather than outrunning it. Colour picks a fresh random hue per beat, forced at least 70 degrees apart so consecutive beats never look alike. All of it lives in a new kDanceLeds block; set randomHue false to hold the mode's magenta instead. Refreshes are throttled to 20Hz because each one writes all 12 LEDs over I2C, and the quiet state is written once on the transition. Note only LED indices 0-5 light on this unit -- the second row is not reachable at any address the controller can drive (see HARDWARE.md), so the flash is one-sided until that hardware is addressed. Also adds yawNeutralOffset, a mechanical yaw trim for the neutral pose: commanding yaw 0 does not point this unit's head straight ahead. The sign is still unverified on hardware, in keeping with every other direction constant in this firmware. The dormant DIAG_LED_TAP block is left in place, compiled out. It drives the tap-to-advance LED test that established the second row is missing, and is one character from being useful again. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 37f4b03 - Browse repository at this point
Copy the full SHA 37f4b03View commit details -
Log the power rails and PMIC limits, and keep the LED test harness
Instrumentation that made today's diagnosis possible, kept because the faults it found were invisible without it. Every 2s (the board was dying between 10s samples, so the trend into the cut was never captured): [HAL] pwr up=Ns batt=N% chg|dis ext=N axp=0xSSSS adc=[b,?,vbus,vsys] The gauge percentage is retained only for comparison: it read a stuck 100% all day while the charger sat in constant-current phase, which a full pack never does. The ADC values are the trustworthy ones, and they are logged raw with the channels identified by magnitude rather than by a recalled register map -- an earlier guess had 0x15 as the input current limit when it is the input VOLTAGE limit (VINDPM), so the addresses here are not asserted beyond what was measured. At boot, the PMIC's configured limits are logged once: vin_dpm(0x15)=0x06 in_curr(0x16)=0x04 charge_cc(0x62)=0x0D which is a 4.36V VINDPM threshold, a 1500mA input current limit and a 700mA charge current. The input limit is the interesting one: the PMIC will draw three times what a 500mA computer port offers, so the port has always been the binding constraint, not the firmware. Also exposes setRgbLedCount() and keeps two compiled-out LED diagnostics. Caution recorded for whoever reaches for them: widening the LED count past the wired 12 and writing those addresses disturbs the PY32 expander and takes the touch input down with it -- the AXP2101 kept answering on the same I2C bus throughout, so the bus was fine and the expander was not. A power cycle clears it. Probing addresses the hardware does not implement is not a safe test. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 1399f75 - Browse repository at this point
Copy the full SHA 1399f75View commit details -
Let the servos relax when idle, and bring back the ambient face motion
Hal::startXiaozhi() is the only place in this firmware that ever called setAutoTorqueReleaseEnabled(true), which makes Servo::update() drop torque 200ms after the head stops moving. So the AI Agent path relaxed the servos when idle, and every other app -- DANCE, Companion -- held torque continuously, the pitch servo fighting gravity for as long as the app was open. That standing current, not just the movement spikes, is what sagged the rail and produced the endless servo bus read errors. It also explains why cutting servo power entirely let the board run 30 minutes where every other configuration died: that was crudely achieving what torque release does properly. Comparing against stock firmware in AI Agent mode is what surfaced it -- the vendor shipped the mechanism, we just never turned it on in our own apps. There is an uncomfortable implication worth recording: the servo-bus lock-ups that prompted the watchdog in 5ec93a6 are plausibly the downstream effect of this same standing current, which would make that watchdog a cure for a problem we had created. Unproven -- the lock-ups were never retested with torque release enabled -- but it fits everything measured. Side effect to expect: a relaxed head can droop under gravity or be moved by hand. park_at_neutral() therefore syncs from the servo's actual angle before animating, so a move after an idle period does not start with a jump from a stale commanded pose. Stock AI Agent mode has always behaved this way. Also restores the ambient face motion DANCE was missing. clearModifiers() drops the default stack, and DANCE only re-added Blink and IdleMotion, so between the occasional small head move nothing happened at all -- still, then twitch. BreathModifier and IdleExpressionModifier are avatar-only (breath's amplitude is in pixels; it moves the face, never the servos), so they cost nothing on the rail and are most of what makes the robot read as continuously alive. Factory and Companion have always installed both. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for bc41b78 - Browse repository at this point
Copy the full SHA bc41b78View commit details
Commits on Sep 27, 2026
-
Record the measured yaw trim and the sign convention it revealed
Commanding yaw 0 does not point this unit's head straight ahead -- the servo horn's mounting sets where zero physically lands. Driving yaw directly from the dashboard and watching the robot put physical centre at +40 (4 degrees), so that is now yawNeutralOffset. The previous -200 was an unverified sign probe: both the wrong direction and five times too large. The same session settled something documented nowhere in this firmware: NEGATIVE yaw -> robot's LEFT shoulder POSITIVE yaw -> robot's RIGHT shoulder The remote's joystick mapping spans +-1280 (joystick_handle.c:174, note the deliberate inversion) but never says which end is which, which is why this had to be measured rather than read. Every other direction constant here carries the same kind of empirically-determined comment. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>Configuration menu - View commit details
-
Copy full SHA for aea36ef - Browse repository at this point
Copy the full SHA aea36efView commit details -
Give AVATAR a face, LED control, and make it the boot default
AVATAR installed no modifiers at all: its face only ever changed when the server sent a ControlAvatar frame, so between commands the robot sat with a fixed stare and looked switched off. It now carries the same ambient stack as DANCE -- breath, blink, idle expression, and a calm idle look-around. The first three are avatar-only (breath's amplitude is in pixels; they move the face, never the servos) so they cost nothing on a servo rail this unit has been struggling with. Idle motion does drive the head, so it gets the deliberately modest profile: yaw +-250 instead of +-800, pitch near neutral, speed capped at 200, and no "quick glance" -- that action swings +-500 at speed 400 and is the harshest thing the idle loop does. Idle motion stands down the moment a ControlMotion frame arrives and resumes three seconds after the server goes quiet. Without that handover the idle loop and the remote client fight over the head and remote control feels possessed. LEDs are now reachable over the WebSocket. The protocol has no LED message and adding one would mean changing both ends -- but it does not need one: the RGB keys (leftRgbColor, leftRgbDuration, right...) are disjoint from the avatar keys (leftEye, rightEye, mouth), and both parsers ignore what they do not recognise. So ControlAvatar payloads are now fed to updateNeonLightFromJson() as well, and one frame can carry face fields, LED fields or both, with older clients unaffected. Note only one bar lights on this unit; the second row of six is physically absent (see HARDWARE.md). AVATAR also becomes the cold-boot default, replacing DANCE. It connects to the self-hosted server on power-up, so the robot is reachable from the network without someone walking over to navigate the launcher -- and with the ambient stack above it no longer looks dead while it waits. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for b39154b - Browse repository at this point
Copy the full SHA b39154bView commit details
This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
You can try running this command locally to see the comparison on your machine:
git diff main...main